/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/errors.py

  • Committer: Robert Collins
  • Date: 2007-04-19 02:27:44 UTC
  • mto: This revision was merged to the branch mainline in revision 2426.
  • Revision ID: robertc@robertcollins.net-20070419022744-pfdqz42kp1wizh43
``make docs`` now creates a man page at ``man1/bzr.1`` fixing bug 107388.
(Robert Collins)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005-2013, 2016 Canonical Ltd
 
1
# Copyright (C) 2005, 2006, 2007 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
12
12
#
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
 
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
16
 
17
17
"""Exceptions for bzr, and reporting of them.
18
18
"""
19
19
 
20
20
 
 
21
from bzrlib import (
 
22
    osutils,
 
23
    symbol_versioning,
 
24
    )
 
25
from bzrlib.patches import (
 
26
    MalformedHunkHeader,
 
27
    MalformedLine,
 
28
    MalformedPatchHeader,
 
29
    PatchConflict,
 
30
    PatchSyntax,
 
31
    )
 
32
 
 
33
 
21
34
# TODO: is there any value in providing the .args field used by standard
22
 
# python exceptions?   A list of values with no names seems less useful
 
35
# python exceptions?   A list of values with no names seems less useful 
23
36
# to me.
24
37
 
25
 
# TODO: Perhaps convert the exception to a string at the moment it's
 
38
# TODO: Perhaps convert the exception to a string at the moment it's 
26
39
# constructed to make sure it will succeed.  But that says nothing about
27
40
# exceptions that are never raised.
28
41
 
31
44
# 'unprintable'.
32
45
 
33
46
 
34
 
# return codes from the brz program
35
 
EXIT_OK = 0
36
 
EXIT_ERROR = 3
37
 
EXIT_INTERNAL_ERROR = 4
38
 
 
39
 
 
40
 
class BzrError(Exception):
 
47
class BzrError(StandardError):
41
48
    """
42
 
    Base class for errors raised by breezy.
 
49
    Base class for errors raised by bzrlib.
43
50
 
44
 
    :cvar internal_error: if True this was probably caused by a brz bug and
45
 
        should be displayed with a traceback; if False (or absent) this was
46
 
        probably a user or environment error and they don't need the gory
47
 
        details.  (That can be overridden by -Derror on the command line.)
 
51
    :cvar internal_error: if true (or absent) this was probably caused by a
 
52
    bzr bug and should be displayed with a traceback; if False this was
 
53
    probably a user or environment error and they don't need the gory details.
 
54
    (That can be overridden by -Derror on the command line.)
48
55
 
49
56
    :cvar _fmt: Format string to display the error; this is expanded
50
 
        by the instance's dict.
 
57
    by the instance's dict.
51
58
    """
52
 
 
 
59
    
53
60
    internal_error = False
54
61
 
55
62
    def __init__(self, msg=None, **kwds):
60
67
        arguments can be given.  The first is for generic "user" errors which
61
68
        are not intended to be caught and so do not need a specific subclass.
62
69
        The second case is for use with subclasses that provide a _fmt format
63
 
        string to print the arguments.
 
70
        string to print the arguments.  
64
71
 
65
 
        Keyword arguments are taken as parameters to the error, which can
66
 
        be inserted into the format string template.  It's recommended
67
 
        that subclasses override the __init__ method to require specific
 
72
        Keyword arguments are taken as parameters to the error, which can 
 
73
        be inserted into the format string template.  It's recommended 
 
74
        that subclasses override the __init__ method to require specific 
68
75
        parameters.
69
76
 
70
77
        :param msg: If given, this is the literal complete text for the error,
71
 
           not subject to expansion. 'msg' is used instead of 'message' because
72
 
           python evolved and, in 2.6, forbids the use of 'message'.
 
78
        not subject to expansion.
73
79
        """
74
 
        Exception.__init__(self)
 
80
        StandardError.__init__(self)
75
81
        if msg is not None:
76
82
            # I was going to deprecate this, but it actually turns out to be
77
83
            # quite handy - mbp 20061103.
81
87
            for key, value in kwds.items():
82
88
                setattr(self, key, value)
83
89
 
84
 
    def _format(self):
 
90
    def __str__(self):
85
91
        s = getattr(self, '_preformatted_string', None)
86
92
        if s is not None:
87
 
            # contains a preformatted message
88
 
            return s
89
 
        err = None
 
93
            # contains a preformatted message; must be cast to plain str
 
94
            return str(s)
90
95
        try:
91
96
            fmt = self._get_format_string()
92
97
            if fmt:
93
 
                d = dict(self.__dict__)
94
 
                s = fmt % d
 
98
                s = fmt % self.__dict__
95
99
                # __str__() should always return a 'str' object
96
100
                # never a 'unicode' object.
 
101
                if isinstance(s, unicode):
 
102
                    return s.encode('utf8')
97
103
                return s
98
 
        except Exception as e:
99
 
            err = e
100
 
        return 'Unprintable exception %s: dict=%r, fmt=%r, error=%r' \
 
104
        except (AttributeError, TypeError, NameError, ValueError, KeyError), e:
 
105
            return 'Unprintable exception %s: dict=%r, fmt=%r, error=%s' \
 
106
                % (self.__class__.__name__,
 
107
                   self.__dict__,
 
108
                   getattr(self, '_fmt', None),
 
109
                   str(e))
 
110
 
 
111
    def _get_format_string(self):
 
112
        """Return format string for this exception or None"""
 
113
        fmt = getattr(self, '_fmt', None)
 
114
        if fmt is not None:
 
115
            return fmt
 
116
        fmt = getattr(self, '__doc__', None)
 
117
        if fmt is not None:
 
118
            symbol_versioning.warn("%s uses its docstring as a format, "
 
119
                    "it should use _fmt instead" % self.__class__.__name__,
 
120
                    DeprecationWarning)
 
121
            return fmt
 
122
        return 'Unprintable exception %s: dict=%r, fmt=%r' \
101
123
            % (self.__class__.__name__,
102
124
               self.__dict__,
103
125
               getattr(self, '_fmt', None),
104
 
               err)
105
 
 
106
 
    __str__ = _format
107
 
 
108
 
    def __repr__(self):
109
 
        return '%s(%s)' % (self.__class__.__name__, str(self))
110
 
 
111
 
    def _get_format_string(self):
112
 
        """Return format string for this exception or None"""
113
 
        fmt = getattr(self, '_fmt', None)
114
 
        if fmt is not None:
115
 
            from breezy.i18n import gettext
116
 
            return gettext(fmt)  # _fmt strings should be ascii
117
 
 
118
 
    def __eq__(self, other):
119
 
        if self.__class__ is not other.__class__:
120
 
            return NotImplemented
121
 
        return self.__dict__ == other.__dict__
122
 
 
123
 
    def __hash__(self):
124
 
        return id(self)
125
 
 
126
 
 
127
 
class InternalBzrError(BzrError):
128
 
    """Base class for errors that are internal in nature.
129
 
 
130
 
    This is a convenience class for errors that are internal. The
131
 
    internal_error attribute can still be altered in subclasses, if needed.
132
 
    Using this class is simply an easy way to get internal errors.
