/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

Merge from bzr.dev, resolving conflicts.

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
 
from __future__ import absolute_import
21
 
 
22
 
from .sixish import (
23
 
    PY3,
24
 
    )
 
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
 
25
33
 
26
34
# TODO: is there any value in providing the .args field used by standard
27
 
# 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 
28
36
# to me.
29
37
 
30
 
# 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 
31
39
# constructed to make sure it will succeed.  But that says nothing about
32
40
# exceptions that are never raised.
33
41
 
36
44
# 'unprintable'.
37
45
 
38
46
 
39
 
# return codes from the brz program
40
 
EXIT_OK = 0
41
 
EXIT_ERROR = 3
42
 
EXIT_INTERNAL_ERROR = 4
43
 
 
44
 
 
45
 
class BzrError(Exception):
 
47
class BzrError(StandardError):
46
48
    """
47
 
    Base class for errors raised by breezy.
 
49
    Base class for errors raised by bzrlib.
48
50
 
49
 
    :cvar internal_error: if True this was probably caused by a brz bug and
50
 
        should be displayed with a traceback; if False (or absent) this was
51
 
        probably a user or environment error and they don't need the gory
52
 
        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.)
53
55
 
54
56
    :cvar _fmt: Format string to display the error; this is expanded
55
 
        by the instance's dict.
 
57
    by the instance's dict.
56
58
    """
57
 
 
 
59
    
58
60
    internal_error = False
59
61
 
60
62
    def __init__(self, msg=None, **kwds):
65
67
        arguments can be given.  The first is for generic "user" errors which
66
68
        are not intended to be caught and so do not need a specific subclass.
67
69
        The second case is for use with subclasses that provide a _fmt format
68
 
        string to print the arguments.
 
70
        string to print the arguments.  
69
71
 
70
 
        Keyword arguments are taken as parameters to the error, which can
71
 
        be inserted into the format string template.  It's recommended
72
 
        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 
73
75
        parameters.
74
76
 
75
77
        :param msg: If given, this is the literal complete text for the error,
76
 
           not subject to expansion. 'msg' is used instead of 'message' because
77
 
           python evolved and, in 2.6, forbids the use of 'message'.
 
78
        not subject to expansion.
78
79
        """
79
 
        Exception.__init__(self)
 
80
        StandardError.__init__(self)
80
81
        if msg is not None:
81
82
            # I was going to deprecate this, but it actually turns out to be
82
83
            # quite handy - mbp 20061103.
86
87
            for key, value in kwds.items():
87
88
                setattr(self, key, value)
88
89
 
89
 
    def _format(self):
 
90
    def __str__(self):
90
91
        s = getattr(self, '_preformatted_string', None)
91
92
        if s is not None:
92
 
            # contains a preformatted message
93
 
            return s
94
 
        err = None
 
93
            # contains a preformatted message; must be cast to plain str
 
94
            return str(s)
95
95
        try:
96
96
            fmt = self._get_format_string()
97
97
            if fmt:
98
 
                d = dict(self.__dict__)
99
 
                s = fmt % d
 
98
                s = fmt % self.__dict__
100
99
                # __str__() should always return a 'str' object
101
100
                # never a 'unicode' object.
 
101
                if isinstance(s, unicode):
 
102
                    return s.encode('utf8')
102
103
                return s
103
 
        except Exception as e:
104
 
            err = e
105
 
        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' \
106
123
            % (self.__class__.__name__,
107
124
               self.__dict__,
108
125
               getattr(self, '_fmt', None),
109
 
               err)
110
 
 
111
 
    if PY3:
112
 
        __str__ = _format
113
 
    else:
114
 
        def __str__(self):
115
 
            return self._format().encode('utf-8')
116
 
 
117
 
        __unicode__ = _format
118
 
 
119
 
    def __repr__(self):
120
 
        return '%s(%s)' % (self.__class__.__name__, str(self))
121
 
 
122
 
    def _get_format_string(self):
123
 
        """Return format string for this exception or None"""
124
 
        fmt = getattr(self, '_fmt', None)
125
 
        if fmt is not None:
126
 
            from breezy.i18n import gettext
127
 
            return gettext(fmt) # _fmt strings should be ascii
128
 
 
129
 
    def __eq__(self, other):
130
 
        if self.__class__ is not other.__class__:
131
 
            return NotImplemented
132
 
        return self.__dict__ == other.__dict__
133
 
 
134
 
    def __hash__(self):
135
 
        return id(self)
136
 
 
137
 
 
138
 
class InternalBzrError(BzrError):
139
 
    """Base class for errors that are internal in nature.
140
 
 
141
 
    This is a convenience class for errors that are internal. The
142
 
    internal_error attribute can still be altered in subclasses, if needed.
143
 
    Using this class is simply an easy way to get internal errors.
144
 
    """
145
 
 
146
 
    internal_error = True
147
 
 
148
 
 
149
 
class BranchError(BzrError):
150
 
    """Base class for concrete 'errors about a branch'."""
151
 
 
152
 
    def __init__(self, branch):
153
 
        BzrError.__init__(self, branch=branch)
154
 
 
155
 
 
156
 
class BzrCheckError(InternalBzrError):
157
 
 
158
 
    _fmt = "Internal check failed: %(msg)s"
159
 
 
160
 
    def __init__(self, msg):
161
 
        BzrError.__init__(self)
162
 
        self.msg = msg
163
 
 
164
 
 
165
 
class IncompatibleVersion(BzrError):
166
 
 
167
 
    _fmt = 'API %(api)s is not compatible; one of versions %(wanted)r '\
168
 
           'is required, but current version is %(current)r.'
169
 
 
170
 
    def __init__(self, api, wanted, current):
171
 
        self.api = api
172
 
        self.wanted = wanted
173
 
        self.current = current
174
 
 
175
 
 
176
 
class InProcessTransport(BzrError):
177
 
 
178
 
    _fmt = "The transport '%(transport)s' is only accessible within this " \
179
 
        "process."
180
 
 
181
 
    def __init__(self, transport):
182
 
        self.transport = transport
183
 
 
184
 
 
185
 
class InvalidEntryName(InternalBzrError):
186
 
 
 
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
    
187
191
    _fmt = "Invalid entry name: %(name)s"
188
192
 
 
193
    internal_error = True
 
194
 
189
195
    def __init__(self, name):
190
196
        BzrError.__init__(self)
191
197
        self.name = name
192
198
 
193
199
 
194
200
class InvalidRevisionNumber(BzrError):
195
 
 
 
201
    
196
202
    _fmt = "Invalid revision number %(revno)s"
197
203
 
198
204
    def __init__(self, revno):
210
216
        self.revision_id = revision_id
211
217
        self.branch = branch
212
218
 
213
 
 
214
219
class ReservedId(BzrError):
215
220
 
216
221
    _fmt = "Reserved revision-id {%(revision_id)s}"
218
223
    def __init__(self, revision_id):
219
224
        self.revision_id = revision_id
220
225
 
221
 
 
222
 
class RootMissing(InternalBzrError):
223
 
 
224
 
    _fmt = ("The root entry of a tree must be the first entry supplied to "
225
 
        "the commit builder.")
226
 
 
227
 
 
228
 
class NoPublicBranch(BzrError):
229
 
 
230
 
    _fmt = 'There is no public branch set for "%(branch_url)s".'
231
 
 
232
 
    def __init__(self, branch):
233
 
        from . import urlutils
234
 
        public_location = urlutils.unescape_for_display(branch.base, 'ascii')
235
 
        BzrError.__init__(self, branch_url=public_location)
236
 
 
237
 
 
238
226
class NoSuchId(BzrError):
239
227
 
240
 
    _fmt = 'The file id "%(file_id)s" is not present in the tree %(tree)s.'
241
 
 
 
228
    _fmt = "The file id %(file_id)s is not present in the tree %(tree)s."
 
229
    
242
230
    def __init__(self, tree, file_id):
243
231
        BzrError.__init__(self)
244
232
        self.file_id = file_id
245
233
        self.tree = tree
246
234
 
247
235
 
248
 
class NotStacked(BranchError):
249
 
 
250
 
    _fmt = "The branch '%(branch)s' is not stacked."
251
 
 
252
 
 
253
 
class InventoryModified(InternalBzrError):
 
236
class InventoryModified(BzrError):
254
237
 
255
238
    _fmt = ("The current inventory for the tree %(tree)r has been modified,"
256
239
            " so a clean inventory cannot be read without data loss.")
257
240
 
 
241
    internal_error = True
 
242
 
258
243
    def __init__(self, tree):
259
244
        self.tree = tree
260
245
 
261
246
 
262
247
class NoWorkingTree(BzrError):
263
248
 
264
 
    _fmt = 'No WorkingTree exists for "%(base)s".'
265
 
 
 
249
    _fmt = "No WorkingTree exists for %(base)s."
 
250
    
266
251
    def __init__(self, base):
267
252
        BzrError.__init__(self)
268
253
        self.base = base
269
254
 
270
255
 
 
256
class NotBuilding(BzrError):
 
257
 
 
258
    _fmt = "Not currently building a tree."
 
259
 
 
260
 
271
261
class NotLocalUrl(BzrError):
272
262
 
273
263
    _fmt = "%(url)s is not a local path."
276
266
        self.url = url
277
267
 
278
268
 
279
 
class WorkingTreeAlreadyPopulated(InternalBzrError):
280
 
 
281
 
    _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
282
274
 
283
275
    def __init__(self, base):
284
276
        self.base = base
285
277
 
286
 
 
287
278
class BzrCommandError(BzrError):
288
279
    """Error from user command"""
289
280
 
 
281
    internal_error = False
 
282
 
290
283
    # Error from malformed user command; please avoid raising this as a
291
284
    # generic exception not caused by user input.
292
285
    #
294
287
    # are not intended to be caught anyway.  UI code need not subclass
295
288
    # BzrCommandError, and non-UI code should not throw a subclass of
296
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
297
300
 
298
301
 
299
302
class NotWriteLocked(BzrError):
304
307
        self.not_locked = not_locked
305
308
 
306
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
    
307
323
class StrictCommitFailed(BzrError):
308
324
 
309
325
    _fmt = "Commit refused because there are unknown files in the tree"
311
327
 
312
328
# XXX: Should be unified with TransportError; they seem to represent the
313
329
# same thing
314
 
# RBC 20060929: I think that unifiying with TransportError would be a mistake
315
 
# - this is finer than a TransportError - and more useful as such. It
316
 
# differentiates between 'transport has failed' and 'operation on a transport
317
 
# has failed.'
318
330
class PathError(BzrError):
319
 
 
 
331
    
320
332
    _fmt = "Generic path error: %(path)r%(extra)s)"
321
333
 
322
334
    def __init__(self, path, extra=None):
342
354
    """Used when renaming and both source and dest exist."""
343
355
 
344
356
    _fmt = ("Could not rename %(source)s => %(dest)s because both files exist."
345
 
            " (Use --after to tell brz about a rename that has already"
346
 
            " happened)%(extra)s")
 
357
            "%(extra)s")
347
358
 
348
359
    def __init__(self, source, dest, extra=None):
349
360
        BzrError.__init__(self)
357
368
 
358
369
class NotADirectory(PathError):
359
370
 
360
 
    _fmt = '"%(path)s" is not a directory %(extra)s'
 
371
    _fmt = "%(path)r is not a directory %(extra)s"
361
372
 
362
373
 
363
374
class NotInWorkingDirectory(PathError):
364
375
 
365
 
    _fmt = '"%(path)s" is not in the working directory %(extra)s'
 
376
    _fmt = "%(path)r is not in the working directory %(extra)s"
366
377
 
367
378
 
368
379
class DirectoryNotEmpty(PathError):
369
380
 
370
 
    _fmt = 'Directory not empty: "%(path)s"%(extra)s'
371
 
 
372
 
 
373
 
class HardLinkNotSupported(PathError):
374
 
 
375
 
    _fmt = 'Hard-linking "%(path)s" is not supported'
376
 
 
377
 
 
378
 
class ReadingCompleted(InternalBzrError):
379
 
 
 
381
    _fmt = "Directory not empty: %(path)r%(extra)s"
 
382
 
 
383
 
 
384
class ReadingCompleted(BzrError):
 
385
    
380
386
    _fmt = ("The MediumRequest '%(request)s' has already had finish_reading "
381
387
            "called upon it - the request has been completed and no more "
382
388
            "data may be read.")
383
389
 
 
390
    internal_error = True
 
391
 
384
392
    def __init__(self, request):
385
393
        self.request = request
386
394
 
387
395
 
388
396
class ResourceBusy(PathError):
389
397
 
390
 
    _fmt = 'Device or resource busy: "%(path)s"%(extra)s'
 
398
    _fmt = "Device or resource busy: %(path)r%(extra)s"
391
399
 
392
400
 
393
401
class PermissionDenied(PathError):
394
402
 
395
 
    _fmt = 'Permission denied: "%(path)s"%(extra)s'
396
 
 
397
 
 
398
 
class UnavailableRepresentation(InternalBzrError):
399
 
 
400
 
    _fmt = ("The encoding '%(wanted)s' is not available for key %(key)s which "
401
 
        "is encoded as '%(native)s'.")
402
 
 
403
 
    def __init__(self, key, wanted, native):
404
 
        InternalBzrError.__init__(self)
405
 
        self.wanted = wanted
406
 
        self.native = native
407
 
        self.key = key
 
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
408
428
 
409
429
 
410
430
class UnsupportedProtocol(PathError):
411
431
 
412
432
    _fmt = 'Unsupported protocol for url "%(path)s"%(extra)s'
413
433
 
414
 
    def __init__(self, url, extra=""):
 
434
    def __init__(self, url, extra):
415
435
        PathError.__init__(self, url, extra=extra)
416
436
 
417
437
 
418
 
class UnstackableLocationError(BzrError):
419
 
 
420
 
    _fmt = "The branch '%(branch_url)s' cannot be stacked on '%(target_url)s'."
421
 
 
422
 
    def __init__(self, branch_url, target_url):
423
 
        BzrError.__init__(self)
424
 
        self.branch_url = branch_url
425
 
        self.target_url = target_url
426
 
 
427
 
 
428
 
class UnstackableRepositoryFormat(BzrError):
429
 
 
430
 
    _fmt = ("The repository '%(url)s'(%(format)s) is not a stackable format. "
431
 
        "You will need to upgrade the repository to permit branch stacking.")
432
 
 
433
 
    def __init__(self, format, url):
434
 
        BzrError.__init__(self)
435
 
        self.format = format
436
 
        self.url = url
437
 
 
438
 
 
439
 
class ReadError(PathError):
440
 
 
441
 
    _fmt = """Error reading from %(path)r."""
442
 
 
443
 
 
444
438
class ShortReadvError(PathError):
445
439
 
446
 
    _fmt = ('readv() read %(actual)s bytes rather than %(length)s bytes'
447
 
            ' 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")
448
442
 
449
443
    internal_error = True
450
444
 
455
449
        self.actual = actual
456
450
 
457
451
 
458
 
class PathNotChild(PathError):
459
 
 
460
 
    _fmt = 'Path "%(path)s" is not a child of path "%(base)s"%(extra)s'
461
 
 
462
 
    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
463
457
 
464
458
    def __init__(self, path, base, extra=None):
465
459
        BzrError.__init__(self)
473
467
 
474
468
class InvalidNormalization(PathError):
475
469
 
476
 
    _fmt = 'Path "%(path)s" is not unicode normalized'
 
470
    _fmt = "Path %(path)r is not unicode normalized"
477
471
 
478
472
 
479
473
# TODO: This is given a URL; we try to unescape it but doing that from inside
480
474
# the exception object is a bit undesirable.
481
 
# TODO: Probably this behavior of should be a common superclass
 
475
# TODO: Probably this behavior of should be a common superclass 
482
476
class NotBranchError(PathError):
483
477
 
484
 
    _fmt = 'Not a branch: "%(path)s"%(detail)s.'
485
 
 
486
 
    def __init__(self, path, detail=None, controldir=None):
487
 
       from . import urlutils
488
 
       path = urlutils.unescape_for_display(path, 'ascii')
489
 
       if detail is not None:
490
 
           detail = ': ' + detail
491
 
       self.detail = detail
492
 
       self.controldir = controldir
493
 
       PathError.__init__(self, path=path)
494
 
 
495
 
    def __repr__(self):
496
 
        return '<%s %r>' % (self.__class__.__name__, self.__dict__)
497
 
 
498
 
    def _get_format_string(self):
499
 
        # GZ 2017-06-08: Not the best place to lazy fill detail in.
500
 
        if self.detail is None:
501
 
           self.detail = self._get_detail()
502
 
        return super(NotBranchError, self)._get_format_string()
503
 
 
504
 
    def _get_detail(self):
505
 
        if self.controldir is not None:
506
 
            try:
507
 
                self.controldir.open_repository()
508
 
            except NoRepositoryPresent:
509
 
                return ''
510
 
            except Exception as e:
511
 
                # Just ignore unexpected errors.  Raising arbitrary errors
512
 
                # during str(err) can provoke strange bugs.  Concretely
513
 
                # Launchpad's codehosting managed to raise NotBranchError
514
 
                # here, and then get stuck in an infinite loop/recursion
515
 
                # trying to str() that error.  All this error really cares
516
 
                # about that there's no working repository there, and if
517
 
                # open_repository() fails, there probably isn't.
518
 
                return ': ' + e.__class__.__name__
519
 
            else:
520
 
                return ': location is a repository'
521
 
        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')
522
483
 
523
484
 
524
485
class NoSubmitBranch(PathError):
526
487
    _fmt = 'No submit branch available for branch "%(path)s"'
527
488
 
528
489
    def __init__(self, branch):
529
 
       from . import urlutils
 
490
       import bzrlib.urlutils as urlutils
530
491
       self.path = urlutils.unescape_for_display(branch.base, 'ascii')
531
492
 
532
493
 
533
 
class AlreadyControlDirError(PathError):
534
 
 
535
 
    _fmt = 'A control directory already exists: "%(path)s".'
536
 
 
537
 
 
538
494
class AlreadyBranchError(PathError):
539
495
 
540
 
    _fmt = 'Already a branch: "%(path)s".'
541
 
 
542
 
 
543
 
class InvalidBranchName(PathError):
544
 
 
545
 
    _fmt = "Invalid branch name: %(name)s"
546
 
 
547
 
    def __init__(self, name):
548
 
        BzrError.__init__(self)
549
 
        self.name = name
550
 
 
551
 
 
552
 
class ParentBranchExists(AlreadyBranchError):
553
 
 
554
 
    _fmt = 'Parent branch already exists: "%(path)s".'
 
496
    _fmt = "Already a branch: %(path)s."
555
497
 
556
498
 
557
499
class BranchExistsWithoutWorkingTree(PathError):
558
500
 
559
 
    _fmt = 'Directory contains a branch, but no working tree \
560
 
(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"
561
503
 
562
504
 
563
505
class AtomicFileAlreadyClosed(PathError):
564
506
 
565
 
    _fmt = ('"%(function)s" called on an AtomicFile after it was closed:'
566
 
            ' "%(path)s"')
 
507
    _fmt = ("'%(function)s' called on an AtomicFile after it was closed:"
 
508
            " %(path)s")
567
509
 
568
510
    def __init__(self, path, function):
569
511
        PathError.__init__(self, path=path, extra=None)
572
514
 
573
515
class InaccessibleParent(PathError):
574
516
 
575
 
    _fmt = ('Parent not accessible given base "%(base)s" and'
576
 
            ' relative path "%(path)s"')
 
517
    _fmt = ("Parent not accessible given base %(base)s and"
 
518
            " relative path %(path)s")
577
519
 
578
520
    def __init__(self, path, base):
579
521
        PathError.__init__(self, path)
582
524
 
583
525
class NoRepositoryPresent(BzrError):
584
526
 
585
 
    _fmt = 'No repository present: "%(path)s"'
586
 
    def __init__(self, controldir):
587
 
        BzrError.__init__(self)
588
 
        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
589
542
 
590
543
 
591
544
class UnsupportedFormatError(BzrError):
592
545
 
593
 
    _fmt = "Unsupported branch format: %(format)s\nPlease run 'brz upgrade'"
 
546
    _fmt = "Unsupported branch format: %(format)s\nPlease run 'bzr upgrade'"
594
547
 
595
548
 
596
549
class UnknownFormatError(BzrError):
597
 
 
598
 
    _fmt = "Unknown %(kind)s format: %(format)r"
599
 
 
600
 
    def __init__(self, format, kind='branch'):
601
 
        self.kind = kind
602
 
        self.format = format
 
550
    
 
551
    _fmt = "Unknown branch format: %(format)r"
603
552
 
604
553
 
605
554
class IncompatibleFormat(BzrError):
606
 
 
607
 
    _fmt = "Format %(format)s is not compatible with .bzr version %(controldir)s."
608
 
 
609
 
    def __init__(self, format, controldir_format):
610
 
        BzrError.__init__(self)
611
 
        self.format = format
612
 
        self.controldir = controldir_format
613
 
 
614
 
 
615
 
class ParseFormatError(BzrError):
616
 
 
617
 
    _fmt = "Parse error on line %(lineno)d of %(format)s format: %(line)s"
618
 
 
619
 
    def __init__(self, format, lineno, line, text):
620
 
        BzrError.__init__(self)
621
 
        self.format = format
622
 
        self.lineno = lineno
623
 
        self.line = line
624
 
        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
625
562
 
626
563
 
627
564
class IncompatibleRepositories(BzrError):
628
 
    """Report an error that two repositories are not compatible.