133
 
    """
134
 
 
135
 
    internal_error = True
136
 
 
137
 
 
138
 
class BranchError(BzrError):
139
 
    """Base class for concrete 'errors about a branch'."""
140
 
 
141
 
    def __init__(self, branch):
142
 
        BzrError.__init__(self, branch=branch)
143
 
 
144
 
 
145
 
class BzrCheckError(InternalBzrError):
146
 
 
147
 
    _fmt = "Internal check failed: %(msg)s"
148
 
 
149
 
    def __init__(self, msg):
150
 
        BzrError.__init__(self)
151
 
        self.msg = msg
152
 
 
153
 
 
154
 
class IncompatibleVersion(BzrError):
155
 
 
156
 
    _fmt = 'API %(api)s is not compatible; one of versions %(wanted)r '\
157
 
           'is required, but current version is %(current)r.'
158
 
 
159
 
    def __init__(self, api, wanted, current):
160
 
        self.api = api
161
 
        self.wanted = wanted
162
 
        self.current = current
163
 
 
164
 
 
165
 
class InProcessTransport(BzrError):
166
 
 
167
 
    _fmt = "The transport '%(transport)s' is only accessible within this " \
168
 
        "process."
169
 
 
170
 
    def __init__(self, transport):
171
 
        self.transport = transport
 
126
               )
 
127
 
 
128
 
 
129
class BzrNewError(BzrError):
 
130
    """Deprecated error base class."""
 
131
    # base classes should override the docstring with their human-
 
132
    # readable explanation
 
133
 
 
134
    def __init__(self, *args, **kwds):
 
135
        # XXX: Use the underlying BzrError to always generate the args
 
136
        # attribute if it doesn't exist.  We can't use super here, because
 
137
        # exceptions are old-style classes in python2.4 (but new in 2.5).
 
138
        # --bmc, 20060426
 
139
        symbol_versioning.warn('BzrNewError was deprecated in bzr 0.13; '
 
140
             'please convert %s to use BzrError instead'
 
141
             % self.__class__.__name__,
 
142
             DeprecationWarning,
 
143
             stacklevel=2)
 
144
        BzrError.__init__(self, *args)
 
145
        for key, value in kwds.items():
 
146
            setattr(self, key, value)
 
147
 
 
148
    def __str__(self):
 
149
        try:
 
150
            # __str__() should always return a 'str' object
 
151
            # never a 'unicode' object.
 
152
            s = self.__doc__ % self.__dict__
 
153
            if isinstance(s, unicode):
 
154
                return s.encode('utf8')
 
155
            return s
 
156
        except (TypeError, NameError, ValueError, KeyError), e:
 
157
            return 'Unprintable exception %s(%r): %s' \
 
158
                % (self.__class__.__name__,
 
159
                   self.__dict__, str(e))
 
160
 
 
161
 
 
162
class AlreadyBuilding(BzrError):
 
163
    
 
164
    _fmt = "The tree builder is already building a tree."
 
165
 
 
166
 
 
167
class BzrCheckError(BzrError):
 
168
    
 
169
    _fmt = "Internal check failed: %(message)s"
 
170
 
 
171
    internal_error = True
 
172
 
 
173
    def __init__(self, message):
 
174
        BzrError.__init__(self)
 
175
        self.message = message
 
176
 
 
177
 
 
178
class DisabledMethod(BzrError):
 
179
 
 
180
    _fmt = "The smart server method '%(class_name)s' is disabled."
 
181
 
 
182
    internal_error = True
 
183
 
 
184
    def __init__(self, class_name):
 
185
        BzrError.__init__(self)
 
186
        self.class_name = class_name
 
187
 
 
188
 
 
189
class InvalidEntryName(BzrError):
 
190
    
 
191
    _fmt = "Invalid entry name: %(name)s"
 
192
 
 
193
    internal_error = True
 
194
 
 
195
    def __init__(self, name):
 
196
        BzrError.__init__(self)
 
197
        self.name = name
172
198
 
173
199
 
174
200
class InvalidRevisionNumber(BzrError):
175
 
 
 
201
    
176
202
    _fmt = "Invalid revision number %(revno)s"
177
203
 
178
204
    def __init__(self, revno):
190
216
        self.revision_id = revision_id
191
217
        self.branch = branch
192
218
 
193
 
 
194
219
class ReservedId(BzrError):
195
220
 
196
221
    _fmt = "Reserved revision-id {%(revision_id)s}"
198
223
    def __init__(self, revision_id):
199
224
        self.revision_id = revision_id
200
225
 
201
 
 
202
 
class RootMissing(InternalBzrError):
203
 
 
204
 
    _fmt = ("The root entry of a tree must be the first entry supplied to "
205
 
            "the commit builder.")
206
 
 
207
 
 
208
 
class NoPublicBranch(BzrError):
209
 
 
210
 
    _fmt = 'There is no public branch set for "%(branch_url)s".'
211
 
 
212
 
    def __init__(self, branch):
213
 
        from . import urlutils
214
 
        public_location = urlutils.unescape_for_display(branch.base, 'ascii')
215
 
        BzrError.__init__(self, branch_url=public_location)
216
 
 
217
 
 
218
226
class NoSuchId(BzrError):
219
227
 
220
 
    _fmt = 'The file id "%(file_id)s" is not present in the tree %(tree)s.'
221
 
 
 
228
    _fmt = "The file id %(file_id)s is not present in the tree %(tree)s."
 
229
    
222
230
    def __init__(self, tree, file_id):
223
231
        BzrError.__init__(self)
224
232
        self.file_id = file_id
225
233
        self.tree = tree
226
234
 
227
235
 
228
 
class NotStacked(BranchError):
229
 
 
230
 
    _fmt = "The branch '%(branch)s' is not stacked."
 
236
class InventoryModified(BzrError):
 
237
 
 
238
    _fmt = ("The current inventory for the tree %(tree)r has been modified,"
 
239
            " so a clean inventory cannot be read without data loss.")
 
240
 
 
241
    internal_error = True
 
242
 
 
243
    def __init__(self, tree):
 
244
        self.tree = tree
231
245
 
232
246
 
233
247
class NoWorkingTree(BzrError):
234
248
 
235
 
    _fmt = 'No WorkingTree exists for "%(base)s".'
236
 
 
 
249
    _fmt = "No WorkingTree exists for %(base)s."
 
250
    
237
251
    def __init__(self, base):
238
252
        BzrError.__init__(self)
239
253
        self.base = base
240
254
 
241
255
 
 
256
class NotBuilding(BzrError):
 
257
 
 
258
    _fmt = "Not currently building a tree."
 
259
 
 
260
 
242
261
class NotLocalUrl(BzrError):
243
262
 
244
263
    _fmt = "%(url)s is not a local path."
247
266
        self.url = url
248
267
 
249
268
 
250
 
class WorkingTreeAlreadyPopulated(InternalBzrError):
251
 
 
252
 
    _fmt = 'Working tree already populated in "%(base)s"'
 
269
class WorkingTreeAlreadyPopulated(BzrError):
 
270
 
 
271
    _fmt = """Working tree already populated in %(base)s"""
 
272
 
 
273
    internal_error = True
253
274
 
254
275
    def __init__(self, base):
255
276
        self.base = base
256
277
 
257
 
 
258
 
class NoWhoami(BzrError):
259
 
 
260
 
    _fmt = ('Unable to determine your name.\n'
261
 
            "Please, set your name with the 'whoami' command.\n"
262
 
            'E.g. brz whoami "Your Name <name@example.com>"')
263
 
 
264
 
 
265
 
class CommandError(BzrError):
 
278
class BzrCommandError(BzrError):
266
279
    """Error from user command"""
267
280
 
 
281
    internal_error = False
 
282
 
268
283
    # Error from malformed user command; please avoid raising this as a
269
284
    # generic exception not caused by user input.
270
285
    #
271
286
    # I think it's a waste of effort to differentiate between errors that
272
287
    # are not intended to be caught anyway.  UI code need not subclass
273
 
    # CommandError, and non-UI code should not throw a subclass of
274
 
    # CommandError.  ADHB 20051211
275
 
 
276
 
 
277
 
# Provide the old name as backup, for the moment.
278
 
BzrCommandError = CommandError
 
288
    # BzrCommandError, and non-UI code should not throw a subclass of
 
289
    # BzrCommandError.  ADHB 20051211
 
290
    def __init__(self, msg):
 
291
        # Object.__str__() must return a real string
 
292
        # returning a Unicode string is a python error.
 
293
        if isinstance(msg, unicode):
 
294
            self.msg = msg.encode('utf8')
 
295
        else:
 
296
            self.msg = msg
 
297
 
 
298
    def __str__(self):
 
299
        return self.msg
279
300
 
280
301
 
281
302
class NotWriteLocked(BzrError):
286
307
        self.not_locked = not_locked
287
308
 
288
309
 
 
310
class BzrOptionError(BzrCommandError):
 
311
 
 
312
    _fmt = "Error in command line options"
 
313
 
 
314
 
 
315
class BadOptionValue(BzrError):
 
316
 
 
317
    _fmt = """Bad value "%(value)s" for option "%(name)s"."""
 
318
 
 
319
    def __init__(self, name, value):
 
320
        BzrError.__init__(self, name=name, value=value)
 
321
 
 
322
    
289
323
class StrictCommitFailed(BzrError):
290
324
 
291
325
    _fmt = "Commit refused because there are unknown files in the tree"
293
327
 
294
328
# XXX: Should be unified with TransportError; they seem to represent the
295
329
# same thing
296
 
# RBC 20060929: I think that unifiying with TransportError would be a mistake
297
 
# - this is finer than a TransportError - and more useful as such. It
298
 
# differentiates between 'transport has failed' and 'operation on a transport
299
 
# has failed.'
300
330
class PathError(BzrError):
301
 
 
 
331
    
302
332
    _fmt = "Generic path error: %(path)r%(extra)s)"
303
333
 
304
334
    def __init__(self, path, extra=None):
324
354
    """Used when renaming and both source and dest exist."""
325
355
 
326
356
    _fmt = ("Could not rename %(source)s => %(dest)s because both files exist."
327
 
            " (Use --after to tell brz about a rename that has already"
328
 
            " happened)%(extra)s")
 
357
            "%(extra)s")
329
358
 
330
359
    def __init__(self, source, dest, extra=None):
331
360
        BzrError.__init__(self)
339
368
 
340
369
class NotADirectory(PathError):
341
370
 
342
 
    _fmt = '"%(path)s" is not a directory %(extra)s'
 
371
    _fmt = "%(path)r is not a directory %(extra)s"
343
372
 
344
373
 
345
374
class NotInWorkingDirectory(PathError):
346
375
 
347
 
    _fmt = '"%(path)s" is not in the working directory %(extra)s'
 
376
    _fmt = "%(path)r is not in the working directory %(extra)s"
348
377
 
349
378
 
350
379
class DirectoryNotEmpty(PathError):
351
380
 
352
 
    _fmt = 'Directory not empty: "%(path)s"%(extra)s'
353
 
 
354
 
 
355
 
class HardLinkNotSupported(PathError):
356
 
 
357
 
    _fmt = 'Hard-linking "%(path)s" is not supported'
358
 
 
359
 
 
360
 
class ReadingCompleted(InternalBzrError):
361
 
 
 
381
    _fmt = "Directory not empty: %(path)r%(extra)s"
 
382
 
 
383
 
 
384
class ReadingCompleted(BzrError):
 
385
    
362
386
    _fmt = ("The MediumRequest '%(request)s' has already had finish_reading "
363
387
            "called upon it - the request has been completed and no more "
364
388
            "data may be read.")
365
389
 
 
390
    internal_error = True
 
391
 
366
392
    def __init__(self, request):
367
393
        self.request = request
368
394
 
369
395
 
370
396
class ResourceBusy(PathError):
371
397
 
372
 
    _fmt = 'Device or resource busy: "%(path)s"%(extra)s'
 
398
    _fmt = "Device or resource busy: %(path)r%(extra)s"
373
399
 
374
400
 
375
401
class PermissionDenied(PathError):
376
402
 
377
 
    _fmt = 'Permission denied: "%(path)s"%(extra)s'
 
403
    _fmt = "Permission denied: %(path)r%(extra)s"
 
404
 
 
405
 
 
406
class InvalidURL(PathError):
 
407
 
 
408
    _fmt = "Invalid url supplied to transport: %(path)r%(extra)s"
 
409
 
 
410
 
 
411
class InvalidURLJoin(PathError):
 
412
 
 
413
    _fmt = "Invalid URL join request: %(args)s%(extra)s"
 
414
 
 
415
    def __init__(self, msg, base, args):
 
416
        PathError.__init__(self, base, msg)
 
417
        self.args = [base] + list(args)
 
418
 
 
419
 
 
420
class UnknownHook(BzrError):
 
421
 
 
422
    _fmt = "The %(type)s hook '%(hook)s' is unknown in this version of bzrlib."
 
423
 
 
424
    def __init__(self, hook_type, hook_name):
 
425
        BzrError.__init__(self)
 
426
        self.type = hook_type
 
427
        self.hook = hook_name
378
428
 
379
429
 
380
430
class UnsupportedProtocol(PathError):
381
431
 
382
432
    _fmt = 'Unsupported protocol for url "%(path)s"%(extra)s'
383
433
 
384
 
    def __init__(self, url, extra=""):
 
434
    def __init__(self, url, extra):
385
435
        PathError.__init__(self, url, extra=extra)
386
436
 
387
437
 
388
 
class UnstackableLocationError(BzrError):
389
 
 
390
 
    _fmt = "The branch '%(branch_url)s' cannot be stacked on '%(target_url)s'."
391
 
 
392
 
    def __init__(self, branch_url, target_url):
393
 
        BzrError.__init__(self)
394
 
        self.branch_url = branch_url
395
 
        self.target_url = target_url
396
 
 
397
 
 
398
 
class UnstackableRepositoryFormat(BzrError):
399
 
 
400
 
    _fmt = ("The repository '%(url)s'(%(format)s) is not a stackable format. "
401
 
            "You will need to upgrade the repository to permit branch stacking.")
402
 
 
403
 
    def __init__(self, format, url):
404
 
        BzrError.__init__(self)
405
 
        self.format = format
406
 
        self.url = url
407
 
 
408
 
 
409
 
class ReadError(PathError):
410
 
 
411
 
    _fmt = """Error reading from %(path)r."""
412
 
 
413
 
 
414
438
class ShortReadvError(PathError):
415
439
 
416
 
    _fmt = ('readv() read %(actual)s bytes rather than %(length)s bytes'
417
 
            ' at %(offset)s for "%(path)s"%(extra)s')
 
440
    _fmt = ("readv() read %(actual)s bytes rather than %(length)s bytes"
 
441
            " at %(offset)s for %(path)s%(extra)s")
418
442
 
419
443
    internal_error = True
420
444
 
425
449
        self.actual = actual
426
450
 
427
451
 
428
 
class PathNotChild(PathError):
429
 
 
430
 
    _fmt = 'Path "%(path)s" is not a child of path "%(base)s"%(extra)s'
431
 
 
432
 
    internal_error = False
 
452
class PathNotChild(BzrError):
 
453
 
 
454
    _fmt = "Path %(path)r is not a child of path %(base)r%(extra)s"
 
455
 
 
456
    internal_error = True
433
457
 
434
458
    def __init__(self, path, base, extra=None):
435
459
        BzrError.__init__(self)
443
467
 
444
468
class InvalidNormalization(PathError):
445
469
 
446
 
    _fmt = 'Path "%(path)s" is not unicode normalized'
 
470
    _fmt = "Path %(path)r is not unicode normalized"
447
471
 
448
472
 
449
473
# TODO: This is given a URL; we try to unescape it but doing that from inside
450
474
# the exception object is a bit undesirable.
451
 
# TODO: Probably this behavior of should be a common superclass
 
475
# TODO: Probably this behavior of should be a common superclass 
452
476
class NotBranchError(PathError):
453
477
 
454
 
    _fmt = 'Not a branch: "%(path)s"%(detail)s.'
455
 
 
456
 
    def __init__(self, path, detail=None, controldir=None):
457
 
        from . import urlutils
458
 
        path = urlutils.unescape_for_display(path, 'ascii')
459
 
        if detail is not None:
460
 
            detail = ': ' + detail
461
 
        self.detail = detail
462
 
        self.controldir = controldir
463
 
        PathError.__init__(self, path=path)
464
 
 
465
 
    def __repr__(self):
466
 
        return '<%s %r>' % (self.__class__.__name__, self.__dict__)
467
 
 
468
 
    def _get_format_string(self):
469
 
        # GZ 2017-06-08: Not the best place to lazy fill detail in.
470
 
        if self.detail is None:
471
 
            self.detail = self._get_detail()
472
 
        return super(NotBranchError, self)._get_format_string()
473
 
 
474
 
    def _get_detail(self):
475
 
        if self.controldir is not None:
476
 
            try:
477
 
                self.controldir.open_repository()
478
 
            except NoRepositoryPresent:
479
 
                return ''
480
 
            except Exception as e:
481
 
                # Just ignore unexpected errors.  Raising arbitrary errors
482
 
                # during str(err) can provoke strange bugs.  Concretely
483
 
                # Launchpad's codehosting managed to raise NotBranchError
484
 
                # here, and then get stuck in an infinite loop/recursion
485
 
                # trying to str() that error.  All this error really cares
486
 
                # about that there's no working repository there, and if
487
 
                # open_repository() fails, there probably isn't.
488
 
                return ': ' + e.__class__.__name__
489
 
            else:
490
 
                return ': location is a repository'
491
 
        return ''
 
478
    _fmt = "Not a branch: %(path)s"
 
479
 
 
480
    def __init__(self, path):
 
481
       import bzrlib.urlutils as urlutils
 
482
       self.path = urlutils.unescape_for_display(path, 'ascii')
492
483
 
493
484
 
494
485
class NoSubmitBranch(PathError):
496
487
    _fmt = 'No submit branch available for branch "%(path)s"'
497
488
 
498
489
    def __init__(self, branch):
499
 
        from . import urlutils
500
 
        self.path = urlutils.unescape_for_display(branch.base, 'ascii')
501
 
 
502
 
 
503
 
class AlreadyControlDirError(PathError):
504
 
 
505
 
    _fmt = 'A control directory already exists: "%(path)s".'
 
490
       import bzrlib.urlutils as urlutils
 
491
       self.path = urlutils.unescape_for_display(branch.base, 'ascii')
506
492
 
507
493
 
508
494
class AlreadyBranchError(PathError):
509
495
 
510
 
    _fmt = 'Already a branch: "%(path)s".'
511
 
 
512
 
 
513
 
class InvalidBranchName(PathError):
514
 
 
515
 
    _fmt = "Invalid branch name: %(name)s"
516
 
 
517
 
    def __init__(self, name):
518
 
        BzrError.__init__(self)
519
 
        self.name = name
520
 
 
521
 
 
522
 
class ParentBranchExists(AlreadyBranchError):
523
 
 
524
 
    _fmt = 'Parent branch already exists: "%(path)s".'
 
496
    _fmt = "Already a branch: %(path)s."
525
497
 
526
498
 
527
499
class BranchExistsWithoutWorkingTree(PathError):
528
500
 
529
 
    _fmt = 'Directory contains a branch, but no working tree \
530
 
(use brz checkout if you wish to build a working tree): "%(path)s"'
 
501
    _fmt = "Directory contains a branch, but no working tree \
 
502
(use bzr checkout if you wish to build a working tree): %(path)s"
 
503
 
 
504
 
 
505
class AtomicFileAlreadyClosed(PathError):
 
506
 
 
507
    _fmt = ("'%(function)s' called on an AtomicFile after it was closed:"
 
508
            " %(path)s")
 
509
 
 
510
    def __init__(self, path, function):
 
511
        PathError.__init__(self, path=path, extra=None)
 
512
        self.function = function
531
513
 
532
514
 
533
515
class InaccessibleParent(PathError):
534
516
 
535
 
    _fmt = ('Parent not accessible given base "%(base)s" and'
536
 
            ' relative path "%(path)s"')
 
517
    _fmt = ("Parent not accessible given base %(base)s and"
 
518
            " relative path %(path)s")
537
519
 
538
520
    def __init__(self, path, base):
539
521
        PathError.__init__(self, path)
542
524
 
543
525
class NoRepositoryPresent(BzrError):
544
526
 
545
 
    _fmt = 'No repository present: "%(path)s"'
546
 
 
547
 
    def __init__(self, controldir):
548
 
        BzrError.__init__(self)
549
 
        self.path = controldir.transport.clone('..').base
 
527
    _fmt = "No repository present: %(path)r"
 
528
    def __init__(self, bzrdir):
 
529
        BzrError.__init__(self)
 
530
        self.path = bzrdir.transport.clone('..').base
 
531
 
 
532
 
 
533
class FileInWrongBranch(BzrError):
 
534
 
 
535
    _fmt = "File %(path)s in not in branch %(branch_base)s."
 
536
 
 
537
    def __init__(self, branch, path):
 
538
        BzrError.__init__(self)
 
539
        self.branch = branch
 
540
        self.branch_base = branch.base
 
541
        self.path = path
550
542
 
551
543
 
552
544
class UnsupportedFormatError(BzrError):
553
545
 
554
 
    _fmt = "Unsupported branch format: %(format)s\nPlease run 'brz upgrade'"
 
546
    _fmt = "Unsupported branch format: %(format)s\nPlease run 'bzr upgrade'"
555
547
 
556
548
 
557
549
class UnknownFormatError(BzrError):
558
 
 
559
 
    _fmt = "Unknown %(kind)s format: %(format)r"
560
 
 
561
 
    def __init__(self, format, kind='branch'):
562
 
        self.kind = kind
563
 
        self.format = format
 
550
    
 
551
    _fmt = "Unknown branch format: %(format)r"
564
552
 
565
553
 
566
554
class IncompatibleFormat(BzrError):
567
 
 
568
 
    _fmt = "Format %(format)s is not compatible with .bzr version %(controldir)s."
569
 
 
570
 
    def __init__(self, format, controldir_format):
571
 
        BzrError.__init__(self)
572
 
        self.format = format
573
 
        self.controldir = controldir_format
574
 
 
575
 
 
576
 
class ParseFormatError(BzrError):
577
 
 
578
 
    _fmt = "Parse error on line %(lineno)d of %(format)s format: %(line)s"
579
 
 
580
 
    def __init__(self, format, lineno, line, text):
581
 
        BzrError.__init__(self)
582
 
        self.format = format
583
 
        self.lineno = lineno
584
 
        self.line = line
585
 
        self.text = text
 
555
    
 
556
    _fmt = "Format %(format)s is not compatible with .bzr version %(bzrdir)s."
 
557
 
 
558
    def __init__(self, format, bzrdir_format):
 
559
        BzrError.__init__(self)
 
560
        self.format = format
 
561
        self.bzrdir = bzrdir_format
586
562
 
587
563
 
588
564
class IncompatibleRepositories(BzrError):
589
 
    """Report an error that two repositories are not compatible.