629
 
 
630
 
    Note that the source and target repositories are permitted to be strings:
631
 
    this exception is thrown from the smart server and may refer to a
632
 
    repository the client hasn't opened.
633
 
    """
634
 
 
635
 
    _fmt = "%(target)s\n" \
636
 
            "is not compatible with\n" \
637
 
            "%(source)s\n" \
638
 
            "%(details)s"
639
 
 
640
 
    def __init__(self, source, target, details=None):
641
 
        if details is None:
642
 
            details = "(no details)"
643
 
        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)
644
571
 
645
572
 
646
573
class IncompatibleRevision(BzrError):
647
 
 
 
574
    
648
575
    _fmt = "Revision is not compatible with %(repo_format)s"
649
576
 
650
577
    def __init__(self, repo_format):
655
582
class AlreadyVersionedError(BzrError):
656
583
    """Used when a path is expected not to be versioned, but it is."""
657
584
 
658
 
    _fmt = "%(context_info)s%(path)s is already versioned."
 
585
    _fmt = "%(context_info)s%(path)s is already versioned"
659
586
 
660
587
    def __init__(self, path, context_info=None):
661
588
        """Construct a new AlreadyVersionedError.
662
589
 
663
590
        :param path: This is the path which is versioned,
664
 
            which should be in a user friendly form.
 
591
        which should be in a user friendly form.
665
592
        :param context_info: If given, this is information about the context,
666
 
            which could explain why this is expected to not be versioned.
 
593
        which could explain why this is expected to not be versioned.
667
594
        """
668
595
        BzrError.__init__(self)
669
596
        self.path = path
676
603
class NotVersionedError(BzrError):
677
604
    """Used when a path is expected to be versioned, but it is not."""
678
605
 
679
 
    _fmt = "%(context_info)s%(path)s is not versioned."
 
606
    _fmt = "%(context_info)s%(path)s is not versioned"
680
607
 
681
608
    def __init__(self, path, context_info=None):
682
609
        """Construct a new NotVersionedError.
683
610
 
684
611
        :param path: This is the path which is not versioned,
685
 
            which should be in a user friendly form.
 
612
        which should be in a user friendly form.
686
613
        :param context_info: If given, this is information about the context,
687
 
            which could explain why this is expected to be versioned.
 
614
        which could explain why this is expected to be versioned.
688
615
        """
689
616
        BzrError.__init__(self)
690
617
        self.path = path
700
627
    _fmt = "Path(s) are not versioned: %(paths_as_string)s"
701
628
 
702
629
    def __init__(self, paths):
703
 
        from breezy.osutils import quotefn
 
630
        from bzrlib.osutils import quotefn
704
631
        BzrError.__init__(self)
705
632
        self.paths = paths
706
633
        self.paths_as_string = ' '.join([quotefn(p) for p in paths])
715
642
 
716
643
    def __init__(self, paths, extra=None):
717
644
        # circular import
718
 
        from breezy.osutils import quotefn
 
645
        from bzrlib.osutils import quotefn
719
646
        BzrError.__init__(self)
720
647
        self.paths = paths
721
648
        self.paths_as_string = ' '.join([quotefn(p) for p in paths])
733
660
        BzrError.__init__(self, filename=filename, kind=kind)
734
661
 
735
662
 
736
 
class BadFilenameEncoding(BzrError):
737
 
 
738
 
    _fmt = ('Filename %(filename)r is not valid in your current filesystem'
739
 
            ' encoding %(fs_encoding)s')
740
 
 
741
 
    def __init__(self, filename, fs_encoding):
742
 
        BzrError.__init__(self)
743
 
        self.filename = filename
744
 
        self.fs_encoding = fs_encoding
745
 
 
746
 
 
747
663
class ForbiddenControlFileError(BzrError):
748
664
 
749
 
    _fmt = 'Cannot operate on "%(filename)s" because it is a control file'
750
 
 
751
 
 
752
 
class LockError(InternalBzrError):
 
665
    _fmt = "Cannot operate on %(filename)s because it is a control file"
 
666
 
 
667
 
 
668
class LockError(BzrError):
753
669
 
754
670
    _fmt = "Lock error: %(msg)s"
755
671
 
 
672
    internal_error = True
 
673
 
756
674
    # All exceptions from the lock/unlock functions should be from
757
675
    # this exception class.  They will be translated as necessary. The
758
676
    # original exception is available as e.original_error
759
677
    #
760
678
    # New code should prefer to raise specific subclasses
761
 
    def __init__(self, msg):
762
 
        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
763
684
 
764
685
 
765
686
class LockActive(LockError):
799
720
        self.obj = obj
800
721
 
801
722
 
802
 
class LockFailed(LockError):
803
 
 
804
 
    internal_error = False
805
 
 
806
 
    _fmt = "Cannot lock %(lock)s: %(why)s"
807
 
 
808
 
    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):
809
728
        LockError.__init__(self, '')
810
 
        self.lock = lock
811
 
        self.why = why
 
729
        self.fname = fname
 
730
        self.msg = msg
812
731
 
813
732
 
814
733
class OutSideTransaction(BzrError):
838
757
 
839
758
class UnlockableTransport(LockError):
840
759
 
841
 
    internal_error = False
842
 
 
843
760
    _fmt = "Cannot lock: transport is read only: %(transport)s"
844
761
 
845
762
    def __init__(self, transport):
848
765
 
849
766
class LockContention(LockError):
850
767
 
851
 
    _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?
852
771
 
853
772
    internal_error = False
854
773
 
855
 
    def __init__(self, lock, msg=''):
 
774
    def __init__(self, lock):
856
775
        self.lock = lock
857
 
        self.msg = msg
858
776
 
859
777
 
860
778
class LockBroken(LockError):
881
799
        self.target = target
882
800
 
883
801
 
884
 
class LockCorrupt(LockError):
885
 
 
886
 
    _fmt = ("Lock is apparently held, but corrupted: %(corruption_info)s\n"
887
 
            "Use 'brz break-lock' to clear it")
888
 
 
889
 
    internal_error = False
890
 
 
891
 
    def __init__(self, corruption_info, file_data=None):
892
 
        self.corruption_info = corruption_info
893
 
        self.file_data = file_data
894
 
 
895
 
 
896
802
class LockNotHeld(LockError):
897
803
 
898
804
    _fmt = "Lock not held: %(lock)s"
907
813
 
908
814
    _fmt = "The object %(obj)s does not support token specifying a token when locking."
909
815
 
 
816
    internal_error = True
 
817
 
910
818
    def __init__(self, obj):
911
819
        self.obj = obj
912
820
 
922
830
        self.lock_token = lock_token
923
831
 
924
832
 
 
833
class PointlessCommit(BzrError):
 
834
 
 
835
    _fmt = "No changes to commit"
 
836
 
 
837
 
925
838
class UpgradeReadonly(BzrError):
926
839
 
927
840
    _fmt = "Upgrade URL cannot work with readonly URLs."
936
849
        self.format = format
937
850
 
938
851
 
939
 
class NoSuchRevision(InternalBzrError):
940
 
 
941
 
    _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
942
862
 
943
863
    def __init__(self, branch, revision):
944
 
        # 'branch' may sometimes be an internal object like a KnitRevisionStore
945
864
        BzrError.__init__(self, branch=branch, revision=revision)
946
865
 
947
866
 
948
 
class RangeInChangeOption(BzrError):
949
 
 
950
 
    _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)
951
878
 
952
879
 
953
880
class NoSuchRevisionSpec(BzrError):
960
887
 
961
888
class NoSuchRevisionInTree(NoSuchRevision):
962
889
    """When using Tree.revision_tree, and the revision is not accessible."""
963
 
 
964
 
    _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."
965
892
 
966
893
    def __init__(self, tree, revision_id):
967
894
        BzrError.__init__(self)
971
898
 
972
899
class InvalidRevisionSpec(BzrError):
973
900
 
974
 
    _fmt = ("Requested revision: '%(spec)s' does not exist in branch:"
975
 
            " %(branch_url)s%(extra)s")
 
901
    _fmt = ("Requested revision: %(spec)r does not exist in branch:"
 
902
            " %(branch)s%(extra)s")
976
903
 
977
904
    def __init__(self, spec, branch, extra=None):
978
905
        BzrError.__init__(self, branch=branch, spec=spec)
979
 
        self.branch_url = getattr(branch, 'user_url', str(branch))
980
906
        if extra:
981
907
            self.extra = '\n' + str(extra)
982
908
        else:
983
909
            self.extra = ''
984
910
 
985
911
 
 
912
class HistoryMissing(BzrError):
 
913
 
 
914
    _fmt = "%(branch)s is missing %(object_type)s {%(object_id)s}"
 
915
 
 
916
 
986
917
class AppendRevisionsOnlyViolation(BzrError):
987
918
 
988
919
    _fmt = ('Operation denied because it would change the main history,'
990
921
           ' branch "%(location)s".')
991
922
 
992
923
    def __init__(self, location):
993
 
       import breezy.urlutils as urlutils
 
924
       import bzrlib.urlutils as urlutils
994
925
       location = urlutils.unescape_for_display(location, 'ascii')
995
926
       BzrError.__init__(self, location=location)
996
927
 
998
929
class DivergedBranches(BzrError):
999
930
 
1000
931
    _fmt = ("These branches have diverged."
1001
 
            " Use the missing command to see how.\n"
1002
 
            "Use the merge command to reconcile them.")
 
932
            " Use the merge command to reconcile them.")
 
933
 
 
934
    internal_error = False
1003
935
 
1004
936
    def __init__(self, branch1, branch2):
1005
937
        self.branch1 = branch1
1006
938
        self.branch2 = branch2
1007
939
 
1008
940
 
1009
 
class NotLefthandHistory(InternalBzrError):
 
941
class NotLefthandHistory(BzrError):
1010
942
 
1011
943
    _fmt = "Supplied history does not follow left-hand parents"
1012
944
 
 
945
    internal_error = True
 
946
 
1013
947
    def __init__(self, history):
1014
948
        BzrError.__init__(self, history=history)
1015
949
 
1019
953
    _fmt = ("Branches have no common ancestor, and"
1020
954
            " no merge base revision was specified.")
1021
955
 
1022
 
 
1023
 
class CannotReverseCherrypick(BzrError):
1024
 
 
1025
 
    _fmt = ('Selected merge cannot perform reverse cherrypicks.  Try merge3'
1026
 
            ' or diff3.')
 
956
    internal_error = False
1027
957
 
1028
958
 
1029
959
class NoCommonAncestor(BzrError):
1030
 
 
 
960
    
1031
961
    _fmt = "Revisions have no common ancestor: %(revision_a)s %(revision_b)s"
1032
962
 
1033
963
    def __init__(self, revision_a, revision_b):
1053
983
            not_ancestor_id=not_ancestor_id)
1054
984
 
1055
985
 
1056
 
class NoCommits(BranchError):
 
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):
1057
1007
 
1058
1008
    _fmt = "Branch %(branch)s has no commits."
1059
1009
 
 
1010
    def __init__(self, branch):
 
1011
        BzrError.__init__(self, branch=branch)
 
1012
 
1060
1013
 
1061
1014
class UnlistableStore(BzrError):
1062
1015
 
1073
1026
 
1074
1027
class BoundBranchOutOfDate(BzrError):
1075
1028
 
1076
 
    _fmt = ("Bound branch %(branch)s is out of date with master branch"
1077
 
            " %(master)s.%(extra_help)s")
 
1029
    _fmt = ("Bound branch %(branch)s is out of date"
 
1030
            " with master branch %(master)s.")
1078
1031
 
1079
1032
    def __init__(self, branch, master):
1080
1033
        BzrError.__init__(self)
1081
1034
        self.branch = branch
1082
1035
        self.master = master
1083
 
        self.extra_help = ''
1084
 
 
1085
 
 
 
1036
 
 
1037
        
1086
1038
class CommitToDoubleBoundBranch(BzrError):
1087
1039
 
1088
1040
    _fmt = ("Cannot commit to branch %(branch)s."
1116
1068
        self.error = error
1117
1069
 
1118
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
 
1119
1144
class VersionedFileError(BzrError):
1120
 
 
 
1145
    
1121
1146
    _fmt = "Versioned file error"
1122
1147
 
1123
1148
 
1124
1149
class RevisionNotPresent(VersionedFileError):
1125
 
 
1126
 
    _fmt = 'Revision {%(revision_id)s} not present in "%(file_id)s".'
 
1150
    
 
1151
    _fmt = "Revision {%(revision_id)s} not present in %(file_id)s."
1127
1152
 
1128
1153
    def __init__(self, revision_id, file_id):
1129
1154
        VersionedFileError.__init__(self)
1132
1157
 
1133
1158
 
1134
1159
class RevisionAlreadyPresent(VersionedFileError):
1135
 
 
1136
 
    _fmt = 'Revision {%(revision_id)s} already present in "%(file_id)s".'
 
1160
    
 
1161
    _fmt = "Revision {%(revision_id)s} already present in %(file_id)s."
1137
1162
 
1138
1163
    def __init__(self, revision_id, file_id):
1139
1164
        VersionedFileError.__init__(self)
1141
1166
        self.file_id = file_id
1142
1167
 
1143
1168
 
1144
 
class VersionedFileInvalidChecksum(VersionedFileError):
1145
 
 
1146
 
    _fmt = "Text did not match its checksum: %(msg)s"
1147
 
 
1148
 
 
1149
 
class RetryWithNewPacks(BzrError):
1150
 
    """Raised when we realize that the packs on disk have changed.