590
 
 
591
 
    Note that the source and target repositories are permitted to be strings:
592
 
    this exception is thrown from the smart server and may refer to a
593
 
    repository the client hasn't opened.
594
 
    """
595
 
 
596
 
    _fmt = "%(target)s\n" \
597
 
        "is not compatible with\n" \
598
 
        "%(source)s\n" \
599
 
        "%(details)s"
600
 
 
601
 
    def __init__(self, source, target, details=None):
602
 
        if details is None:
603
 
            details = "(no details)"
604
 
        BzrError.__init__(self, target=target, source=source, details=details)
 
565
 
 
566
    _fmt = "Repository %(target)s is not compatible with repository"\
 
567
        " %(source)s"
 
568
 
 
569
    def __init__(self, source, target):
 
570
        BzrError.__init__(self, target=target, source=source)
605
571
 
606
572
 
607
573
class IncompatibleRevision(BzrError):
608
 
 
 
574
    
609
575
    _fmt = "Revision is not compatible with %(repo_format)s"
610
576
 
611
577
    def __init__(self, repo_format):
616
582
class AlreadyVersionedError(BzrError):
617
583
    """Used when a path is expected not to be versioned, but it is."""
618
584
 
619
 
    _fmt = "%(context_info)s%(path)s is already versioned."
 
585
    _fmt = "%(context_info)s%(path)s is already versioned"
620
586
 
621
587
    def __init__(self, path, context_info=None):
622
588
        """Construct a new AlreadyVersionedError.
623
589
 
624
590
        :param path: This is the path which is versioned,
625
 
            which should be in a user friendly form.
 
591
        which should be in a user friendly form.
626
592
        :param context_info: If given, this is information about the context,
627
 
            which could explain why this is expected to not be versioned.
 
593
        which could explain why this is expected to not be versioned.
628
594
        """
629
595
        BzrError.__init__(self)
630
596
        self.path = path
637
603
class NotVersionedError(BzrError):
638
604
    """Used when a path is expected to be versioned, but it is not."""
639
605
 
640
 
    _fmt = "%(context_info)s%(path)s is not versioned."
 
606
    _fmt = "%(context_info)s%(path)s is not versioned"
641
607
 
642
608
    def __init__(self, path, context_info=None):
643
609
        """Construct a new NotVersionedError.
644
610
 
645
611
        :param path: This is the path which is not versioned,
646
 
            which should be in a user friendly form.
 
612
        which should be in a user friendly form.
647
613
        :param context_info: If given, this is information about the context,
648
 
            which could explain why this is expected to be versioned.
 
614
        which could explain why this is expected to be versioned.
649
615
        """
650
616
        BzrError.__init__(self)
651
617
        self.path = path
661
627
    _fmt = "Path(s) are not versioned: %(paths_as_string)s"
662
628
 
663
629
    def __init__(self, paths):
664
 
        from breezy.osutils import quotefn
 
630
        from bzrlib.osutils import quotefn
665
631
        BzrError.__init__(self)
666
632
        self.paths = paths
667
633
        self.paths_as_string = ' '.join([quotefn(p) for p in paths])
676
642
 
677
643
    def __init__(self, paths, extra=None):
678
644
        # circular import
679
 
        from breezy.osutils import quotefn
 
645
        from bzrlib.osutils import quotefn
680
646
        BzrError.__init__(self)
681
647
        self.paths = paths
682
648
        self.paths_as_string = ' '.join([quotefn(p) for p in paths])
694
660
        BzrError.__init__(self, filename=filename, kind=kind)
695
661
 
696
662
 
697
 
class BadFilenameEncoding(BzrError):
698
 
 
699
 
    _fmt = ('Filename %(filename)r is not valid in your current filesystem'
700
 
            ' encoding %(fs_encoding)s')
701
 
 
702
 
    def __init__(self, filename, fs_encoding):
703
 
        BzrError.__init__(self)
704
 
        self.filename = filename
705
 
        self.fs_encoding = fs_encoding
706
 
 
707
 
 
708
663
class ForbiddenControlFileError(BzrError):
709
664
 
710
 
    _fmt = 'Cannot operate on "%(filename)s" because it is a control file'
711
 
 
712
 
 
713
 
class LockError(InternalBzrError):
 
665
    _fmt = "Cannot operate on %(filename)s because it is a control file"
 
666
 
 
667
 
 
668
class LockError(BzrError):
714
669
 
715
670
    _fmt = "Lock error: %(msg)s"
716
671
 
 
672
    internal_error = True
 
673
 
717
674
    # All exceptions from the lock/unlock functions should be from
718
675
    # this exception class.  They will be translated as necessary. The
719
676
    # original exception is available as e.original_error
720
677
    #
721
678
    # New code should prefer to raise specific subclasses
722
 
    def __init__(self, msg):
723
 
        self.msg = msg
 
679
    def __init__(self, message):
 
680
        # Python 2.5 uses a slot for StandardError.message,
 
681
        # so use a different variable name
 
682
        # so it is exposed in self.__dict__
 
683
        self.msg = message
724
684
 
725
685
 
726
686
class LockActive(LockError):
760
720
        self.obj = obj
761
721
 
762
722
 
763
 
class LockFailed(LockError):
764
 
 
765
 
    internal_error = False
766
 
 
767
 
    _fmt = "Cannot lock %(lock)s: %(why)s"
768
 
 
769
 
    def __init__(self, lock, why):
 
723
class ReadOnlyLockError(LockError):
 
724
 
 
725
    _fmt = "Cannot acquire write lock on %(fname)s. %(msg)s"
 
726
 
 
727
    def __init__(self, fname, msg):
770
728
        LockError.__init__(self, '')
771
 
        self.lock = lock
772
 
        self.why = why
 
729
        self.fname = fname
 
730
        self.msg = msg
773
731
 
774
732
 
775
733
class OutSideTransaction(BzrError):
799
757
 
800
758
class UnlockableTransport(LockError):
801
759
 
802
 
    internal_error = False
803
 
 
804
760
    _fmt = "Cannot lock: transport is read only: %(transport)s"
805
761
 
806
762
    def __init__(self, transport):
809
765
 
810
766
class LockContention(LockError):
811
767
 
812
 
    _fmt = 'Could not acquire lock "%(lock)s": %(msg)s'
 
768
    _fmt = "Could not acquire lock %(lock)s"
 
769
    # TODO: show full url for lock, combining the transport and relative
 
770
    # bits?
813
771
 
814
772
    internal_error = False
815
773
 
816
 
    def __init__(self, lock, msg=''):
 
774
    def __init__(self, lock):
817
775
        self.lock = lock
818
 
        self.msg = msg
819
776
 
820
777
 
821
778
class LockBroken(LockError):
842
799
        self.target = target
843
800
 
844
801
 
845
 
class LockCorrupt(LockError):
846
 
 
847
 
    _fmt = ("Lock is apparently held, but corrupted: %(corruption_info)s\n"
848
 
            "Use 'brz break-lock' to clear it")
849
 
 
850
 
    internal_error = False
851
 
 
852
 
    def __init__(self, corruption_info, file_data=None):
853
 
        self.corruption_info = corruption_info
854
 
        self.file_data = file_data
855
 
 
856
 
 
857
802
class LockNotHeld(LockError):
858
803
 
859
804
    _fmt = "Lock not held: %(lock)s"
868
813
 
869
814
    _fmt = "The object %(obj)s does not support token specifying a token when locking."
870
815
 
 
816
    internal_error = True
 
817
 
871
818
    def __init__(self, obj):
872
819
        self.obj = obj
873
820
 
883
830
        self.lock_token = lock_token
884
831
 
885
832
 
 
833
class PointlessCommit(BzrError):
 
834
 
 
835
    _fmt = "No changes to commit"
 
836
 
 
837
 
886
838
class UpgradeReadonly(BzrError):
887
839
 
888
840
    _fmt = "Upgrade URL cannot work with readonly URLs."
897
849
        self.format = format
898
850
 
899
851
 
900
 
class NoSuchRevision(InternalBzrError):
901
 
 
902
 
    _fmt = "%(branch)s has no revision %(revision)s"
 
852
class StrictCommitFailed(Exception):
 
853
 
 
854
    _fmt = "Commit refused because there are unknowns in the tree."
 
855
 
 
856
 
 
857
class NoSuchRevision(BzrError):
 
858
 
 
859
    _fmt = "Branch %(branch)s has no revision %(revision)s"
 
860
 
 
861
    internal_error = True
903
862
 
904
863
    def __init__(self, branch, revision):
905
 
        # 'branch' may sometimes be an internal object like a KnitRevisionStore
906
864
        BzrError.__init__(self, branch=branch, revision=revision)
907
865
 
908
866
 
909
 
class RangeInChangeOption(BzrError):
910
 
 
911
 
    _fmt = "Option --change does not accept revision ranges"
 
867
class NotLeftParentDescendant(BzrError):
 
868
 
 
869
    _fmt = ("Revision %(old_revision)s is not the left parent of"
 
870
            " %(new_revision)s, but branch %(branch_location)s expects this")
 
871
 
 
872
    internal_error = True
 
873
 
 
874
    def __init__(self, branch, old_revision, new_revision):
 
875
        BzrError.__init__(self, branch_location=branch.base,
 
876
                          old_revision=old_revision,
 
877
                          new_revision=new_revision)
912
878
 
913
879
 
914
880
class NoSuchRevisionSpec(BzrError):
921
887
 
922
888
class NoSuchRevisionInTree(NoSuchRevision):
923
889
    """When using Tree.revision_tree, and the revision is not accessible."""
924
 
 
925
 
    _fmt = "The revision id {%(revision_id)s} is not present in the tree %(tree)s."
 
890
    
 
891
    _fmt = "The revision id %(revision_id)s is not present in the tree %(tree)s."
926
892
 
927
893
    def __init__(self, tree, revision_id):
928
894
        BzrError.__init__(self)
930
896
        self.revision_id = revision_id
931
897
 
932
898
 
 
899
class InvalidRevisionSpec(BzrError):
 
900
 
 
901
    _fmt = ("Requested revision: %(spec)r does not exist in branch:"
 
902
            " %(branch)s%(extra)s")
 
903
 
 
904
    def __init__(self, spec, branch, extra=None):
 
905
        BzrError.__init__(self, branch=branch, spec=spec)
 
906
        if extra:
 
907
            self.extra = '\n' + str(extra)
 
908
        else:
 
909
            self.extra = ''
 
910
 
 
911
 
 
912
class HistoryMissing(BzrError):
 
913
 
 
914
    _fmt = "%(branch)s is missing %(object_type)s {%(object_id)s}"
 
915
 
 
916
 
933
917
class AppendRevisionsOnlyViolation(BzrError):
934
918
 
935
919
    _fmt = ('Operation denied because it would change the main history,'
936
 
            ' which is not permitted by the append_revisions_only setting on'
937
 
            ' branch "%(location)s".')
 
920
           ' which is not permitted by the append_revisions_only setting on'
 
921
           ' branch "%(location)s".')
938
922
 
939
923
    def __init__(self, location):
940
 
        import breezy.urlutils as urlutils
941
 
        location = urlutils.unescape_for_display(location, 'ascii')
942
 
        BzrError.__init__(self, location=location)
 
924
       import bzrlib.urlutils as urlutils
 
925
       location = urlutils.unescape_for_display(location, 'ascii')
 
926
       BzrError.__init__(self, location=location)
943
927
 
944
928
 
945
929
class DivergedBranches(BzrError):
946
930
 
947
931
    _fmt = ("These branches have diverged."
948
 
            " Use the missing command to see how.\n"
949
 
            "Use the merge command to reconcile them.")
 
932
            " Use the merge command to reconcile them.")
 
933
 
 
934
    internal_error = False
950
935
 
951
936
    def __init__(self, branch1, branch2):
952
937
        self.branch1 = branch1
953
938
        self.branch2 = branch2
954
939
 
955
940
 
956
 
class NotLefthandHistory(InternalBzrError):
 
941
class NotLefthandHistory(BzrError):
957
942
 
958
943
    _fmt = "Supplied history does not follow left-hand parents"
959
944
 
 
945
    internal_error = True
 
946
 
960
947
    def __init__(self, history):
961
948
        BzrError.__init__(self, history=history)
962
949
 
966
953
    _fmt = ("Branches have no common ancestor, and"
967
954
            " no merge base revision was specified.")
968
955
 
969
 
 
970
 
class CannotReverseCherrypick(BzrError):
971
 
 
972
 
    _fmt = ('Selected merge cannot perform reverse cherrypicks.  Try merge3'
973
 
            ' or diff3.')
 
956
    internal_error = False
974
957
 
975
958
 
976
959
class NoCommonAncestor(BzrError):
977
 
 
 
960
    
978
961
    _fmt = "Revisions have no common ancestor: %(revision_a)s %(revision_b)s"
979
962
 
980
963
    def __init__(self, revision_a, revision_b):
985
968
class NoCommonRoot(BzrError):
986
969
 
987
970
    _fmt = ("Revisions are not derived from the same root: "
988
 
            "%(revision_a)s %(revision_b)s.")
 
971
           "%(revision_a)s %(revision_b)s.")
989
972
 
990
973
    def __init__(self, revision_a, revision_b):
991
974
        BzrError.__init__(self, revision_a=revision_a, revision_b=revision_b)
997
980
 
998
981
    def __init__(self, rev_id, not_ancestor_id):
999
982
        BzrError.__init__(self, rev_id=rev_id,
1000
 
                          not_ancestor_id=not_ancestor_id)
1001
 
 
1002
 
 
1003
 
class NoCommits(BranchError):
 
983
            not_ancestor_id=not_ancestor_id)
 
984
 
 
985
 
 
986
class InstallFailed(BzrError):
 
987
 
 
988
    def __init__(self, revisions):
 
989
        revision_str = ", ".join(str(r) for r in revisions)
 
990
        msg = "Could not install revisions:\n%s" % revision_str
 
991
        BzrError.__init__(self, msg)
 
992
        self.revisions = revisions
 
993
 
 
994
 
 
995
class AmbiguousBase(BzrError):
 
996
 
 
997
    def __init__(self, bases):
 
998
        warn("BzrError AmbiguousBase has been deprecated as of bzrlib 0.8.",
 
999
                DeprecationWarning)
 
1000
        msg = ("The correct base is unclear, because %s are all equally close"
 
1001
                % ", ".join(bases))
 
1002
        BzrError.__init__(self, msg)
 
1003
        self.bases = bases
 
1004
 
 
1005
 
 
1006
class NoCommits(BzrError):
1004
1007
 
1005
1008
    _fmt = "Branch %(branch)s has no commits."
1006
1009
 
 
1010
    def __init__(self, branch):
 
1011
        BzrError.__init__(self, branch=branch)
 
1012
 
1007
1013
 
1008
1014
class UnlistableStore(BzrError):
1009
1015
 
1011
1017
        BzrError.__init__(self, "Store %s is not listable" % store)
1012
1018
 
1013
1019
 
 
1020
 
1014
1021
class UnlistableBranch(BzrError):
1015
1022
 
1016
1023
    def __init__(self, br):
1019
1026
 
1020
1027
class BoundBranchOutOfDate(BzrError):
1021
1028
 
1022
 
    _fmt = ("Bound branch %(branch)s is out of date with master branch"
1023
 
            " %(master)s.%(extra_help)s")
 
1029
    _fmt = ("Bound branch %(branch)s is out of date"
 
1030
            " with master branch %(master)s.")
1024
1031
 
1025
1032
    def __init__(self, branch, master):
1026
1033
        BzrError.__init__(self)
1027
1034
        self.branch = branch
1028
1035
        self.master = master
1029
 
        self.extra_help = ''
1030
 
 
1031
 
 
 
1036
 
 
1037
        
1032
1038
class CommitToDoubleBoundBranch(BzrError):
1033
1039
 
1034
1040
    _fmt = ("Cannot commit to branch %(branch)s."
1062
1068
        self.error = error
1063
1069
 
1064
1070
 
 
1071
class WeaveError(BzrError):
 
1072
 
 
1073
    _fmt = "Error in processing weave: %(message)s"
 
1074
 
 
1075
    def __init__(self, message=None):
 
1076
        BzrError.__init__(self)
 
1077
        self.message = message
 
1078
 
 
1079
 
 
1080
class WeaveRevisionAlreadyPresent(WeaveError):
 
1081
 
 
1082
    _fmt = "Revision {%(revision_id)s} already present in %(weave)s"
 
1083
 
 
1084
    def __init__(self, revision_id, weave):
 
1085
 
 
1086
        WeaveError.__init__(self)
 
1087
        self.revision_id = revision_id
 
1088
        self.weave = weave
 
1089
 
 
1090
 
 
1091
class WeaveRevisionNotPresent(WeaveError):
 
1092
 
 
1093
    _fmt = "Revision {%(revision_id)s} not present in %(weave)s"
 
1094
 
 
1095
    def __init__(self, revision_id, weave):
 
1096
        WeaveError.__init__(self)
 
1097
        self.revision_id = revision_id
 
1098
        self.weave = weave
 
1099
 
 
1100
 
 
1101
class WeaveFormatError(WeaveError):
 
1102
 
 
1103
    _fmt = "Weave invariant violated: %(what)s"
 
1104
 
 
1105
    def __init__(self, what):
 
1106
        WeaveError.__init__(self)
 
1107
        self.what = what
 
1108
 
 
1109
 
 
1110
class WeaveParentMismatch(WeaveError):
 
1111
 
 
1112
    _fmt = "Parents are mismatched between two revisions."
 
1113
    
 
1114
 
 
1115
class WeaveInvalidChecksum(WeaveError):
 
1116
 
 
1117
    _fmt = "Text did not match it's checksum: %(message)s"
 
1118
 
 
1119
 
 
1120
class WeaveTextDiffers(WeaveError):
 
1121
 
 
1122
    _fmt = ("Weaves differ on text content. Revision:"
 
1123
            " {%(revision_id)s}, %(weave_a)s, %(weave_b)s")
 
1124
 
 
1125
    def __init__(self, revision_id, weave_a, weave_b):
 
1126
        WeaveError.__init__(self)
 
1127
        self.revision_id = revision_id
 
1128
        self.weave_a = weave_a
 
1129
        self.weave_b = weave_b
 
1130
 
 
1131
 
 
1132
class WeaveTextDiffers(WeaveError):
 
1133
 
 
1134
    _fmt = ("Weaves differ on text content. Revision:"
 
1135
            " {%(revision_id)s}, %(weave_a)s, %(weave_b)s")
 
1136
 
 
1137
    def __init__(self, revision_id, weave_a, weave_b):
 
1138
        WeaveError.__init__(self)
 
1139
        self.revision_id = revision_id
 
1140
        self.weave_a = weave_a
 
1141
        self.weave_b = weave_b
 
1142
 
 
1143
 
1065
1144
class VersionedFileError(BzrError):
1066
 
 
 
1145
    
1067
1146
    _fmt = "Versioned file error"
1068
1147
 
1069
1148
 
1070
1149
class RevisionNotPresent(VersionedFileError):
1071
 
 
1072
 
    _fmt = 'Revision {%(revision_id)s} not present in "%(file_id)s".'
 
1150
    
 
1151
    _fmt = "Revision {%(revision_id)s} not present in %(file_id)s."
1073
1152
 
1074
1153
    def __init__(self, revision_id, file_id):
1075
1154
        VersionedFileError.__init__(self)
1078
1157
 
1079
1158
 
1080
1159
class RevisionAlreadyPresent(VersionedFileError):
1081
 
 
1082
 
    _fmt = 'Revision {%(revision_id)s} already present in "%(file_id)s".'
 
1160
    
 
1161
    _fmt = "Revision {%(revision_id)s} already present in %(file_id)s."
1083
1162
 
1084
1163
    def __init__(self, revision_id, file_id):
1085
1164
        VersionedFileError.__init__(self)
1087
1166
        self.file_id = file_id
1088
1167
 
1089
1168
 
1090
 
class VersionedFileInvalidChecksum(VersionedFileError):
1091
 
 
1092
 
    _fmt = "Text did not match its checksum: %(msg)s"
1093
 
 
1094
 
 
1095
 
class RetryWithNewPacks(BzrError):
1096
 
    """Raised when we realize that the packs on disk have changed.
1097
 
 
1098
 
    This is meant as more of a signaling exception, to trap between where a
1099
 
    local error occurred and the code that can actually handle the error and
1100
 
    code that can retry appropriately.
1101
 
    """
1102
 
 
1103
 
    internal_error = True
1104
 
 
1105
 
    _fmt = ("Pack files have changed, reload and retry. context: %(context)s"
1106
 
            " %(orig_error)s")
1107
 
 
1108
 
    def __init__(self, context, reload_occurred, exc_info):
1109
 
        """create a new RetryWithNewPacks error.
1110
 
 
1111
 
        :param reload_occurred: Set to True if we know that the packs have
1112
 
            already been reloaded, and we are failing because of an in-memory
1113
 
            cache miss. If set to True then we will ignore if a reload says
1114
 
            nothing has changed, because we assume it has already reloaded. If
1115
 
            False, then a reload with nothing changed will force an error.
1116
 
        :param exc_info: The original exception traceback, so if there is a
1117
 
            problem we can raise the original error (value from sys.exc_info())
1118
 
        """
1119
 
        BzrError.__init__(self)
1120
 
        self.context = context
1121
 
        self.reload_occurred = reload_occurred
1122
 
        self.exc_info = exc_info
1123
 
        self.orig_error = exc_info[1]
1124
 
        # TODO: The global error handler should probably treat this by
1125
 
        #       raising/printing the original exception with a bit about
1126
 
        #       RetryWithNewPacks also not being caught
1127
 
 
1128
 
 
1129
 
class RetryAutopack(RetryWithNewPacks):
1130
 
    """Raised when we are autopacking and we find a missing file.
1131
 
 
1132
 
    Meant as a signaling exception, to tell the autopack code it should try
1133
 
    again.