1151
 
 
1152
 
    This is meant as more of a signaling exception, to trap between where a
1153
 
    local error occurred and the code that can actually handle the error and
1154
 
    code that can retry appropriately.
1155
 
    """
1156
 
 
1157
 
    internal_error = True
1158
 
 
1159
 
    _fmt = ("Pack files have changed, reload and retry. context: %(context)s"
1160
 
            " %(orig_error)s")
1161
 
 
1162
 
    def __init__(self, context, reload_occurred, exc_info):
1163
 
        """create a new RetryWithNewPacks error.
1164
 
 
1165
 
        :param reload_occurred: Set to True if we know that the packs have
1166
 
            already been reloaded, and we are failing because of an in-memory
1167
 
            cache miss. If set to True then we will ignore if a reload says
1168
 
            nothing has changed, because we assume it has already reloaded. If
1169
 
            False, then a reload with nothing changed will force an error.
1170
 
        :param exc_info: The original exception traceback, so if there is a
1171
 
            problem we can raise the original error (value from sys.exc_info())
1172
 
        """
1173
 
        BzrError.__init__(self)
1174
 
        self.context = context
1175
 
        self.reload_occurred = reload_occurred
1176
 
        self.exc_info = exc_info
1177
 
        self.orig_error = exc_info[1]
1178
 
        # TODO: The global error handler should probably treat this by
1179
 
        #       raising/printing the original exception with a bit about
1180
 
        #       RetryWithNewPacks also not being caught
1181
 
 
1182
 
 
1183
 
class RetryAutopack(RetryWithNewPacks):
1184
 
    """Raised when we are autopacking and we find a missing file.
1185
 
 
1186
 
    Meant as a signaling exception, to tell the autopack code it should try
1187
 
    again.
1188
 
    """
1189
 
 
1190
 
    internal_error = True
1191
 
 
1192
 
    _fmt = ("Pack files have changed, reload and try autopack again."
1193
 
            " 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
1194
1209
 
1195
1210
 
1196
1211
class NoSuchExportFormat(BzrError):
1197
 
 
 
1212
    
1198
1213
    _fmt = "Export format %(format)r not supported"
1199
1214
 
1200
1215
    def __init__(self, format):
1203
1218
 
1204
1219
 
1205
1220
class TransportError(BzrError):
1206
 
 
 
1221
    
1207
1222
    _fmt = "Transport error: %(msg)s %(orig_error)s"
1208
1223
 
1209
1224
    def __init__(self, msg=None, orig_error=None):
1218
1233
        BzrError.__init__(self)
1219
1234
 
1220
1235
 
1221
 
class TooManyConcurrentRequests(InternalBzrError):
 
1236
class TooManyConcurrentRequests(BzrError):
1222
1237
 
1223
1238
    _fmt = ("The medium '%(medium)s' has reached its concurrent request limit."
1224
1239
            " Be sure to finish_writing and finish_reading on the"
1225
1240
            " currently open request.")
1226
1241
 
 
1242
    internal_error = True
 
1243
 
1227
1244
    def __init__(self, medium):
1228
1245
        self.medium = medium
1229
1246
 
1236
1253
        self.details = details
1237
1254
 
1238
1255
 
1239
 
class UnexpectedProtocolVersionMarker(TransportError):
1240
 
 
1241
 
    _fmt = "Received bad protocol version marker: %(marker)r"
1242
 
 
1243
 
    def __init__(self, marker):
1244
 
        self.marker = marker
1245
 
 
1246
 
 
1247
 
class UnknownSmartMethod(InternalBzrError):
1248
 
 
1249
 
    _fmt = "The server does not recognise the '%(verb)s' request."
1250
 
 
1251
 
    def __init__(self, verb):
1252
 
        self.verb = verb
1253
 
 
1254
 
 
1255
 
class SmartMessageHandlerError(InternalBzrError):
1256
 
 
1257
 
    _fmt = ("The message handler raised an exception:\n"
1258
 
            "%(traceback_text)s")
1259
 
 
1260
 
    def __init__(self, exc_info):
1261
 
        import traceback
1262
 
        # GZ 2010-08-10: Cycle with exc_tb/exc_info affects at least one test
1263
 
        self.exc_type, self.exc_value, self.exc_tb = exc_info
1264
 
        self.exc_info = exc_info
1265
 
        traceback_strings = traceback.format_exception(
1266
 
                self.exc_type, self.exc_value, self.exc_tb)
1267
 
        self.traceback_text = ''.join(traceback_strings)
1268
 
 
1269
 
 
1270
1256
# A set of semi-meaningful errors which can be thrown
1271
1257
class TransportNotPossible(TransportError):
1272
1258
 
1297
1283
            self.port = ':%s' % port
1298
1284
 
1299
1285
 
1300
 
# XXX: This is also used for unexpected end of file, which is different at the
1301
 
# TCP level from "connection reset".
1302
1286
class ConnectionReset(TransportError):
1303
1287
 
1304
1288
    _fmt = "Connection closed: %(msg)s %(orig_error)s"
1305
1289
 
1306
1290
 
1307
 
class ConnectionTimeout(ConnectionError):
1308
 
 
1309
 
    _fmt = "Connection Timeout: %(msg)s%(orig_error)s"
1310
 
 
1311
 
 
1312
1291
class InvalidRange(TransportError):
1313
1292
 
1314
 
    _fmt = "Invalid range access in %(path)s at %(offset)s: %(msg)s"
1315
 
 
1316
 
    def __init__(self, path, offset, msg=None):
1317
 
        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)))
1318
1298
        self.path = path
1319
1299
        self.offset = offset
1320
1300
 
1321
1301
 
1322
1302
class InvalidHttpResponse(TransportError):
1323
1303
 
1324
 
    _fmt = "Invalid http response for %(path)s: %(msg)s%(orig_error)s"
 
1304
    _fmt = "Invalid http response for %(path)s: %(msg)s"
1325
1305
 
1326
1306
    def __init__(self, path, msg, orig_error=None):
1327
1307
        self.path = path
1328
 
        if orig_error is None:
1329
 
            orig_error = ''
1330
 
        else:
1331
 
            # This is reached for obscure and unusual errors so we want to
1332
 
            # preserve as much info as possible to ease debug.
1333
 
            orig_error = ': %r' % (orig_error,)
1334
1308
        TransportError.__init__(self, msg, orig_error=orig_error)
1335
1309
 
1336
1310
 
1337
1311
class InvalidHttpRange(InvalidHttpResponse):
1338
1312
 
1339
1313
    _fmt = "Invalid http range %(range)r for %(path)s: %(msg)s"
1340
 
 
 
1314
    
1341
1315
    def __init__(self, path, range, msg):
1342
1316
        self.range = range
1343
1317
        InvalidHttpResponse.__init__(self, path, msg)
1344
1318
 
1345
1319
 
1346
 
class HttpBoundaryMissing(InvalidHttpResponse):
1347
 
    """A multipart response ends with no boundary marker.