1134
 
    """
1135
 
 
1136
 
    internal_error = True
1137
 
 
1138
 
    _fmt = ("Pack files have changed, reload and try autopack again."
1139
 
            " context: %(context)s %(orig_error)s")
 
1169
class KnitError(BzrError):
 
1170
    
 
1171
    _fmt = "Knit error"
 
1172
 
 
1173
    internal_error = True
 
1174
 
 
1175
 
 
1176
class KnitHeaderError(KnitError):
 
1177
 
 
1178
    _fmt = "Knit header error: %(badline)r unexpected for file %(filename)s"
 
1179
 
 
1180
    def __init__(self, badline, filename):
 
1181
        KnitError.__init__(self)
 
1182
        self.badline = badline
 
1183
        self.filename = filename
 
1184
 
 
1185
 
 
1186
class KnitCorrupt(KnitError):
 
1187
 
 
1188
    _fmt = "Knit %(filename)s corrupt: %(how)s"
 
1189
 
 
1190
    def __init__(self, filename, how):
 
1191
        KnitError.__init__(self)
 
1192
        self.filename = filename
 
1193
        self.how = how
 
1194
 
 
1195
 
 
1196
class KnitIndexUnknownMethod(KnitError):
 
1197
    """Raised when we don't understand the storage method.
 
1198
 
 
1199
    Currently only 'fulltext' and 'line-delta' are supported.
 
1200
    """
 
1201
    
 
1202
    _fmt = ("Knit index %(filename)s does not have a known method"
 
1203
            " in options: %(options)r")
 
1204
 
 
1205
    def __init__(self, filename, options):
 
1206
        KnitError.__init__(self)
 
1207
        self.filename = filename
 
1208
        self.options = options
1140
1209
 
1141
1210
 
1142
1211
class NoSuchExportFormat(BzrError):
1143
 
 
 
1212
    
1144
1213
    _fmt = "Export format %(format)r not supported"
1145
1214
 
1146
1215
    def __init__(self, format):
1149
1218
 
1150
1219
 
1151
1220
class TransportError(BzrError):
1152
 
 
 
1221
    
1153
1222
    _fmt = "Transport error: %(msg)s %(orig_error)s"
1154
1223
 
1155
1224
    def __init__(self, msg=None, orig_error=None):
1158
1227
        if orig_error is None:
1159
1228
            orig_error = ''
1160
1229
        if msg is None:
1161
 
            msg = ''
 
1230
            msg =  ''
1162
1231
        self.msg = msg
1163
1232
        self.orig_error = orig_error
1164
1233
        BzrError.__init__(self)
1165
1234
 
1166
1235
 
1167
 
class TooManyConcurrentRequests(InternalBzrError):
 
1236
class TooManyConcurrentRequests(BzrError):
1168
1237
 
1169
1238
    _fmt = ("The medium '%(medium)s' has reached its concurrent request limit."
1170
1239
            " Be sure to finish_writing and finish_reading on the"
1171
 
            " currently open request.")
 
1240
            " current request that is open.")
 
1241
 
 
1242
    internal_error = True
1172
1243
 
1173
1244
    def __init__(self, medium):
1174
1245
        self.medium = medium
1182
1253
        self.details = details
1183
1254
 
1184
1255
 
1185
 
class UnexpectedProtocolVersionMarker(TransportError):
1186
 
 
1187
 
    _fmt = "Received bad protocol version marker: %(marker)r"
1188
 
 
1189
 
    def __init__(self, marker):
1190
 
        self.marker = marker
1191
 
 
1192
 
 
1193
 
class UnknownSmartMethod(InternalBzrError):
1194
 
 
1195
 
    _fmt = "The server does not recognise the '%(verb)s' request."
1196
 
 
1197
 
    def __init__(self, verb):
1198
 
        self.verb = verb
1199
 
 
1200
 
 
1201
 
class SmartMessageHandlerError(InternalBzrError):
1202
 
 
1203
 
    _fmt = ("The message handler raised an exception:\n"
1204
 
            "%(traceback_text)s")
1205
 
 
1206
 
    def __init__(self, exc_info):
1207
 
        import traceback
1208
 
        # GZ 2010-08-10: Cycle with exc_tb/exc_info affects at least one test
1209
 
        self.exc_type, self.exc_value, self.exc_tb = exc_info
1210
 
        self.exc_info = exc_info
1211
 
        traceback_strings = traceback.format_exception(
1212
 
            self.exc_type, self.exc_value, self.exc_tb)
1213
 
        self.traceback_text = ''.join(traceback_strings)
1214
 
 
1215
 
 
1216
1256
# A set of semi-meaningful errors which can be thrown
1217
1257
class TransportNotPossible(TransportError):
1218
1258
 
1243
1283
            self.port = ':%s' % port
1244
1284
 
1245
1285
 
1246
 
# XXX: This is also used for unexpected end of file, which is different at the
1247
 
# TCP level from "connection reset".
1248
1286
class ConnectionReset(TransportError):
1249
1287
 
1250
1288
    _fmt = "Connection closed: %(msg)s %(orig_error)s"
1251
1289
 
1252
1290
 
1253
 
class ConnectionTimeout(ConnectionError):
1254
 
 
1255
 
    _fmt = "Connection Timeout: %(msg)s%(orig_error)s"
1256
 
 
1257
 
 
1258
1291
class InvalidRange(TransportError):
1259
1292
 
1260
 
    _fmt = "Invalid range access in %(path)s at %(offset)s: %(msg)s"
1261
 
 
1262
 
    def __init__(self, path, offset, msg=None):
1263
 
        TransportError.__init__(self, msg)
 
1293
    _fmt = "Invalid range access in %(path)s at %(offset)s."
 
1294
    
 
1295
    def __init__(self, path, offset):
 
1296
        TransportError.__init__(self, ("Invalid range access in %s at %d"
 
1297
                                       % (path, offset)))
1264
1298
        self.path = path
1265
1299
        self.offset = offset
1266
1300
 
1267
1301
 
1268
1302
class InvalidHttpResponse(TransportError):
1269
1303
 
1270
 
    _fmt = "Invalid http response for %(path)s: %(msg)s%(orig_error)s"
 
1304
    _fmt = "Invalid http response for %(path)s: %(msg)s"
1271
1305
 
1272
1306
    def __init__(self, path, msg, orig_error=None):
1273
1307
        self.path = path
1274
 
        if orig_error is None:
1275
 
            orig_error = ''
1276
 
        else:
1277
 
            # This is reached for obscure and unusual errors so we want to
1278
 
            # preserve as much info as possible to ease debug.
1279
 
            orig_error = ': %r' % (orig_error,)
1280
1308
        TransportError.__init__(self, msg, orig_error=orig_error)
1281
1309
 
1282
1310
 
1283
 
class UnexpectedHttpStatus(InvalidHttpResponse):
1284
 
 
1285
 
    _fmt = "Unexpected HTTP status %(code)d for %(path)s: %(extra)s"
1286
 
 
1287
 
    def __init__(self, path, code, extra=None):
1288
 
        self.path = path
1289
 
        self.code = code
1290
 
        self.extra = extra or ''
1291
 
        full_msg = 'status code %d unexpected' % code
1292
 
        if extra is not None:
1293
 
            full_msg += ': ' + extra
1294
 
        InvalidHttpResponse.__init__(
1295
 
            self, path, full_msg)
1296
 
 
1297
 
 
1298
 
class BadHttpRequest(UnexpectedHttpStatus):
1299
 
 
1300
 
    _fmt = "Bad http request for %(path)s: %(reason)s"
1301
 
 
1302
 
    def __init__(self, path, reason):
1303
 
        self.path = path
1304
 
        self.reason = reason
1305
 
        TransportError.__init__(self, reason)
1306
 
 
1307
 
 
1308
1311
class InvalidHttpRange(InvalidHttpResponse):
1309
1312
 
1310
1313
    _fmt = "Invalid http range %(range)r for %(path)s: %(msg)s"
1311
 
 
 
1314
    
1312
1315
    def __init__(self, path, range, msg):
1313
1316
        self.range = range
1314
1317
        InvalidHttpResponse.__init__(self, path, msg)
1315
1318
 
1316
1319
 
1317
 
class HttpBoundaryMissing(InvalidHttpResponse):
1318
 
    """A multipart response ends with no boundary marker.
1319
 
 
1320
 
    This is a special case caused by buggy proxies, described in
1321
 
    <https://bugs.launchpad.net/bzr/+bug/198646>.
1322
 
    """
1323
 
 
1324
 
    _fmt = "HTTP MIME Boundary missing for %(path)s: %(msg)s"
1325
 
 
1326
 
    def __init__(self, path, msg):
1327
 
        InvalidHttpResponse.__init__(self, path, msg)
1328
 
 
1329
 
 
1330
1320
class InvalidHttpContentType(InvalidHttpResponse):
1331
1321
 
1332
1322
    _fmt = 'Invalid http Content-type "%(ctype)s" for %(path)s: %(msg)s'
1333
 
 
 
1323
    
1334
1324
    def __init__(self, path, ctype, msg):
1335
1325
        self.ctype = ctype
1336
1326
        InvalidHttpResponse.__init__(self, path, msg)
1340
1330
 
1341
1331
    _fmt = '%(source)s is%(permanently)s redirected to %(target)s'
1342
1332
 
1343
 
    def __init__(self, source, target, is_permanent=False):
 
1333
    def __init__(self, source, target, is_permament=False, qual_proto=None):
1344
1334
        self.source = source
1345
1335
        self.target = target
1346
 
        if is_permanent:
 
1336
        if is_permament:
1347
1337
            self.permanently = ' permanently'
1348
1338
        else:
1349
1339
            self.permanently = ''
 
1340
        self.is_permament = is_permament
 
1341
        self._qualified_proto = qual_proto
1350
1342
        TransportError.__init__(self)
1351
1343
 
 
1344
    def _requalify_url(self, url):
 
1345
        """Restore the qualified proto in front of the url"""
 
1346
        # When this exception is raised, source and target are in
 
1347
        # user readable format. But some transports may use a
 
1348
        # different proto (http+urllib:// will present http:// to
 
1349
        # the user. If a qualified proto is specified, the code
 
1350
        # trapping the exception can get the qualified urls to
 
1351
        # properly handle the redirection themself (creating a
 
1352
        # new transport object from the target url for example).
 
1353
        # But checking that the scheme of the original and
 
1354
        # redirected urls are the same can be tricky. (see the
 
1355
        # FIXME in BzrDir.open_from_transport for the unique use
 
1356
        # case so far).
 
1357
        if self._qualified_proto is None:
 
1358
            return url
 
1359
 
 
1360
        # The TODO related to NotBranchError mention that doing
 
1361
        # that kind of manipulation on the urls may not be the
 
1362
        # exception object job. On the other hand, this object is
 
1363
        # the interface between the code and the user so
 
1364
        # presenting the urls in different ways is indeed its
 
1365
        # job...
 
1366
        import urlparse
 
1367
        proto, netloc, path, query, fragment = urlparse.urlsplit(url)
 
1368
        return urlparse.urlunsplit((self._qualified_proto, netloc, path,
 
1369
                                   query, fragment))
 
1370
 
 
1371
    def get_source_url(self):
 
1372
        return self._requalify_url(self.source)
 
1373
 
 
1374
    def get_target_url(self):
 
1375
        return self._requalify_url(self.target)
 
1376
 
1352
1377
 
1353
1378
class TooManyRedirections(TransportError):
1354
1379
 
1355
1380
    _fmt = "Too many redirections"
1356
1381
 
1357
 
 
1358
1382
class ConflictsInTree(BzrError):
1359
1383
 
1360
1384
    _fmt = "Working tree has conflicts."
1361
1385
 
1362
1386
 
1363
 
class DependencyNotPresent(BzrError):
1364
 
 
1365
 
    _fmt = 'Unable to import library "%(library)s": %(error)s'
1366
 
 
1367
 
    def __init__(self, library, error):
1368
 
        BzrError.__init__(self, library=library, error=error)
 
1387
class ParseConfigError(BzrError):
 
1388
 
 
1389
    def __init__(self, errors, filename):
 
1390
        if filename is None:
 
1391
            filename = ""
 
1392
        message = "Error(s) parsing config file %s:\n%s" % \
 
1393
            (filename, ('\n'.join(e.message for e in errors)))
 
1394
        BzrError.__init__(self, message)
 
1395
 
 
1396
 
 
1397
class NoEmailInUsername(BzrError):
 
1398
 
 
1399
    _fmt = "%(username)r does not seem to contain a reasonable email address"
 
1400
 
 
1401
    def __init__(self, username):
 
1402
        BzrError.__init__(self)
 
1403
        self.username = username
 
1404
 
 
1405
 
 
1406
class SigningFailed(BzrError):
 
1407
 
 
1408
    _fmt = "Failed to gpg sign data with command %(command_line)r"
 
1409
 
 
1410
    def __init__(self, command_line):
 
1411
        BzrError.__init__(self, command_line=command_line)
1369
1412
 
1370
1413
 
1371
1414
class WorkingTreeNotRevision(BzrError):
1372
1415
 
1373
 
    _fmt = ("The working tree for %(basedir)s has changed since"
 
1416
    _fmt = ("The working tree for %(basedir)s has changed since" 
1374
1417
            " the last commit, but weave merge requires that it be"
1375
1418
            " unchanged")
1376
1419
 
1378
1421
        BzrError.__init__(self, basedir=tree.basedir)
1379
1422
 
1380
1423
 
 
1424
class CantReprocessAndShowBase(BzrError):
 
1425
 
 
1426
    _fmt = ("Can't reprocess and show base, because reprocessing obscures "
 
1427
           "the relationship of conflicting lines to the base")
 
1428
 
 
1429
 
1381
1430
class GraphCycleError(BzrError):
1382
1431
 
1383
1432
    _fmt = "Cycle in graph %(graph)r"
1387
1436
        self.graph = graph
1388
1437
 
1389
1438
 
1390
 
class WritingCompleted(InternalBzrError):
 
1439
class WritingCompleted(BzrError):
1391
1440
 
1392
1441
    _fmt = ("The MediumRequest '%(request)s' has already had finish_writing "
1393
1442
            "called upon it - accept bytes may not be called anymore.")
1394
1443
 
 
1444
    internal_error = True
 
1445
 
1395
1446
    def __init__(self, request):
1396
1447
        self.request = request
1397
1448
 
1398
1449
 
1399
 
class WritingNotComplete(InternalBzrError):
 
1450
class WritingNotComplete(BzrError):
1400
1451
 
1401
1452
    _fmt = ("The MediumRequest '%(request)s' has not has finish_writing "
1402
1453
            "called upon it - until the write phase is complete no "
1403
1454
            "data may be read.")
1404
1455
 
 
1456
    internal_error = True
 
1457
 
1405
1458
    def __init__(self, request):
1406
1459
        self.request = request
1407
1460
 
1415
1468
        self.filename = filename
1416
1469
 
1417
1470
 
1418
 
class MediumNotConnected(InternalBzrError):
 
1471
class MediumNotConnected(BzrError):
1419
1472
 
1420
1473
    _fmt = """The medium '%(medium)s' is not connected."""
1421
1474
 
 
1475
    internal_error = True
 
1476
 
1422
1477
    def __init__(self, medium):
1423
1478
        self.medium = medium
1424
1479
 
1430
1485
 
1431
1486
class NoBundleFound(BzrError):
1432
1487
 
1433
 
    _fmt = 'No bundle was found in "%(filename)s".'
 
1488
    _fmt = "No bundle was found in %(filename)s"
1434
1489
 
1435
1490
    def __init__(self, filename):
1436
1491
        BzrError.__init__(self)
1460
1515
        self.file_id = file_id
1461
1516
 
1462
1517
 
 
1518
class DuplicateFileId(BzrError):
 
1519
 
 
1520
    _fmt = "File id {%(file_id)s} already exists in inventory as %(entry)s"
 
1521
 
 
1522
    def __init__(self, file_id, entry):
 
1523
        BzrError.__init__(self)
 
1524
        self.file_id = file_id
 
1525
        self.entry = entry
 
1526
 
 
1527
 
1463
1528
class DuplicateKey(BzrError):
1464
1529
 
1465
1530
    _fmt = "Key %(key)s is already present in map"
1466
1531
 
1467
1532
 
1468
 
class DuplicateHelpPrefix(BzrError):
1469
 
 
1470
 
    _fmt = "The prefix %(prefix)s is in the help search path twice."
1471
 
 
1472
 
    def __init__(self, prefix):
1473
 
        self.prefix = prefix
1474
 
 
1475
 
 
1476
 
class BzrBadParameter(InternalBzrError):
 
1533
class MalformedTransform(BzrError):
 
1534
 
 
1535
    _fmt = "Tree transform is malformed %(conflicts)r"
 
1536
 
 
1537
 
 
1538
class NoFinalPath(BzrError):
 
1539
 
 
1540
    _fmt = ("No final name for trans_id %(trans_id)r\n"
 
1541
            "file-id: %(file_id)r\n"
 
1542
            "root trans-id: %(root_trans_id)r\n")
 
1543
 
 
1544
    def __init__(self, trans_id, transform):
 
1545
        self.trans_id = trans_id
 
1546
        self.file_id = transform.final_file_id(trans_id)
 
1547
        self.root_trans_id = transform.root
 
1548
 
 
1549
 
 
1550
class BzrBadParameter(BzrError):
1477
1551
 
1478
1552
    _fmt = "Bad parameter: %(param)r"
1479
1553
 
1490
1564
    _fmt = "Parameter %(param)s is neither unicode nor utf8."
1491
1565
 
1492
1566
 
 
1567
class ReusingTransform(BzrError):
 
1568
 
 
1569
    _fmt = "Attempt to reuse a transform that has already been applied."
 
1570
 
 
1571
 
 
1572
class CantMoveRoot(BzrError):
 
1573
 
 
1574
    _fmt = "Moving the root directory is not supported at this time"
 
1575
 
 
1576
 
1493
1577
class BzrMoveFailedError(BzrError):
1494
1578
 
1495
 
    _fmt = ("Could not move %(from_path)s%(operator)s %(to_path)s"
1496
 
            "%(_has_extra)s%(extra)s")
 
1579
    _fmt = "Could not move %(from_path)s%(operator)s %(to_path)s%(extra)s"
1497
1580
 
1498
1581
    def __init__(self, from_path='', to_path='', extra=None):
1499
 
        from breezy.osutils import splitpath
1500
1582
        BzrError.__init__(self)
1501
1583
        if extra:
1502
 
            self.extra, self._has_extra = extra, ': '
 
1584
            self.extra = ': ' + str(extra)
1503
1585
        else:
1504
 
            self.extra = self._has_extra = ''
 
1586
            self.extra = ''
1505
1587
 
1506
1588
        has_from = len(from_path) > 0
1507
1589
        has_to = len(to_path) > 0
1508
1590
        if has_from:
1509
 
            self.from_path = splitpath(from_path)[-1]
 
1591
            self.from_path = osutils.splitpath(from_path)[-1]
1510
1592
        else:
1511
1593
            self.from_path = ''
1512
1594
 
1513
1595
        if has_to:
1514
 
            self.to_path = splitpath(to_path)[-1]
 
1596
            self.to_path = osutils.splitpath(to_path)[-1]
1515
1597
        else:
1516
1598
            self.to_path = ''
1517
1599
 
1528
1610
 
1529
1611
class BzrRenameFailedError(BzrMoveFailedError):
1530
1612
 
1531
 
    _fmt = ("Could not rename %(from_path)s%(operator)s %(to_path)s"
1532
 
            "%(_has_extra)s%(extra)s")
 
1613
    _fmt = "Could not rename %(from_path)s%(operator)s %(to_path)s%(extra)s"
1533
1614
 
1534
1615
    def __init__(self, from_path, to_path, extra=None):
1535
1616
        BzrMoveFailedError.__init__(self, from_path, to_path, extra)
1542
1623
 
1543
1624
class BzrBadParameterMissing(BzrBadParameter):
1544
1625
 
1545
 
    _fmt = "Parameter %(param)s is required but not present."
 
1626
    _fmt = "Parameter $(param)s is required but not present."
1546
1627
 
1547
1628
 
1548
1629
class BzrBadParameterUnicode(BzrBadParameter):
1556
1637
    _fmt = "Parameter %(param)s contains a newline."
1557
1638
 
1558
1639
 
 
1640
class DependencyNotPresent(BzrError):
 
1641
 
 
1642
    _fmt = 'Unable to import library "%(library)s": %(error)s'
 
1643
 
 
1644
    def __init__(self, library, error):
 
1645
        BzrError.__init__(self, library=library, error=error)
 
1646
 
 
1647
 
1559
1648
class ParamikoNotPresent(DependencyNotPresent):
1560
1649
 
1561
1650
    _fmt = "Unable to import paramiko (required for sftp support): %(error)s"
1571
1660
 
1572
1661
class UninitializableFormat(BzrError):
1573
1662
 
1574
 
    _fmt = "Format %(format)s cannot be initialised by this version of brz."
 
1663
    _fmt = "Format %(format)s cannot be initialised by this version of bzr."
1575
1664
 
1576
1665
    def __init__(self, format):
1577
1666
        BzrError.__init__(self)
1580
1669
 
1581
1670
class BadConversionTarget(BzrError):
1582
1671
 
1583
 
    _fmt = "Cannot convert from format %(from_format)s to format %(format)s." \
1584
 
        "    %(problem)s"
 
1672
    _fmt = "Cannot convert to format %(format)s.  %(problem)s"
1585
1673
 
1586
 
    def __init__(self, problem, format, from_format=None):
 
1674
    def __init__(self, problem, format):
1587
1675
        BzrError.__init__(self)
1588
1676
        self.problem = problem
1589
1677
        self.format = format
1590
 
        self.from_format = from_format or '(unspecified)'
1591
 
 
1592
 
 
1593
 
class NoDiffFound(BzrError):
1594
 
 
1595
 
    _fmt = 'Could not find an appropriate Differ for file "%(path)s"'
1596
 
 
1597
 
    def __init__(self, path):
1598
 
        BzrError.__init__(self, path)
1599
 
 
1600
 
 
1601
 
class ExecutableMissing(BzrError):
1602
 
 
1603
 
    _fmt = "%(exe_name)s could not be found on this machine"
1604
 
 
1605
 
    def __init__(self, exe_name):
1606
 
        BzrError.__init__(self, exe_name=exe_name)
1607
1678
 
1608
1679
 
1609
1680
class NoDiff(BzrError):
1624
1695
    _fmt = """This tree contains left-over files from a failed operation.
1625
1696
    Please examine %(limbo_dir)s to see if it contains any files you wish to
1626
1697
    keep, and delete it when you are done."""
1627
 
 
1628
 
    def __init__(self, limbo_dir):
1629
 
        BzrError.__init__(self)
1630
 
        self.limbo_dir = limbo_dir
1631
 
 
1632
 
 
1633
 
class ExistingPendingDeletion(BzrError):
1634
 
 
1635
 
    _fmt = """This tree contains left-over files from a failed operation.
1636
 
    Please examine %(pending_deletion)s to see if it contains any files you
1637
 
    wish to keep, and delete it when you are done."""
1638
 
 
1639
 
    def __init__(self, pending_deletion):
1640
 
        BzrError.__init__(self, pending_deletion=pending_deletion)
1641
 
 
1642
 
 
1643
 
class ImmortalPendingDeletion(BzrError):
1644
 
 
1645
 
    _fmt = ("Unable to delete transform temporary directory "
1646
 
            "%(pending_deletion)s.  Please examine %(pending_deletion)s to see if it "
1647
 
            "contains any files you wish to keep, and delete it when you are done.")
1648
 
 
1649
 
    def __init__(self, pending_deletion):
1650
 
        BzrError.__init__(self, pending_deletion=pending_deletion)
 
1698
    
 
1699
    def __init__(self, limbo_dir):
 
1700
       BzrError.__init__(self)
 
1701
       self.limbo_dir = limbo_dir
 
1702
 
 
1703
 
 
1704
class ImmortalLimbo(BzrError):
 
1705
 
 
1706
    _fmt = """Unable to delete transform temporary directory $(limbo_dir)s.
 
1707
    Please examine %(limbo_dir)s to see if it contains any files you wish to
 