1348
 
 
1349
 
    This is a special case caused by buggy proxies, described in
1350
 
    <https://bugs.launchpad.net/bzr/+bug/198646>.
1351
 
    """
1352
 
 
1353
 
    _fmt = "HTTP MIME Boundary missing for %(path)s: %(msg)s"
1354
 
 
1355
 
    def __init__(self, path, msg):
1356
 
        InvalidHttpResponse.__init__(self, path, msg)
1357
 
 
1358
 
 
1359
1320
class InvalidHttpContentType(InvalidHttpResponse):
1360
1321
 
1361
1322
    _fmt = 'Invalid http Content-type "%(ctype)s" for %(path)s: %(msg)s'
1362
 
 
 
1323
    
1363
1324
    def __init__(self, path, ctype, msg):
1364
1325
        self.ctype = ctype
1365
1326
        InvalidHttpResponse.__init__(self, path, msg)
1369
1330
 
1370
1331
    _fmt = '%(source)s is%(permanently)s redirected to %(target)s'
1371
1332
 
1372
 
    def __init__(self, source, target, is_permanent=False):
 
1333
    def __init__(self, source, target, is_permament=False, qual_proto=None):
1373
1334
        self.source = source
1374
1335
        self.target = target
1375
 
        if is_permanent:
 
1336
        if is_permament:
1376
1337
            self.permanently = ' permanently'
1377
1338
        else:
1378
1339
            self.permanently = ''
 
1340
        self.is_permament = is_permament
 
1341
        self._qualified_proto = qual_proto
1379
1342
        TransportError.__init__(self)
1380
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
 
1381
1377
 
1382
1378
class TooManyRedirections(TransportError):
1383
1379
 
1384
1380
    _fmt = "Too many redirections"
1385
1381
 
1386
 
 
1387
1382
class ConflictsInTree(BzrError):
1388
1383
 
1389
1384
    _fmt = "Working tree has conflicts."
1390
1385
 
1391
1386
 
1392
 
class DependencyNotPresent(BzrError):
1393
 
 
1394
 
    _fmt = 'Unable to import library "%(library)s": %(error)s'
1395
 
 
1396
 
    def __init__(self, library, error):
1397
 
        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)
1398
1412
 
1399
1413
 
1400
1414
class WorkingTreeNotRevision(BzrError):
1401
1415
 
1402
 
    _fmt = ("The working tree for %(basedir)s has changed since"
 
1416
    _fmt = ("The working tree for %(basedir)s has changed since" 
1403
1417
            " the last commit, but weave merge requires that it be"
1404
1418
            " unchanged")
1405
1419
 
1422
1436
        self.graph = graph
1423
1437
 
1424
1438
 
1425
 
class WritingCompleted(InternalBzrError):
 
1439
class WritingCompleted(BzrError):
1426
1440
 
1427
1441
    _fmt = ("The MediumRequest '%(request)s' has already had finish_writing "
1428
1442
            "called upon it - accept bytes may not be called anymore.")
1429
1443
 
 
1444
    internal_error = True
 
1445
 
1430
1446
    def __init__(self, request):
1431
1447
        self.request = request
1432
1448
 
1433
1449
 
1434
 
class WritingNotComplete(InternalBzrError):
 
1450
class WritingNotComplete(BzrError):
1435
1451
 
1436
1452
    _fmt = ("The MediumRequest '%(request)s' has not has finish_writing "
1437
1453
            "called upon it - until the write phase is complete no "
1438
1454
            "data may be read.")
1439
1455
 
 
1456
    internal_error = True
 
1457
 
1440
1458
    def __init__(self, request):
1441
1459
        self.request = request
1442
1460
 
1450
1468
        self.filename = filename
1451
1469
 
1452
1470
 
1453
 
class MediumNotConnected(InternalBzrError):
 
1471
class MediumNotConnected(BzrError):
1454
1472
 
1455
1473
    _fmt = """The medium '%(medium)s' is not connected."""
1456
1474
 
 
1475
    internal_error = True
 
1476
 
1457
1477
    def __init__(self, medium):
1458
1478
        self.medium = medium
1459
1479
 
1465
1485
 
1466
1486
class NoBundleFound(BzrError):
1467
1487
 
1468
 
    _fmt = 'No bundle was found in "%(filename)s".'
 
1488
    _fmt = "No bundle was found in %(filename)s"
1469
1489
 
1470
1490
    def __init__(self, filename):
1471
1491
        BzrError.__init__(self)
1510
1530
    _fmt = "Key %(key)s is already present in map"
1511
1531
 
1512
1532
 
1513
 
class DuplicateHelpPrefix(BzrError):
1514
 
 
1515
 
    _fmt = "The prefix %(prefix)s is in the help search path twice."
1516
 
 
1517
 
    def __init__(self, prefix):
1518
 
        self.prefix = prefix
1519
 
 
1520
 
 
1521
 
class MalformedTransform(InternalBzrError):
 
1533
class MalformedTransform(BzrError):
1522
1534
 
1523
1535
    _fmt = "Tree transform is malformed %(conflicts)r"
1524
1536
 
1535
1547
        self.root_trans_id = transform.root
1536
1548
 
1537
1549
 
1538
 
class BzrBadParameter(InternalBzrError):
 
1550
class BzrBadParameter(BzrError):
1539
1551
 
1540
1552
    _fmt = "Bad parameter: %(param)r"
1541
1553
 
1562
1574
    _fmt = "Moving the root directory is not supported at this time"
1563
1575
 
1564
1576
 
1565
 
class TransformRenameFailed(BzrError):
1566
 
 
1567
 
    _fmt = "Failed to rename %(from_path)s to %(to_path)s: %(why)s"
1568
 
 
1569
 
    def __init__(self, from_path, to_path, why, errno):
1570
 
        self.from_path = from_path
1571
 
        self.to_path = to_path
1572
 
        self.why = why
1573
 
        self.errno = errno
1574
 
 
1575
 
 
1576
1577
class BzrMoveFailedError(BzrError):
1577
1578
 
1578
 
    _fmt = ("Could not move %(from_path)s%(operator)s %(to_path)s"
1579
 
        "%(_has_extra)s%(extra)s")
 
1579
    _fmt = "Could not move %(from_path)s%(operator)s %(to_path)s%(extra)s"
1580
1580
 
1581
1581
    def __init__(self, from_path='', to_path='', extra=None):
1582
 
        from breezy.osutils import splitpath
1583
1582
        BzrError.__init__(self)
1584
1583
        if extra:
1585
 
            self.extra, self._has_extra = extra, ': '
 
1584
            self.extra = ': ' + str(extra)
1586
1585
        else:
1587
 
            self.extra = self._has_extra = ''
 
1586
            self.extra = ''
1588
1587
 
1589
1588
        has_from = len(from_path) > 0
1590
1589
        has_to = len(to_path) > 0
1591
1590
        if has_from:
1592
 
            self.from_path = splitpath(from_path)[-1]
 
1591
            self.from_path = osutils.splitpath(from_path)[-1]
1593
1592
        else:
1594
1593
            self.from_path = ''
1595
1594
 
1596
1595
        if has_to:
1597
 
            self.to_path = splitpath(to_path)[-1]
 
1596
            self.to_path = osutils.splitpath(to_path)[-1]
1598
1597
        else:
1599
1598
            self.to_path = ''
1600
1599
 
1611
1610
 
1612
1611
class BzrRenameFailedError(BzrMoveFailedError):
1613
1612
 
1614
 
    _fmt = ("Could not rename %(from_path)s%(operator)s %(to_path)s"
1615
 
        "%(_has_extra)s%(extra)s")
 
1613
    _fmt = "Could not rename %(from_path)s%(operator)s %(to_path)s%(extra)s"
1616
1614
 
1617
1615
    def __init__(self, from_path, to_path, extra=None):
1618
1616
        BzrMoveFailedError.__init__(self, from_path, to_path, extra)
1625
1623
 
1626
1624
class BzrBadParameterMissing(BzrBadParameter):
1627
1625
 
1628
 
    _fmt = "Parameter %(param)s is required but not present."
 
1626
    _fmt = "Parameter $(param)s is required but not present."
1629
1627
 
1630
1628
 
1631
1629
class BzrBadParameterUnicode(BzrBadParameter):
1639
1637
    _fmt = "Parameter %(param)s contains a newline."
1640
1638
 
1641
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
 
1642
1648
class ParamikoNotPresent(DependencyNotPresent):
1643
1649
 
1644
1650
    _fmt = "Unable to import paramiko (required for sftp support): %(error)s"
1654
1660
 
1655
1661
class UninitializableFormat(BzrError):
1656
1662
 
1657
 
    _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."
1658
1664
 
1659
1665
    def __init__(self, format):
1660
1666
        BzrError.__init__(self)
1663
1669
 
1664
1670
class BadConversionTarget(BzrError):
1665
1671
 
1666
 
    _fmt = "Cannot convert from format %(from_format)s to format %(format)s." \
1667
 
            "    %(problem)s"
 
1672
    _fmt = "Cannot convert to format %(format)s.  %(problem)s"
1668
1673
 
1669
 
    def __init__(self, problem, format, from_format=None):
 
1674
    def __init__(self, problem, format):
1670
1675
        BzrError.__init__(self)
1671
1676
        self.problem = problem
1672
1677
        self.format = format
1673
 
        self.from_format = from_format or '(unspecified)'
1674
 
 
1675
 
 
1676
 
class NoDiffFound(BzrError):
1677
 
 
1678
 
    _fmt = 'Could not find an appropriate Differ for file "%(path)s"'
1679
 
 
1680
 
    def __init__(self, path):
1681
 
        BzrError.__init__(self, path)
1682
 
 
1683
 
 
1684
 
class ExecutableMissing(BzrError):
1685
 
 
1686
 
    _fmt = "%(exe_name)s could not be found on this machine"
1687
 
 
1688
 
    def __init__(self, exe_name):
1689
 
        BzrError.__init__(self, exe_name=exe_name)
1690
1678
 
1691
1679
 
1692
1680
class NoDiff(BzrError):
1702
1690
    _fmt = "Diff3 is not installed on this machine."
1703
1691
 
1704
1692
 
1705
 
class ExistingContent(BzrError):
1706
 
    # Added in breezy 0.92, used by VersionedFile.add_lines.
1707
 
 
1708
 
    _fmt = "The content being inserted is already present."
1709
 
 
1710
 
 
1711
1693
class ExistingLimbo(BzrError):
1712
1694
 
1713
1695
    _fmt = """This tree contains left-over files from a failed operation.