1708
    keep, and delete it when you are done."""
 
1709
 
 
1710
    def __init__(self, limbo_dir):
 
1711
       BzrError.__init__(self)
 
1712
       self.limbo_dir = limbo_dir
1651
1713
 
1652
1714
 
1653
1715
class OutOfDateTree(BzrError):
1654
1716
 
1655
 
    _fmt = "Working tree is out of date, please run 'brz update'.%(more)s"
 
1717
    _fmt = "Working tree is out of date, please run 'bzr update'."
1656
1718
 
1657
 
    def __init__(self, tree, more=None):
1658
 
        if more is None:
1659
 
            more = ''
1660
 
        else:
1661
 
            more = ' ' + more
 
1719
    def __init__(self, tree):
1662
1720
        BzrError.__init__(self)
1663
1721
        self.tree = tree
1664
 
        self.more = more
1665
1722
 
1666
1723
 
1667
1724
class PublicBranchOutOfDate(BzrError):
1670
1727
        '"%(revstring)s".'
1671
1728
 
1672
1729
    def __init__(self, public_location, revstring):
1673
 
        import breezy.urlutils as urlutils
 
1730
        import bzrlib.urlutils as urlutils
1674
1731
        public_location = urlutils.unescape_for_display(public_location,
1675
1732
                                                        'ascii')
1676
1733
        BzrError.__init__(self, public_location=public_location,
1690
1747
class CorruptRepository(BzrError):
1691
1748
 
1692
1749
    _fmt = ("An error has been detected in the repository %(repo_path)s.\n"
1693
 
            "Please run brz reconcile on this repository.")
 
1750
            "Please run bzr reconcile on this repository.")
1694
1751
 
1695
1752
    def __init__(self, repo):
1696
1753
        BzrError.__init__(self)
1697
 
        self.repo_path = repo.user_url
1698
 
 
1699
 
 
1700
 
class InconsistentDelta(BzrError):
1701
 
    """Used when we get a delta that is not valid."""
1702
 
 
1703
 
    _fmt = ("An inconsistent delta was supplied involving %(path)r,"
1704
 
            " %(file_id)r\nreason: %(reason)s")
1705
 
 
1706
 
    def __init__(self, path, file_id, reason):
1707
 
        BzrError.__init__(self)
1708
 
        self.path = path
1709
 
        self.file_id = file_id
1710
 
        self.reason = reason
1711
 
 
1712
 
 
1713
 
class InconsistentDeltaDelta(InconsistentDelta):
1714
 
    """Used when we get a delta that is not valid."""
1715
 
 
1716
 
    _fmt = ("An inconsistent delta was supplied: %(delta)r"
1717
 
            "\nreason: %(reason)s")
1718
 
 
1719
 
    def __init__(self, delta, reason):
1720
 
        BzrError.__init__(self)
1721
 
        self.delta = delta
1722
 
        self.reason = reason
 
1754
        self.repo_path = repo.bzrdir.root_transport.base
1723
1755
 
1724
1756
 
1725
1757
class UpgradeRequired(BzrError):
1731
1763
        self.path = path
1732
1764
 
1733
1765
 
1734
 
class RepositoryUpgradeRequired(UpgradeRequired):
1735
 
 
1736
 
    _fmt = "To use this feature you must upgrade your repository at %(path)s."
1737
 
 
1738
 
 
1739
 
class RichRootUpgradeRequired(UpgradeRequired):
1740
 
 
1741
 
    _fmt = ("To use this feature you must upgrade your branch at %(path)s to"
1742
 
            " a format which supports rich roots.")
1743
 
 
1744
 
 
1745
1766
class LocalRequiresBoundBranch(BzrError):
1746
1767
 
1747
1768
    _fmt = "Cannot perform local-only commits on unbound branches."
1748
1769
 
1749
1770
 
 
1771
class MissingProgressBarFinish(BzrError):
 
1772
 
 
1773
    _fmt = "A nested progress bar was not 'finished' correctly."
 
1774
 
 
1775
 
 
1776
class InvalidProgressBarType(BzrError):
 
1777
 
 
1778
    _fmt = ("Environment variable BZR_PROGRESS_BAR='%(bar_type)s"
 
1779
            " is not a supported type Select one of: %(valid_types)s")
 
1780
 
 
1781
    def __init__(self, bar_type, valid_types):
 
1782
        BzrError.__init__(self, bar_type=bar_type, valid_types=valid_types)
 
1783
 
 
1784
 
1750
1785
class UnsupportedOperation(BzrError):
1751
1786
 
1752
1787
    _fmt = ("The method %(mname)s is not supported on"
1758
1793
        self.tname = type(method_self).__name__
1759
1794
 
1760
1795
 
1761
 
class FetchLimitUnsupported(UnsupportedOperation):
1762
 
 
1763
 
    fmt = ("InterBranch %(interbranch)r does not support fetching limits.")
1764
 
 
1765
 
    def __init__(self, interbranch):
1766
 
        BzrError.__init__(self, interbranch=interbranch)
 
1796
class CannotSetRevisionId(UnsupportedOperation):
 
1797
    """Raised when a commit is attempting to set a revision id but cant."""
1767
1798
 
1768
1799
 
1769
1800
class NonAsciiRevisionId(UnsupportedOperation):
1772
1803
    """
1773
1804
 
1774
1805
 
1775
 
class SharedRepositoriesUnsupported(UnsupportedOperation):
1776
 
    _fmt = "Shared repositories are not supported by %(format)r."
1777
 
 
1778
 
    def __init__(self, format):
1779
 
        BzrError.__init__(self, format=format)
1780
 
 
1781
 
 
1782
 
class GhostTagsNotSupported(BzrError):
1783
 
 
1784
 
    _fmt = "Ghost tags not supported by format %(format)r."
1785
 
 
1786
 
    def __init__(self, format):
1787
 
        self.format = format
1788
 
 
1789
 
 
1790
1806
class BinaryFile(BzrError):
1791
 
 
 
1807
    
1792
1808
    _fmt = "File is binary but should be text."
1793
1809
 
1794
1810
 
1814
1830
 
1815
1831
 
1816
1832
class NotABundle(BzrError):
1817
 
 
 
1833
    
1818
1834
    _fmt = "Not a bzr revision-bundle: %(text)r"
1819
1835
 
1820
1836
    def __init__(self, text):
1822
1838
        self.text = text
1823
1839
 
1824
1840
 
1825
 
class BadBundle(BzrError):
1826
 
 
 
1841
class BadBundle(BzrError): 
 
1842
    
1827
1843
    _fmt = "Bad bzr revision-bundle: %(text)r"
1828
1844
 
1829
1845
    def __init__(self, text):
1831
1847
        self.text = text
1832
1848
 
1833
1849
 
1834
 
class MalformedHeader(BadBundle):
1835
 
 
 
1850
class MalformedHeader(BadBundle): 
 
1851
    
1836
1852
    _fmt = "Malformed bzr revision-bundle header: %(text)r"
1837
1853
 
1838
1854
 
1839
 
class MalformedPatches(BadBundle):
1840
 
 
 
1855
class MalformedPatches(BadBundle): 
 
1856
    
1841
1857
    _fmt = "Malformed patches in bzr revision-bundle: %(text)r"
1842
1858
 
1843
1859
 
1844
 
class MalformedFooter(BadBundle):
1845
 
 
 
1860
class MalformedFooter(BadBundle): 
 
1861
    
1846
1862
    _fmt = "Malformed footer in bzr revision-bundle: %(text)r"
1847
1863
 
1848
1864
 
1849
1865
class UnsupportedEOLMarker(BadBundle):
1850
 
 
1851
 
    _fmt = "End of line marker was not \\n in bzr revision-bundle"
 
1866
    
 
1867
    _fmt = "End of line marker was not \\n in bzr revision-bundle"    
1852
1868
 
1853
1869
    def __init__(self):
1854
 
        # XXX: BadBundle's constructor assumes there's explanatory text,
 
1870
        # XXX: BadBundle's constructor assumes there's explanatory text, 
1855
1871
        # but for this there is not
1856
1872
        BzrError.__init__(self)
1857
1873
 
1858
1874
 
1859
1875
class IncompatibleBundleFormat(BzrError):
1860
 
 
 
1876
    
1861
1877
    _fmt = "Bundle format %(bundle_format)s is incompatible with %(other)s"
1862
1878
 
1863
1879
    def __init__(self, bundle_format, other):
1866
1882
        self.other = other
1867
1883
 
1868
1884
 
 
1885
class BadInventoryFormat(BzrError):
 
1886
    
 
1887
    _fmt = "Root class for inventory serialization errors"
 
1888
 
 
1889
 
 
1890
class UnexpectedInventoryFormat(BadInventoryFormat):
 
1891
 
 
1892
    _fmt = "The inventory was not in the expected format:\n %(msg)s"
 
1893
 
 
1894
    def __init__(self, msg):
 
1895
        BadInventoryFormat.__init__(self, msg=msg)
 
1896
 
 
1897
 
1869
1898
class RootNotRich(BzrError):
1870
1899
 
1871
1900
    _fmt = """This operation requires rich root data storage"""
1872
1901
 
1873
1902
 
1874
 
class NoSmartMedium(InternalBzrError):
 
1903
class NoSmartMedium(BzrError):
1875
1904
 
1876
1905
    _fmt = "The transport '%(transport)s' cannot tunnel the smart protocol."
1877
1906
 
 
1907
    internal_error = True
 
1908
 
1878
1909
    def __init__(self, transport):
1879
1910
        self.transport = transport
1880
1911
 
1881
1912
 
 
1913
class NoSmartServer(NotBranchError):
 
1914
 
 
1915
    _fmt = "No smart server available at %(url)s"
 
1916
 
 
1917
    def __init__(self, url):
 
1918
        self.url = url
 
1919
 
 
1920
 
1882
1921
class UnknownSSH(BzrError):
1883
1922
 
1884
 
    _fmt = "Unrecognised value for BRZ_SSH environment variable: %(vendor)s"
 
1923
    _fmt = "Unrecognised value for BZR_SSH environment variable: %(vendor)s"
1885
1924
 
1886
1925
    def __init__(self, vendor):
1887
1926
        BzrError.__init__(self)
1891
1930
class SSHVendorNotFound(BzrError):
1892
1931
 
1893
1932
    _fmt = ("Don't know how to handle SSH connections."
1894
 
            " Please set BRZ_SSH environment variable.")
1895
 
 
1896
 
 
1897
 
class GhostRevisionsHaveNoRevno(BzrError):
1898
 
    """When searching for revnos, if we encounter a ghost, we are stuck"""
1899
 
 
1900
 
    _fmt = ("Could not determine revno for {%(revision_id)s} because"
1901
 
            " its ancestry shows a ghost at {%(ghost_revision_id)s}")
1902
 
 
1903
 
    def __init__(self, revision_id, ghost_revision_id):
1904
 
        self.revision_id = revision_id
1905
 
        self.ghost_revision_id = ghost_revision_id
 
1933
            " Please set BZR_SSH environment variable.")
1906
1934
 
1907
1935
 
1908
1936
class GhostRevisionUnusableHere(BzrError):
1914
1942
        self.revision_id = revision_id
1915
1943
 
1916
1944
 
 
1945
class IllegalUseOfScopeReplacer(BzrError):
 
1946
 
 
1947
    _fmt = ("ScopeReplacer object %(name)r was used incorrectly:"
 
1948
            " %(msg)s%(extra)s")
 
1949
 
 
1950
    internal_error = True
 
1951
 
 
1952
    def __init__(self, name, msg, extra=None):
 
1953
        BzrError.__init__(self)
 
1954
        self.name = name
 
1955
        self.msg = msg
 
1956
        if extra:
 
1957
            self.extra = ': ' + str(extra)
 
1958
        else:
 
1959
            self.extra = ''
 
1960
 
 
1961
 
 
1962
class InvalidImportLine(BzrError):
 
1963
 
 
1964
    _fmt = "Not a valid import statement: %(msg)\n%(text)s"
 
1965
 
 
1966
    internal_error = True
 
1967
 
 
1968
    def __init__(self, text, msg):
 
1969
        BzrError.__init__(self)
 
1970
        self.text = text
 
1971
        self.msg = msg
 
1972
 
 
1973
 
 
1974
class ImportNameCollision(BzrError):
 
1975
 
 
1976
    _fmt = ("Tried to import an object to the same name as"
 
1977
            " an existing object. %(name)s")
 
1978
 
 
1979
    internal_error = True
 
1980
 
 
1981
    def __init__(self, name):
 
1982
        BzrError.__init__(self)
 
1983
        self.name = name
 
1984
 
 
1985
 
1917
1986
class NotAMergeDirective(BzrError):
1918
1987
    """File starting with %(firstline)r is not a merge directive"""
1919
 
 
1920
1988
    def __init__(self, firstline):
1921
1989
        BzrError.__init__(self, firstline=firstline)
1922
1990
 
1928
1996
        " branch location."
1929
1997
 
1930
1998
 
1931
 
class PatchVerificationFailed(BzrError):
1932
 
    """A patch from a merge directive could not be verified"""
1933
 
 
1934
 
    _fmt = "Preview patch does not match requested changes."
1935
 
 
1936
 
 
1937
1999
class PatchMissing(BzrError):
1938
2000
    """Raise a patch type was specified but no patch supplied"""
1939
2001
 
1940
 
    _fmt = "Patch_type was %(patch_type)s, but no patch was supplied."
 
2002
    _fmt = "patch_type was %(patch_type)s, but no patch was supplied."
1941
2003
 
1942
2004
    def __init__(self, patch_type):
1943
2005
        BzrError.__init__(self)
1944
2006
        self.patch_type = patch_type
1945
2007
 
1946
2008
 
1947
 
class TargetNotBranch(BzrError):
1948
 
    """A merge directive's target branch is required, but isn't a branch"""
1949
 
 
1950
 
    _fmt = ("Your branch does not have all of the revisions required in "
1951
 
            "order to merge this merge directive and the target "
1952
 
            "location specified in the merge directive is not a branch: "
1953
 
            "%(location)s.")
1954
 
 
1955
 
    def __init__(self, location):
1956
 
        BzrError.__init__(self)
1957
 
        self.location = location
 
2009
class UnsupportedInventoryKind(BzrError):
 
2010
    
 
2011
    _fmt = """Unsupported entry kind %(kind)s"""
 
2012
 
 
2013
    def __init__(self, kind):
 
2014
        self.kind = kind
1958
2015
 
1959
2016
 
1960
2017
class BadSubsumeSource(BzrError):
1961
2018
 
1962
 
    _fmt = "Can't subsume %(other_tree)s into %(tree)s. %(reason)s"
 
2019
    _fmt = """Can't subsume %(other_tree)s into %(tree)s.  %(reason)s"""
1963
2020
 
1964
2021
    def __init__(self, tree, other_tree, reason):
1965
2022
        self.tree = tree
1968
2025
 
1969
2026
 
1970
2027
class SubsumeTargetNeedsUpgrade(BzrError):
1971
 
 
 
2028
    
1972
2029
    _fmt = """Subsume target %(other_tree)s needs to be upgraded."""
1973
2030
 
1974
2031
    def __init__(self, other_tree):
1975
2032
        self.other_tree = other_tree