1714
1696
    Please examine %(limbo_dir)s to see if it contains any files you wish to
1715
1697
    keep, and delete it when you are done."""
1716
 
 
 
1698
    
1717
1699
    def __init__(self, limbo_dir):
1718
1700
       BzrError.__init__(self)
1719
1701
       self.limbo_dir = limbo_dir
1720
1702
 
1721
1703
 
1722
 
class ExistingPendingDeletion(BzrError):
1723
 
 
1724
 
    _fmt = """This tree contains left-over files from a failed operation.
1725
 
    Please examine %(pending_deletion)s to see if it contains any files you
1726
 
    wish to keep, and delete it when you are done."""
1727
 
 
1728
 
    def __init__(self, pending_deletion):
1729
 
       BzrError.__init__(self, pending_deletion=pending_deletion)
1730
 
 
1731
 
 
1732
1704
class ImmortalLimbo(BzrError):
1733
1705
 
1734
 
    _fmt = """Unable to delete transform temporary directory %(limbo_dir)s.
 
1706
    _fmt = """Unable to delete transform temporary directory $(limbo_dir)s.
1735
1707
    Please examine %(limbo_dir)s to see if it contains any files you wish to
1736
1708
    keep, and delete it when you are done."""
1737
1709
 
1740
1712
       self.limbo_dir = limbo_dir
1741
1713
 
1742
1714
 
1743
 
class ImmortalPendingDeletion(BzrError):
1744
 
 
1745
 
    _fmt = ("Unable to delete transform temporary directory "
1746
 
    "%(pending_deletion)s.  Please examine %(pending_deletion)s to see if it "
1747
 
    "contains any files you wish to keep, and delete it when you are done.")
1748
 
 
1749
 
    def __init__(self, pending_deletion):
1750
 
       BzrError.__init__(self, pending_deletion=pending_deletion)
1751
 
 
1752
 
 
1753
1715
class OutOfDateTree(BzrError):
1754
1716
 
1755
 
    _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'."
1756
1718
 
1757
 
    def __init__(self, tree, more=None):
1758
 
        if more is None:
1759
 
            more = ''
1760
 
        else:
1761
 
            more = ' ' + more
 
1719
    def __init__(self, tree):
1762
1720
        BzrError.__init__(self)
1763
1721
        self.tree = tree
1764
 
        self.more = more
1765
1722
 
1766
1723
 
1767
1724
class PublicBranchOutOfDate(BzrError):
1770
1727
        '"%(revstring)s".'
1771
1728
 
1772
1729
    def __init__(self, public_location, revstring):
1773
 
        import breezy.urlutils as urlutils
 
1730
        import bzrlib.urlutils as urlutils
1774
1731
        public_location = urlutils.unescape_for_display(public_location,
1775
1732
                                                        'ascii')
1776
1733
        BzrError.__init__(self, public_location=public_location,
1790
1747
class CorruptRepository(BzrError):
1791
1748
 
1792
1749
    _fmt = ("An error has been detected in the repository %(repo_path)s.\n"
1793
 
            "Please run brz reconcile on this repository.")
 
1750
            "Please run bzr reconcile on this repository.")
1794
1751
 
1795
1752
    def __init__(self, repo):
1796
1753
        BzrError.__init__(self)
1797
 
        self.repo_path = repo.user_url
1798
 
 
1799
 
 
1800
 
class InconsistentDelta(BzrError):
1801
 
    """Used when we get a delta that is not valid."""
1802
 
 
1803
 
    _fmt = ("An inconsistent delta was supplied involving %(path)r,"
1804
 
            " %(file_id)r\nreason: %(reason)s")
1805
 
 
1806
 
    def __init__(self, path, file_id, reason):
1807
 
        BzrError.__init__(self)
1808
 
        self.path = path
1809
 
        self.file_id = file_id
1810
 
        self.reason = reason
1811
 
 
1812
 
 
1813
 
class InconsistentDeltaDelta(InconsistentDelta):
1814
 
    """Used when we get a delta that is not valid."""
1815
 
 
1816
 
    _fmt = ("An inconsistent delta was supplied: %(delta)r"
1817
 
            "\nreason: %(reason)s")
1818
 
 
1819
 
    def __init__(self, delta, reason):
1820
 
        BzrError.__init__(self)
1821
 
        self.delta = delta
1822
 
        self.reason = reason
 
1754
        self.repo_path = repo.bzrdir.root_transport.base
1823
1755
 
1824
1756
 
1825
1757
class UpgradeRequired(BzrError):
1831
1763
        self.path = path
1832
1764
 
1833
1765
 
1834
 
class RepositoryUpgradeRequired(UpgradeRequired):
1835
 
 
1836
 
    _fmt = "To use this feature you must upgrade your repository at %(path)s."
1837
 
 
1838
 
 
1839
 
class RichRootUpgradeRequired(UpgradeRequired):
1840
 
 
1841
 
    _fmt = ("To use this feature you must upgrade your branch at %(path)s to"
1842
 
           " a format which supports rich roots.")
1843
 
 
1844
 
 
1845
1766
class LocalRequiresBoundBranch(BzrError):
1846
1767
 
1847
1768
    _fmt = "Cannot perform local-only commits on unbound branches."
1848
1769
 
1849
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
 
1850
1785
class UnsupportedOperation(BzrError):
1851
1786
 
1852
1787
    _fmt = ("The method %(mname)s is not supported on"
1858
1793
        self.tname = type(method_self).__name__
1859
1794
 
1860
1795
 
1861
 
class FetchLimitUnsupported(UnsupportedOperation):
1862
 
 
1863
 
    fmt = ("InterBranch %(interbranch)r does not support fetching limits.")
1864
 
 
1865
 
    def __init__(self, interbranch):
1866
 
        BzrError.__init__(self, interbranch=interbranch)
 
1796
class CannotSetRevisionId(UnsupportedOperation):
 
1797
    """Raised when a commit is attempting to set a revision id but cant."""
1867
1798
 
1868
1799
 
1869
1800
class NonAsciiRevisionId(UnsupportedOperation):
1872
1803
    """
1873
1804
 
1874
1805
 
1875
 
class GhostTagsNotSupported(BzrError):
1876
 
 
1877
 
    _fmt = "Ghost tags not supported by format %(format)r."
1878
 
 
1879
 
    def __init__(self, format):
1880
 
        self.format = format
1881
 
 
1882
 
 
1883
1806
class BinaryFile(BzrError):
1884
 
 
 
1807
    
1885
1808
    _fmt = "File is binary but should be text."
1886
1809
 
1887
1810
 
1907
1830
 
1908
1831
 
1909
1832
class NotABundle(BzrError):
1910
 
 
 
1833
    
1911
1834
    _fmt = "Not a bzr revision-bundle: %(text)r"
1912
1835
 
1913
1836
    def __init__(self, text):
1915
1838
        self.text = text
1916
1839
 
1917
1840
 
1918
 
class BadBundle(BzrError):
1919
 
 
 
1841
class BadBundle(BzrError): 
 
1842
    
1920
1843
    _fmt = "Bad bzr revision-bundle: %(text)r"
1921
1844
 
1922
1845
    def __init__(self, text):
1924
1847
        self.text = text
1925
1848
 
1926
1849
 
1927
 
class MalformedHeader(BadBundle):
1928
 
 
 
1850
class MalformedHeader(BadBundle): 
 
1851
    
1929
1852
    _fmt = "Malformed bzr revision-bundle header: %(text)r"
1930
1853
 
1931
1854
 
1932
 
class MalformedPatches(BadBundle):
1933
 
 
 
1855
class MalformedPatches(BadBundle): 
 
1856
    
1934
1857
    _fmt = "Malformed patches in bzr revision-bundle: %(text)r"
1935
1858
 
1936
1859
 
1937
 
class MalformedFooter(BadBundle):
1938
 
 
 
1860
class MalformedFooter(BadBundle): 
 
1861
    
1939
1862
    _fmt = "Malformed footer in bzr revision-bundle: %(text)r"
1940
1863
 
1941
1864
 
1942
1865
class UnsupportedEOLMarker(BadBundle):
1943
 
 
1944
 
    _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"    
1945
1868
 
1946
1869
    def __init__(self):
1947
 
        # XXX: BadBundle's constructor assumes there's explanatory text,
 
1870
        # XXX: BadBundle's constructor assumes there's explanatory text, 
1948
1871
        # but for this there is not
1949
1872
        BzrError.__init__(self)
1950
1873
 
1951
1874
 
1952
1875
class IncompatibleBundleFormat(BzrError):
1953
 
 
 
1876
    
1954
1877
    _fmt = "Bundle format %(bundle_format)s is incompatible with %(other)s"
1955
1878
 
1956
1879
    def __init__(self, bundle_format, other):
1960
1883
 
1961
1884
 
1962
1885
class BadInventoryFormat(BzrError):
1963
 
 
 
1886
    
1964
1887
    _fmt = "Root class for inventory serialization errors"
1965
1888
 
1966
1889
 
1977
1900
    _fmt = """This operation requires rich root data storage"""
1978
1901
 
1979
1902
 
1980
 
class NoSmartMedium(InternalBzrError):
 
1903
class NoSmartMedium(BzrError):
1981
1904
 
1982
1905
    _fmt = "The transport '%(transport)s' cannot tunnel the smart protocol."
1983
1906
 
 
1907
    internal_error = True
 
1908
 
1984
1909
    def __init__(self, transport):
1985
1910
        self.transport = transport
1986
1911
 
1987
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
 
1988
1921
class UnknownSSH(BzrError):
1989
1922
 
1990
 
    _fmt = "Unrecognised value for BRZ_SSH environment variable: %(vendor)s"
 
1923
    _fmt = "Unrecognised value for BZR_SSH environment variable: %(vendor)s"
1991
1924
 
1992
1925
    def __init__(self, vendor):
1993
1926
        BzrError.__init__(self)
1997
1930
class SSHVendorNotFound(BzrError):
1998
1931
 
1999
1932
    _fmt = ("Don't know how to handle SSH connections."
2000
 
            " Please set BRZ_SSH environment variable.")
2001
 
 
2002
 
 
2003
 
class GhostRevisionsHaveNoRevno(BzrError):
2004
 
    """When searching for revnos, if we encounter a ghost, we are stuck"""
2005
 
 
2006
 
    _fmt = ("Could not determine revno for {%(revision_id)s} because"
2007
 
            " its ancestry shows a ghost at {%(ghost_revision_id)s}")
2008
 
 
2009
 
    def __init__(self, revision_id, ghost_revision_id):
2010
 
        self.revision_id = revision_id
2011
 
        self.ghost_revision_id = ghost_revision_id
 
1933
            " Please set BZR_SSH environment variable.")
2012
1934
 
2013
1935
 
2014
1936
class GhostRevisionUnusableHere(BzrError):
2020
1942
        self.revision_id = revision_id
2021
1943
 
2022
1944
 
2023
 
class IllegalUseOfScopeReplacer(InternalBzrError):
 
1945
class IllegalUseOfScopeReplacer(BzrError):
2024
1946
 
2025
1947
    _fmt = ("ScopeReplacer object %(name)r was used incorrectly:"
2026
1948
            " %(msg)s%(extra)s")
2027
1949
 
 
1950
    internal_error = True
 
1951
 
2028
1952
    def __init__(self, name, msg, extra=None):
2029
1953
        BzrError.__init__(self)
2030
1954
        self.name = name
2035
1959
            self.extra = ''
2036
1960
 
2037
1961
 
2038
 
class InvalidImportLine(InternalBzrError):
 
1962
class InvalidImportLine(BzrError):
2039
1963
 
2040
1964
    _fmt = "Not a valid import statement: %(msg)\n%(text)s"
2041
1965
 
 
1966
    internal_error = True
 
1967
 
2042
1968
    def __init__(self, text, msg):
2043
1969
        BzrError.__init__(self)
2044
1970
        self.text = text
2045
1971
        self.msg = msg
2046
1972
 
2047
1973
 
2048
 
class ImportNameCollision(InternalBzrError):
 
1974
class ImportNameCollision(BzrError):
2049
1975
 
2050
1976
    _fmt = ("Tried to import an object to the same name as"
2051
1977
            " an existing object. %(name)s")
2052
1978
 
 
1979
    internal_error = True
 
1980
 
2053
1981
    def __init__(self, name):
2054
1982
        BzrError.__init__(self)
2055
1983
        self.name = name
2068
1996
        " branch location."
2069
1997
 
2070
1998
 
2071
 
class IllegalMergeDirectivePayload(BzrError):
2072
 
    """A merge directive contained something other than a patch or bundle"""
2073
 
 
2074
 
    _fmt = "Bad merge directive payload %(start)r"
2075
 
 
2076
 
    def __init__(self, start):
2077
 
        BzrError(self)
2078
 
        self.start = start
2079
 
 
2080
 
 
2081
 
class PatchVerificationFailed(BzrError):
2082
 
    """A patch from a merge directive could not be verified"""
2083
 
 
2084
 
    _fmt = "Preview patch does not match requested changes."
2085
 
 
2086
 
 
2087
1999
class PatchMissing(BzrError):
2088
2000
    """Raise a patch type was specified but no patch supplied"""
2089
2001
 
2090
 
    _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."
2091
2003
 
2092
2004
    def __init__(self, patch_type):
2093
2005
        BzrError.__init__(self)
2094
2006
        self.patch_type = patch_type
2095
2007
 
2096
2008
 
2097
 
class TargetNotBranch(BzrError):
2098
 
    """A merge directive's target branch is required, but isn't a branch"""
2099
 
 
2100
 
    _fmt = ("Your branch does not have all of the revisions required in "
2101
 
            "order to merge this merge directive and the target "
2102
 
            "location specified in the merge directive is not a branch: "
2103
 
            "%(location)s.")
2104
 
 
2105
 
    def __init__(self, location):
2106
 
        BzrError.__init__(self)
2107
 
        self.location = location
2108
 
 
2109
 
 
2110
2009
class UnsupportedInventoryKind(BzrError):
2111
 
 
 
2010
    
2112
2011
    _fmt = """Unsupported entry kind %(kind)s"""
2113
2012
 
2114
2013
    def __init__(self, kind):
2117
2016
 
2118
2017
class BadSubsumeSource(BzrError):
2119
2018
 
2120
 
    _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"""
2121
2020
 
2122
2021
    def __init__(self, tree, other_tree, reason):
2123
2022
        self.tree = tree
2126
2025
 
2127
2026
 
2128
2027
class SubsumeTargetNeedsUpgrade(BzrError):
2129
 
 
 
2028
    
2130
2029
    _fmt = """Subsume target %(other_tree)s needs to be upgraded."""
2131
2030
 
2132
2031
    def __init__(self, other_tree):
2133
2032
        self.other_tree = other_tree
2134
2033
 
2135
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
 
2136
2047
class NoSuchTag(BzrError):
2137
2048
 
2138
2049
    _fmt = "No such tag: %(tag_name)s"
2144
2055
class TagsNotSupported(BzrError):
2145
2056
 
2146
2057
    _fmt = ("Tags not supported by %(branch)s;"
2147
 
            " you may be able to use brz upgrade.")
 
2058
            " you may be able to use bzr upgrade.")
2148
2059
 
2149
2060
    def __init__(self, branch):
2150
2061
        self.branch = branch
2151
2062
 
2152
 
 
 
2063
        
2153
2064
class TagAlreadyExists(BzrError):
2154
2065
 
2155
2066
    _fmt = "Tag %(tag_name)s already exists."
2156
2067
 
2157
2068
    def __init__(self, tag_name):
2158
2069
        self.tag_name = tag_name
2159
 
 
2160
 
 
2161
 
class UnexpectedSmartServerResponse(BzrError):
2162
 
 
2163
 
    _fmt = "Could not understand response from smart server: %(response_tuple)r"
2164
 
 
2165
 
    def __init__(self, response_tuple):
2166
 
        self.response_tuple = response_tuple
2167
 
 
2168
 
 
2169
 
class ErrorFromSmartServer(BzrError):
2170
 
    """An error was received from a smart server.
2171
 
 
2172
 
    :seealso: UnknownErrorFromSmartServer
2173
 
    """
2174
 
 
2175
 
    _fmt = "Error received from smart server: %(error_tuple)r"
2176
 
 
2177
 
    internal_error = True
2178
 
 
2179
 
    def __init__(self, error_tuple):
2180
 
        self.error_tuple = error_tuple
2181
 
        try:
2182
 
            self.error_verb = error_tuple[0]
2183
 
        except IndexError:
2184
 
            self.error_verb = None
2185
 
        self.error_args = error_tuple[1:]
2186
 
 
2187
 
 
2188
 
class UnknownErrorFromSmartServer(BzrError):
2189
 
    """An ErrorFromSmartServer could not be translated into a typical breezy
2190
 
    error.
2191
 
 
2192
 
    This is distinct from ErrorFromSmartServer so that it is possible to
2193
 
    distinguish between the following two cases:
2194
 
 
2195
 
    - ErrorFromSmartServer was uncaught.  This is logic error in the client
2196
 
      and so should provoke a traceback to the user.
2197
 
    - ErrorFromSmartServer was caught but its error_tuple could not be
2198
 
      translated.  This is probably because the server sent us garbage, and
2199
 
      should not provoke a traceback.
2200
 
    """
2201
 
 
2202
 
    _fmt = "Server sent an unexpected error: %(error_tuple)r"