1976
2033
 
1977
2034
 
 
2035
class BadReferenceTarget(BzrError):
 
2036
 
 
2037
    _fmt = "Can't add reference to %(other_tree)s into %(tree)s.  %(reason)s"
 
2038
 
 
2039
    internal_error = True
 
2040
 
 
2041
    def __init__(self, tree, other_tree, reason):
 
2042
        self.tree = tree
 
2043
        self.other_tree = other_tree
 
2044
        self.reason = reason
 
2045
 
 
2046
 
1978
2047
class NoSuchTag(BzrError):
1979
2048
 
1980
2049
    _fmt = "No such tag: %(tag_name)s"
1986
2055
class TagsNotSupported(BzrError):
1987
2056
 
1988
2057
    _fmt = ("Tags not supported by %(branch)s;"
1989
 
            " you may be able to use 'brz upgrade %(branch_url)s'.")
 
2058
            " you may be able to use bzr upgrade --dirstate-tags.")
1990
2059
 
1991
2060
    def __init__(self, branch):
1992
2061
        self.branch = branch
1993
 
        self.branch_url = branch.user_url
1994
 
 
1995
 
 
 
2062
 
 
2063
        
1996
2064
class TagAlreadyExists(BzrError):
1997
2065
 
1998
2066
    _fmt = "Tag %(tag_name)s already exists."
1999
2067
 
2000
2068
    def __init__(self, tag_name):
2001
2069
        self.tag_name = tag_name
2002
 
 
2003
 
 
2004
 
class UnexpectedSmartServerResponse(BzrError):
2005
 
 
2006
 
    _fmt = "Could not understand response from smart server: %(response_tuple)r"
2007
 
 
2008
 
    def __init__(self, response_tuple):
2009
 
        self.response_tuple = response_tuple
2010
 
 
2011
 
 
2012
 
class ErrorFromSmartServer(BzrError):
2013
 
    """An error was received from a smart server.
2014
 
 
2015
 
    :seealso: UnknownErrorFromSmartServer
2016
 
    """
2017
 
 
2018
 
    _fmt = "Error received from smart server: %(error_tuple)r"
2019
 
 
2020
 
    internal_error = True
2021
 
 
2022
 
    def __init__(self, error_tuple):
2023
 
        self.error_tuple = error_tuple
2024
 
        try:
2025
 
            self.error_verb = error_tuple[0]
2026
 
        except IndexError:
2027
 
            self.error_verb = None
2028
 
        self.error_args = error_tuple[1:]
2029
 
 
2030
 
 
2031
 
class UnknownErrorFromSmartServer(BzrError):
2032
 
    """An ErrorFromSmartServer could not be translated into a typical breezy
2033
 
    error.
2034
 
 
2035
 
    This is distinct from ErrorFromSmartServer so that it is possible to
2036
 
    distinguish between the following two cases:
2037
 
 
2038
 
    - ErrorFromSmartServer was uncaught.  This is logic error in the client
2039
 
      and so should provoke a traceback to the user.
2040
 
    - ErrorFromSmartServer was caught but its error_tuple could not be
2041
 
      translated.  This is probably because the server sent us garbage, and
2042
 
      should not provoke a traceback.
2043
 
    """
2044
 
 
2045
 
    _fmt = "Server sent an unexpected error: %(error_tuple)r"
2046
 
 
2047
 
    internal_error = False
2048
 
 
2049
 
    def __init__(self, error_from_smart_server):
2050
 
        """Constructor.
2051
 
 
2052
 
        :param error_from_smart_server: An ErrorFromSmartServer instance.
2053
 
        """
2054
 
        self.error_from_smart_server = error_from_smart_server
2055
 
        self.error_tuple = error_from_smart_server.error_tuple
2056
 
 
2057
 
 
2058
 
class ContainerError(BzrError):
2059
 
    """Base class of container errors."""
2060
 
 
2061
 
 
2062
 
class UnknownContainerFormatError(ContainerError):
2063
 
 
2064
 
    _fmt = "Unrecognised container format: %(container_format)r"
2065
 
 
2066
 
    def __init__(self, container_format):
2067
 
        self.container_format = container_format
2068
 
 
2069
 
 
2070
 
class UnexpectedEndOfContainerError(ContainerError):
2071
 
 
2072
 
    _fmt = "Unexpected end of container stream"
2073
 
 
2074
 
 
2075
 
class UnknownRecordTypeError(ContainerError):
2076
 
 
2077
 
    _fmt = "Unknown record type: %(record_type)r"
2078
 
 
2079
 
    def __init__(self, record_type):
2080
 
        self.record_type = record_type
2081
 
 
2082
 
 
2083
 
class InvalidRecordError(ContainerError):
2084
 
 
2085
 
    _fmt = "Invalid record: %(reason)s"
2086
 
 
2087
 
    def __init__(self, reason):
2088
 
        self.reason = reason
2089
 
 
2090
 
 
2091
 
class ContainerHasExcessDataError(ContainerError):
2092
 
 
2093
 
    _fmt = "Container has data after end marker: %(excess)r"
2094
 
 
2095
 
    def __init__(self, excess):
2096
 
        self.excess = excess
2097
 
 
2098
 
 
2099
 
class DuplicateRecordNameError(ContainerError):
2100
 
 
2101
 
    _fmt = "Container has multiple records with the same name: %(name)s"
2102
 
 
2103
 
    def __init__(self, name):
2104
 
        self.name = name.decode("utf-8")
2105
 
 
2106
 
 
2107
 
class RepositoryDataStreamError(BzrError):
2108
 
 
2109
 
    _fmt = "Corrupt or incompatible data stream: %(reason)s"
2110
 
 
2111
 
    def __init__(self, reason):
2112
 
        self.reason = reason
2113
 
 
2114
 
 
2115
 
class UncommittedChanges(BzrError):
2116
 
 
2117
 
    _fmt = ('Working tree "%(display_url)s" has uncommitted changes'
2118
 
            ' (See brz status).%(more)s')
2119
 
 
2120
 
    def __init__(self, tree, more=None):
2121
 
        if more is None:
2122
 
            more = ''
2123
 
        else:
2124
 
            more = ' ' + more
2125
 
        import breezy.urlutils as urlutils
2126
 
        user_url = getattr(tree, "user_url", None)
2127
 
        if user_url is None:
2128
 
            display_url = str(tree)
2129
 
        else:
2130
 
            display_url = urlutils.unescape_for_display(user_url, 'ascii')
2131
 
        BzrError.__init__(self, tree=tree, display_url=display_url, more=more)
2132
 
 
2133
 
 
2134
 
class StoringUncommittedNotSupported(BzrError):
2135
 
 
2136
 
    _fmt = ('Branch "%(display_url)s" does not support storing uncommitted'
2137
 
            ' changes.')
2138
 
 
2139
 
    def __init__(self, branch):
2140
 
        import breezy.urlutils as urlutils
2141
 
        user_url = getattr(branch, "user_url", None)
2142
 
        if user_url is None:
2143
 
            display_url = str(branch)
2144
 
        else:
2145
 
            display_url = urlutils.unescape_for_display(user_url, 'ascii')
2146
 
        BzrError.__init__(self, branch=branch, display_url=display_url)
2147
 
 
2148
 
 
2149
 
class ShelvedChanges(UncommittedChanges):
2150
 
 
2151
 
    _fmt = ('Working tree "%(display_url)s" has shelved changes'
2152
 
            ' (See brz shelve --list).%(more)s')
2153
 
 
2154
 
 
2155
 
class UnableEncodePath(BzrError):
2156
 
 
2157
 
    _fmt = ('Unable to encode %(kind)s path %(path)r in '
2158
 
            'user encoding %(user_encoding)s')
2159
 
 
2160
 
    def __init__(self, path, kind):
2161
 
        from breezy.osutils import get_user_encoding
2162
 
        self.path = path
2163
 
        self.kind = kind
2164
 
        self.user_encoding = get_user_encoding()
2165
 
 
2166
 
 
2167
 
class NoSuchAlias(BzrError):
2168
 
 
2169
 
    _fmt = ('The alias "%(alias_name)s" does not exist.')
2170
 
 
2171
 
    def __init__(self, alias_name):
2172
 
        BzrError.__init__(self, alias_name=alias_name)
2173
 
 
2174
 
 
2175
 
class CannotBindAddress(BzrError):
2176
 
 
2177
 
    _fmt = 'Cannot bind address "%(host)s:%(port)i": %(orig_error)s.'
2178
 
 
2179
 
    def __init__(self, host, port, orig_error):
2180
 
        # nb: in python2.4 socket.error doesn't have a useful repr
2181
 
        BzrError.__init__(self, host=host, port=port,
2182
 
                          orig_error=repr(orig_error.args))
2183
 
 
2184
 
 
2185
 
class TipChangeRejected(BzrError):
2186
 
    """A pre_change_branch_tip hook function may raise this to cleanly and
2187
 
    explicitly abort a change to a branch tip.
2188
 
    """
2189
 
 
2190
 
    _fmt = u"Tip change rejected: %(msg)s"
2191
 
 
2192
 
    def __init__(self, msg):
2193
 
        self.msg = msg
2194
 
 
2195
 
 
2196
 
class JailBreak(BzrError):
2197
 
 
2198
 
    _fmt = "An attempt to access a url outside the server jail was made: '%(url)s'."
2199
 
 
2200
 
    def __init__(self, url):
2201
 
        BzrError.__init__(self, url=url)
2202
 
 
2203
 
 
2204
 
class UserAbort(BzrError):
2205
 
 
2206
 
    _fmt = 'The user aborted the operation.'
2207
 
 
2208
 
 
2209
 
class UnresumableWriteGroup(BzrError):
2210
 
 
2211
 
    _fmt = ("Repository %(repository)s cannot resume write group "
2212
 
            "%(write_groups)r: %(reason)s")
2213
 
 
2214
 
    internal_error = True
2215
 
 
2216
 
    def __init__(self, repository, write_groups, reason):
2217
 
        self.repository = repository
2218
 
        self.write_groups = write_groups
2219
 
        self.reason = reason
2220
 
 
2221
 
 
2222
 
class UnsuspendableWriteGroup(BzrError):
2223
 
 
2224
 
    _fmt = ("Repository %(repository)s cannot suspend a write group.")
2225
 
 
2226
 
    internal_error = True
2227
 
 
2228
 
    def __init__(self, repository):
2229
 
        self.repository = repository
2230
 
 
2231
 
 
2232
 
class LossyPushToSameVCS(BzrError):
2233
 
 
2234
 
    _fmt = ("Lossy push not possible between %(source_branch)r and "
2235
 
            "%(target_branch)r that are in the same VCS.")
2236
 
 
2237
 
    internal_error = True
2238
 
 
2239
 
    def __init__(self, source_branch, target_branch):
2240
 
        self.source_branch = source_branch
2241
 
        self.target_branch = target_branch
2242
 
 
2243
 
 
2244
 
class NoRoundtrippingSupport(BzrError):
2245
 
 
2246
 
    _fmt = ("Roundtripping is not supported between %(source_branch)r and "
2247
 
            "%(target_branch)r.")
2248
 
 
2249
 
    internal_error = True
2250
 
 
2251
 
    def __init__(self, source_branch, target_branch):
2252
 
        self.source_branch = source_branch
2253
 
        self.target_branch = target_branch
2254
 
 
2255
 
 
2256
 
class NoColocatedBranchSupport(BzrError):
2257
 
 
2258
 
    _fmt = ("%(controldir)r does not support co-located branches.")
2259
 
 
2260
 
    def __init__(self, controldir):
2261
 
        self.controldir = controldir
2262
 
 
2263
 
 
2264
 
class RecursiveBind(BzrError):
2265
 
 
2266
 
    _fmt = ('Branch "%(branch_url)s" appears to be bound to itself. '
2267
 
            'Please use `brz unbind` to fix.')
2268
 
 
2269
 
    def __init__(self, branch_url):
2270
 
        self.branch_url = branch_url
2271
 
 
2272
 
 
2273
 
class UnsupportedKindChange(BzrError):
2274
 
 
2275
 
    _fmt = ("Kind change from %(from_kind)s to %(to_kind)s for "
2276
 
            "%(path)s not supported by format %(format)r")
2277
 
 
2278
 
    def __init__(self, path, from_kind, to_kind, format):
2279
 
        self.path = path
2280
 
        self.from_kind = from_kind
2281
 
        self.to_kind = to_kind
2282
 
        self.format = format
2283
 
 
2284
 
 
2285
 
class ChangesAlreadyStored(CommandError):
2286
 
 
2287
 
    _fmt = ('Cannot store uncommitted changes because this branch already'
2288
 
            ' stores uncommitted changes.')
2289
 
 
2290
 
 
2291
 
class RevnoOutOfBounds(InternalBzrError):
2292
 
 
2293
 
    _fmt = ("The requested revision number %(revno)d is outside of the "
2294
 
            "expected boundaries (%(minimum)d <= %(maximum)d).")
2295
 
 
2296
 
    def __init__(self, revno, bounds):
2297
 
        InternalBzrError.__init__(
2298
 
            self, revno=revno, minimum=bounds[0], maximum=bounds[1])