2203
 
 
2204
 
    internal_error = False
2205
 
 
2206
 
    def __init__(self, error_from_smart_server):
2207
 
        """Constructor.
2208
 
 
2209
 
        :param error_from_smart_server: An ErrorFromSmartServer instance.
2210
 
        """
2211
 
        self.error_from_smart_server = error_from_smart_server
2212
 
        self.error_tuple = error_from_smart_server.error_tuple
2213
 
 
2214
 
 
2215
 
class ContainerError(BzrError):
2216
 
    """Base class of container errors."""
2217
 
 
2218
 
 
2219
 
class UnknownContainerFormatError(ContainerError):
2220
 
 
2221
 
    _fmt = "Unrecognised container format: %(container_format)r"
2222
 
 
2223
 
    def __init__(self, container_format):
2224
 
        self.container_format = container_format
2225
 
 
2226
 
 
2227
 
class UnexpectedEndOfContainerError(ContainerError):
2228
 
 
2229
 
    _fmt = "Unexpected end of container stream"
2230
 
 
2231
 
 
2232
 
class UnknownRecordTypeError(ContainerError):
2233
 
 
2234
 
    _fmt = "Unknown record type: %(record_type)r"
2235
 
 
2236
 
    def __init__(self, record_type):
2237
 
        self.record_type = record_type
2238
 
 
2239
 
 
2240
 
class InvalidRecordError(ContainerError):
2241
 
 
2242
 
    _fmt = "Invalid record: %(reason)s"
2243
 
 
2244
 
    def __init__(self, reason):
2245
 
        self.reason = reason
2246
 
 
2247
 
 
2248
 
class ContainerHasExcessDataError(ContainerError):
2249
 
 
2250
 
    _fmt = "Container has data after end marker: %(excess)r"
2251
 
 
2252
 
    def __init__(self, excess):
2253
 
        self.excess = excess
2254
 
 
2255
 
 
2256
 
class DuplicateRecordNameError(ContainerError):
2257
 
 
2258
 
    _fmt = "Container has multiple records with the same name: %(name)s"
2259
 
 
2260
 
    def __init__(self, name):
2261
 
        self.name = name.decode("utf-8")
2262
 
 
2263
 
 
2264
 
class RepositoryDataStreamError(BzrError):
2265
 
 
2266
 
    _fmt = "Corrupt or incompatible data stream: %(reason)s"
2267
 
 
2268
 
    def __init__(self, reason):
2269
 
        self.reason = reason
2270
 
 
2271
 
 
2272
 
class UncommittedChanges(BzrError):
2273
 
 
2274
 
    _fmt = ('Working tree "%(display_url)s" has uncommitted changes'
2275
 
            ' (See brz status).%(more)s')
2276
 
 
2277
 
    def __init__(self, tree, more=None):
2278
 
        if more is None:
2279
 
            more = ''
2280
 
        else:
2281
 
            more = ' ' + more
2282
 
        import breezy.urlutils as urlutils
2283
 
        user_url = getattr(tree, "user_url", None)
2284
 
        if user_url is None:
2285
 
            display_url = str(tree)
2286
 
        else:
2287
 
            display_url = urlutils.unescape_for_display(user_url, 'ascii')
2288
 
        BzrError.__init__(self, tree=tree, display_url=display_url, more=more)
2289
 
 
2290
 
 
2291
 
class StoringUncommittedNotSupported(BzrError):
2292
 
 
2293
 
    _fmt = ('Branch "%(display_url)s" does not support storing uncommitted'
2294
 
            ' changes.')
2295
 
 
2296
 
    def __init__(self, branch):
2297
 
        import breezy.urlutils as urlutils
2298
 
        user_url = getattr(branch, "user_url", None)
2299
 
        if user_url is None:
2300
 
            display_url = str(branch)
2301
 
        else:
2302
 
            display_url = urlutils.unescape_for_display(user_url, 'ascii')
2303
 
        BzrError.__init__(self, branch=branch, display_url=display_url)
2304
 
 
2305
 
 
2306
 
class ShelvedChanges(UncommittedChanges):
2307
 
 
2308
 
    _fmt = ('Working tree "%(display_url)s" has shelved changes'
2309
 
            ' (See brz shelve --list).%(more)s')
2310
 
 
2311
 
 
2312
 
class UnableCreateSymlink(BzrError):
2313
 
 
2314
 
    _fmt = 'Unable to create symlink %(path_str)son this platform'
2315
 
 
2316
 
    def __init__(self, path=None):
2317
 
        path_str = ''
2318
 
        if path:
2319
 
            try:
2320
 
                path_str = repr(str(path))
2321
 
            except UnicodeEncodeError:
2322
 
                path_str = repr(path)
2323
 
            path_str += ' '
2324
 
        self.path_str = path_str
2325
 
 
2326
 
 
2327
 
class UnableEncodePath(BzrError):
2328
 
 
2329
 
    _fmt = ('Unable to encode %(kind)s path %(path)r in '
2330
 
            'user encoding %(user_encoding)s')
2331
 
 
2332
 
    def __init__(self, path, kind):
2333
 
        from breezy.osutils import get_user_encoding
2334
 
        self.path = path
2335
 
        self.kind = kind
2336
 
        self.user_encoding = get_user_encoding()
2337
 
 
2338
 
 
2339
 
class NoSuchAlias(BzrError):
2340
 
 
2341
 
    _fmt = ('The alias "%(alias_name)s" does not exist.')
2342
 
 
2343
 
    def __init__(self, alias_name):
2344
 
        BzrError.__init__(self, alias_name=alias_name)
2345
 
 
2346
 
 
2347
 
class CannotBindAddress(BzrError):
2348
 
 
2349
 
    _fmt = 'Cannot bind address "%(host)s:%(port)i": %(orig_error)s.'
2350
 
 
2351
 
    def __init__(self, host, port, orig_error):
2352
 
        # nb: in python2.4 socket.error doesn't have a useful repr
2353
 
        BzrError.__init__(self, host=host, port=port,
2354
 
            orig_error=repr(orig_error.args))
2355
 
 
2356
 
 
2357
 
class TipChangeRejected(BzrError):
2358
 
    """A pre_change_branch_tip hook function may raise this to cleanly and
2359
 
    explicitly abort a change to a branch tip.
2360
 
    """
2361
 
 
2362
 
    _fmt = u"Tip change rejected: %(msg)s"
2363
 
 
2364
 
    def __init__(self, msg):
2365
 
        self.msg = msg
2366
 
 
2367
 
 
2368
 
class JailBreak(BzrError):
2369
 
 
2370
 
    _fmt = "An attempt to access a url outside the server jail was made: '%(url)s'."
2371
 
 
2372
 
    def __init__(self, url):
2373
 
        BzrError.__init__(self, url=url)
2374
 
 
2375
 
 
2376
 
class UserAbort(BzrError):
2377
 
 
2378
 
    _fmt = 'The user aborted the operation.'
2379
 
 
2380
 
 
2381
 
class UnresumableWriteGroup(BzrError):
2382
 
 
2383
 
    _fmt = ("Repository %(repository)s cannot resume write group "
2384
 
            "%(write_groups)r: %(reason)s")
2385
 
 
2386
 
    internal_error = True
2387
 
 
2388
 
    def __init__(self, repository, write_groups, reason):
2389
 
        self.repository = repository
2390
 
        self.write_groups = write_groups
2391
 
        self.reason = reason
2392
 
 
2393
 
 
2394
 
class UnsuspendableWriteGroup(BzrError):
2395
 
 
2396
 
    _fmt = ("Repository %(repository)s cannot suspend a write group.")
2397
 
 
2398
 
    internal_error = True
2399
 
 
2400
 
    def __init__(self, repository):
2401
 
        self.repository = repository
2402
 
 
2403
 
 
2404
 
class LossyPushToSameVCS(BzrError):
2405
 
 
2406
 
    _fmt = ("Lossy push not possible between %(source_branch)r and "
2407
 
            "%(target_branch)r that are in the same VCS.")
2408
 
 
2409
 
    internal_error = True
2410
 
 
2411
 
    def __init__(self, source_branch, target_branch):
2412
 
        self.source_branch = source_branch
2413
 
        self.target_branch = target_branch
2414
 
 
2415
 
 
2416
 
class NoRoundtrippingSupport(BzrError):
2417
 
 
2418
 
    _fmt = ("Roundtripping is not supported between %(source_branch)r and "
2419
 
            "%(target_branch)r.")
2420
 
 
2421
 
    internal_error = True
2422
 
 
2423
 
    def __init__(self, source_branch, target_branch):
2424
 
        self.source_branch = source_branch
2425
 
        self.target_branch = target_branch
2426
 
 
2427
 
 
2428
 
class NoColocatedBranchSupport(BzrError):
2429
 
 
2430
 
    _fmt = ("%(controldir)r does not support co-located branches.")
2431
 
 
2432
 
    def __init__(self, controldir):
2433
 
        self.controldir = controldir
2434
 
 
2435
 
 
2436
 
class RecursiveBind(BzrError):
2437
 
 
2438
 
    _fmt = ('Branch "%(branch_url)s" appears to be bound to itself. '
2439
 
        'Please use `brz unbind` to fix.')
2440
 
 
2441
 
    def __init__(self, branch_url):
2442
 
        self.branch_url = branch_url
2443
 
 
2444
 
 
2445
 
class UnsupportedKindChange(BzrError):
2446
 
 
2447
 
    _fmt = ("Kind change from %(from_kind)s to %(to_kind)s for "
2448
 
            "%(path)s not supported by format %(format)r")
2449
 
 
2450
 
    def __init__(self, path, from_kind, to_kind, format):
2451
 
        self.path = path
2452
 
        self.from_kind = from_kind
2453
 
        self.to_kind = to_kind
2454
 
        self.format = format
2455
 
 
2456
 
 
2457
 
class ChangesAlreadyStored(BzrCommandError):
2458
 
 
2459
 
    _fmt = ('Cannot store uncommitted changes because this branch already'
2460
 
            ' stores uncommitted changes.')