/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] bzr.dev 2240

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005, 2006 Canonical
 
1
# Copyright (C) 2005, 2006 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
15
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
 
 
19
 
There are 3 different classes of error:
20
 
 
21
 
 * KeyboardInterrupt, and OSError with EPIPE - the program terminates 
22
 
   with an appropriate short message
23
 
 
24
 
 * User errors, indicating a problem caused by the user such as a bad URL.
25
 
   These are printed in a short form.
26
 
 
27
 
 * Internal unexpected errors, including most Python builtin errors
28
 
   and some raised from inside bzr.  These are printed with a full 
29
 
   traceback and an invitation to report the bug.
30
 
 
31
 
Exceptions are caught at a high level to report errors to the user, and
32
 
might also be caught inside the program.  Therefore it needs to be
33
 
possible to convert them to a meaningful string, and also for them to be
34
 
interrogated by the program.
35
 
 
36
 
Exceptions are defined such that the arguments given to the constructor
37
 
are stored in the object as properties of the same name.  When the
38
 
object is printed as a string, the doc string of the class is used as
39
 
a format string with the property dictionary available to it.
40
 
 
41
 
This means that exceptions can used like this:
42
 
 
43
 
>>> import sys
44
 
>>> try:
45
 
...   raise NotBranchError(path='/foo/bar')
46
 
... except:
47
 
...   print '%s.%s' % (sys.exc_type.__module__, sys.exc_type.__name__)
48
 
...   print sys.exc_value
49
 
...   path = getattr(sys.exc_value, 'path', None)
50
 
...   if path is not None:
51
 
...     print path
52
 
bzrlib.errors.NotBranchError
53
 
Not a branch: /foo/bar
54
 
/foo/bar
55
 
 
56
 
Therefore:
57
 
 
58
 
 * create a new exception class for any class of error that can be
59
 
   usefully distinguished.  If no callers are likely to want to catch
60
 
   one but not another, don't worry about them.
61
 
 
62
 
 * the __str__ method should generate something useful; BzrError provides
63
 
   a good default implementation
64
 
 
65
 
Exception strings should start with a capital letter and should not have a
66
 
final fullstop.
67
18
"""
68
19
 
69
 
from warnings import warn
70
20
 
 
21
from bzrlib import symbol_versioning
71
22
from bzrlib.patches import (PatchSyntax, 
72
23
                            PatchConflict, 
73
24
                            MalformedPatchHeader,
75
26
                            MalformedLine,)
76
27
 
77
28
 
78
 
# based on Scott James Remnant's hct error classes
79
 
 
80
29
# TODO: is there any value in providing the .args field used by standard
81
30
# python exceptions?   A list of values with no names seems less useful 
82
31
# to me.
85
34
# constructed to make sure it will succeed.  But that says nothing about
86
35
# exceptions that are never raised.
87
36
 
88
 
# TODO: Convert all the other error classes here to BzrNewError, and eliminate
89
 
# the old one.
90
 
 
91
 
# TODO: The pattern (from hct) of using classes docstrings as message
92
 
# templates is cute but maybe not such a great idea - perhaps should have a
93
 
# separate static message_template.
 
37
# TODO: selftest assertRaises should probably also check that every error
 
38
# raised can be formatted as a string successfully, and without giving
 
39
# 'unprintable'.
94
40
 
95
41
 
96
42
class BzrError(StandardError):
 
43
    """
 
44
    Base class for errors raised by bzrlib.
 
45
 
 
46
    :cvar internal_error: if true (or absent) this was probably caused by a
 
47
    bzr bug and should be displayed with a traceback; if False this was
 
48
    probably a user or environment error and they don't need the gory details.
 
49
    (That can be overridden by -Derror on the command line.)
 
50
 
 
51
    :cvar _fmt: Format string to display the error; this is expanded
 
52
    by the instance's dict.
 
53
    """
97
54
    
98
 
    is_user_error = True
 
55
    internal_error = False
 
56
 
 
57
    def __init__(self, msg=None, **kwds):
 
58
        """Construct a new BzrError.
 
59
 
 
60
        There are two alternative forms for constructing these objects.
 
61
        Either a preformatted string may be passed, or a set of named
 
62
        arguments can be given.  The first is for generic "user" errors which
 
63
        are not intended to be caught and so do not need a specific subclass.
 
64
        The second case is for use with subclasses that provide a _fmt format
 
65
        string to print the arguments.  
 
66
 
 
67
        Keyword arguments are taken as parameters to the error, which can 
 
68
        be inserted into the format string template.  It's recommended 
 
69
        that subclasses override the __init__ method to require specific 
 
70
        parameters.
 
71
 
 
72
        :param msg: If given, this is the literal complete text for the error,
 
73
        not subject to expansion.
 
74
        """
 
75
        StandardError.__init__(self)
 
76
        if msg is not None:
 
77
            # I was going to deprecate this, but it actually turns out to be
 
78
            # quite handy - mbp 20061103.
 
79
            self._preformatted_string = msg
 
80
        else:
 
81
            self._preformatted_string = None
 
82
            for key, value in kwds.items():
 
83
                setattr(self, key, value)
99
84
 
100
85
    def __str__(self):
101
 
        # XXX: Should we show the exception class in 
102
 
        # exceptions that don't provide their own message?  
103
 
        # maybe it should be done at a higher level
104
 
        ## n = self.__class__.__name__ + ': '
105
 
        n = ''
106
 
        if len(self.args) == 1:
107
 
            return str(self.args[0])
108
 
        elif len(self.args) == 2:
109
 
            # further explanation or suggestions
110
 
            try:
111
 
                return n + '\n  '.join([self.args[0]] + self.args[1])
112
 
            except TypeError:
113
 
                return n + "%r" % self
114
 
        else:
115
 
            return n + `self.args`
 
86
        s = getattr(self, '_preformatted_string', None)
 
87
        if s is not None:
 
88
            # contains a preformatted message; must be cast to plain str
 
89
            return str(s)
 
90
        try:
 
91
            fmt = self._get_format_string()
 
92
            if fmt:
 
93
                s = fmt % self.__dict__
 
94
                # __str__() should always return a 'str' object
 
95
                # never a 'unicode' object.
 
96
                if isinstance(s, unicode):
 
97
                    return s.encode('utf8')
 
98
                return s
 
99
        except (AttributeError, TypeError, NameError, ValueError, KeyError), e:
 
100
            return 'Unprintable exception %s: dict=%r, fmt=%r, error=%s' \
 
101
                % (self.__class__.__name__,
 
102
                   self.__dict__,
 
103
                   getattr(self, '_fmt', None),
 
104
                   str(e))
 
105
 
 
106
    def _get_format_string(self):
 
107
        """Return format string for this exception or None"""
 
108
        fmt = getattr(self, '_fmt', None)
 
109
        if fmt is not None:
 
110
            return fmt
 
111
        fmt = getattr(self, '__doc__', None)
 
112
        if fmt is not None:
 
113
            symbol_versioning.warn("%s uses its docstring as a format, "
 
114
                    "it should use _fmt instead" % self.__class__.__name__,
 
115
                    DeprecationWarning)
 
116
            return fmt
 
117
        return 'Unprintable exception %s: dict=%r, fmt=%r' \
 
118
            % (self.__class__.__name__,
 
119
               self.__dict__,
 
120
               getattr(self, '_fmt', None),
 
121
               )
116
122
 
117
123
 
118
124
class BzrNewError(BzrError):
119
 
    """bzr error"""
 
125
    """Deprecated error base class."""
120
126
    # base classes should override the docstring with their human-
121
127
    # readable explanation
122
128
 
124
130
        # XXX: Use the underlying BzrError to always generate the args attribute
125
131
        # if it doesn't exist.  We can't use super here, because exceptions are
126
132
        # old-style classes in python2.4 (but new in 2.5).  --bmc, 20060426
 
133
        symbol_versioning.warn('BzrNewError was deprecated in bzr 0.13; '
 
134
             'please convert %s to use BzrError instead' 
 
135
             % self.__class__.__name__,
 
136
             DeprecationWarning,
 
137
             stacklevel=2)
127
138
        BzrError.__init__(self, *args)
128
139
        for key, value in kwds.items():
129
140
            setattr(self, key, value)
142
153
                   self.__dict__, str(e))
143
154
 
144
155
 
145
 
class AlreadyBuilding(BzrNewError):
146
 
    """The tree builder is already building a tree."""
147
 
 
148
 
 
149
 
class BzrCheckError(BzrNewError):
150
 
    """Internal check failed: %(message)s"""
151
 
 
152
 
    is_user_error = False
 
156
class AlreadyBuilding(BzrError):
 
157
    
 
158
    _fmt = "The tree builder is already building a tree."
 
159
 
 
160
 
 
161
class BzrCheckError(BzrError):
 
162
    
 
163
    _fmt = "Internal check failed: %(message)s"
 
164
 
 
165
    internal_error = True
153
166
 
154
167
    def __init__(self, message):
155
 
        BzrNewError.__init__(self)
 
168
        BzrError.__init__(self)
156
169
        self.message = message
157
170
 
158
171
 
159
 
class InvalidEntryName(BzrNewError):
160
 
    """Invalid entry name: %(name)s"""
 
172
class InvalidEntryName(BzrError):
 
173
    
 
174
    _fmt = "Invalid entry name: %(name)s"
161
175
 
162
 
    is_user_error = False
 
176
    internal_error = True
163
177
 
164
178
    def __init__(self, name):
165
 
        BzrNewError.__init__(self)
 
179
        BzrError.__init__(self)
166
180
        self.name = name
167
181
 
168
182
 
169
 
class InvalidRevisionNumber(BzrNewError):
170
 
    """Invalid revision number %(revno)d"""
 
183
class InvalidRevisionNumber(BzrError):
 
184
    
 
185
    _fmt = "Invalid revision number %(revno)s"
 
186
 
171
187
    def __init__(self, revno):
172
 
        BzrNewError.__init__(self)
 
188
        BzrError.__init__(self)
173
189
        self.revno = revno
174
190
 
175
191
 
176
 
class InvalidRevisionId(BzrNewError):
177
 
    """Invalid revision-id {%(revision_id)s} in %(branch)s"""
 
192
class InvalidRevisionId(BzrError):
 
193
 
 
194
    _fmt = "Invalid revision-id {%(revision_id)s} in %(branch)s"
178
195
 
179
196
    def __init__(self, revision_id, branch):
180
197
        # branch can be any string or object with __str__ defined
181
 
        BzrNewError.__init__(self)
 
198
        BzrError.__init__(self)
182
199
        self.revision_id = revision_id
183
200
        self.branch = branch
184
201
 
185
 
 
186
 
class InventoryModified(BzrNewError):
187
 
    """The current inventory for the tree %(tree)r has been modified, so a clean inventory cannot be read without data loss."""
188
 
 
189
 
    def __init__(self, tree):
190
 
        BzrNewError.__init__(self)
191
 
        self.tree = tree
192
 
 
193
 
 
194
 
class NoSuchId(BzrNewError):
195
 
    """The file id %(file_id)s is not present in the tree %(tree)s."""
 
202
class ReservedId(BzrError):
 
203
 
 
204
    _fmt = "Reserved revision-id {%(revision_id)s}"
 
205
 
 
206
    def __init__(self, revision_id):
 
207
        self.revision_id = revision_id
 
208
 
 
209
class NoSuchId(BzrError):
 
210
 
 
211
    _fmt = "The file id %(file_id)s is not present in the tree %(tree)s."
196
212
    
197
213
    def __init__(self, tree, file_id):
198
 
        BzrNewError.__init__(self)
 
214
        BzrError.__init__(self)
199
215
        self.file_id = file_id
200
216
        self.tree = tree
201
217
 
202
218
 
203
 
class NoWorkingTree(BzrNewError):
204
 
    """No WorkingTree exists for %(base)s."""
 
219
class InventoryModified(BzrError):
 
220
 
 
221
    _fmt = ("The current inventory for the tree %(tree)r has been modified, "
 
222
            "so a clean inventory cannot be read without data loss.")
 
223
 
 
224
    internal_error = True
 
225
 
 
226
    def __init__(self, tree):
 
227
        self.tree = tree
 
228
 
 
229
 
 
230
class NoWorkingTree(BzrError):
 
231
 
 
232
    _fmt = "No WorkingTree exists for %(base)s."
205
233
    
206
234
    def __init__(self, base):
207
 
        BzrNewError.__init__(self)
 
235
        BzrError.__init__(self)
208
236
        self.base = base
209
237
 
210
238
 
211
 
class NotBuilding(BzrNewError):
212
 
    """Not currently building a tree."""
213
 
 
214
 
 
215
 
class NotLocalUrl(BzrNewError):
216
 
    """%(url)s is not a local path."""
217
 
    
 
239
class NotBuilding(BzrError):
 
240
 
 
241
    _fmt = "Not currently building a tree."
 
242
 
 
243
 
 
244
class NotLocalUrl(BzrError):
 
245
 
 
246
    _fmt = "%(url)s is not a local path."
 
247
 
218
248
    def __init__(self, url):
219
 
        BzrNewError.__init__(self)
220
249
        self.url = url
221
250
 
222
251
 
223
 
class NotWriteLocked(BzrNewError):
224
 
    """%(not_locked)r is not write locked but needs to be."""
225
 
 
226
 
    def __init__(self, not_locked):
227
 
        BzrNewError.__init__(self)
228
 
        self.not_locked = not_locked
229
 
 
230
 
 
231
 
class BzrCommandError(BzrNewError):
 
252
class WorkingTreeAlreadyPopulated(BzrError):
 
253
 
 
254
    _fmt = """Working tree already populated in %(base)s"""
 
255
 
 
256
    internal_error = True
 
257
 
 
258
    def __init__(self, base):
 
259
        self.base = base
 
260
 
 
261
class BzrCommandError(BzrError):
232
262
    """Error from user command"""
233
263
 
234
 
    is_user_error = True
 
264
    internal_error = False
235
265
 
236
266
    # Error from malformed user command; please avoid raising this as a
237
267
    # generic exception not caused by user input.
252
282
        return self.msg
253
283
 
254
284
 
 
285
class NotWriteLocked(BzrError):
 
286
 
 
287
    _fmt = """%(not_locked)r is not write locked but needs to be."""
 
288
 
 
289
    def __init__(self, not_locked):
 
290
        self.not_locked = not_locked
 
291
 
 
292
 
255
293
class BzrOptionError(BzrCommandError):
256
 
    """Error in command line options"""
 
294
 
 
295
    _fmt = "Error in command line options"
 
296
 
 
297
 
 
298
class BadOptionValue(BzrError):
 
299
 
 
300
    _fmt = """Bad value "%(value)s" for option "%(name)s"."""
 
301
 
 
302
    def __init__(self, name, value):
 
303
        BzrError.__init__(self, name=name, value=value)
257
304
 
258
305
    
259
 
class StrictCommitFailed(BzrNewError):
260
 
    """Commit refused because there are unknown files in the tree"""
 
306
class StrictCommitFailed(BzrError):
 
307
 
 
308
    _fmt = "Commit refused because there are unknown files in the tree"
261
309
 
262
310
 
263
311
# XXX: Should be unified with TransportError; they seem to represent the
264
312
# same thing
265
 
class PathError(BzrNewError):
266
 
    """Generic path error: %(path)r%(extra)s)"""
 
313
class PathError(BzrError):
 
314
    
 
315
    _fmt = "Generic path error: %(path)r%(extra)s)"
267
316
 
268
317
    def __init__(self, path, extra=None):
269
 
        BzrNewError.__init__(self)
 
318
        BzrError.__init__(self)
270
319
        self.path = path
271
320
        if extra:
272
321
            self.extra = ': ' + str(extra)
275
324
 
276
325
 
277
326
class NoSuchFile(PathError):
278
 
    """No such file: %(path)r%(extra)s"""
 
327
 
 
328
    _fmt = "No such file: %(path)r%(extra)s"
279
329
 
280
330
 
281
331
class FileExists(PathError):
282
 
    """File exists: %(path)r%(extra)s"""
 
332
 
 
333
    _fmt = "File exists: %(path)r%(extra)s"
283
334
 
284
335
 
285
336
class DirectoryNotEmpty(PathError):
286
 
    """Directory not empty: %(path)r%(extra)s"""
 
337
 
 
338
    _fmt = "Directory not empty: %(path)r%(extra)s"
 
339
 
 
340
 
 
341
class ReadingCompleted(BzrError):
 
342
    
 
343
    _fmt = ("The MediumRequest '%(request)s' has already had finish_reading "
 
344
            "called upon it - the request has been completed and no more "
 
345
            "data may be read.")
 
346
 
 
347
    internal_error = True
 
348
 
 
349
    def __init__(self, request):
 
350
        self.request = request
287
351
 
288
352
 
289
353
class ResourceBusy(PathError):
290
 
    """Device or resource busy: %(path)r%(extra)s"""
 
354
 
 
355
    _fmt = "Device or resource busy: %(path)r%(extra)s"
291
356
 
292
357
 
293
358
class PermissionDenied(PathError):
294
 
    """Permission denied: %(path)r%(extra)s"""
 
359
 
 
360
    _fmt = "Permission denied: %(path)r%(extra)s"
295
361
 
296
362
 
297
363
class InvalidURL(PathError):
298
 
    """Invalid url supplied to transport: %(path)r%(extra)s"""
 
364
 
 
365
    _fmt = "Invalid url supplied to transport: %(path)r%(extra)s"
299
366
 
300
367
 
301
368
class InvalidURLJoin(PathError):
302
 
    """Invalid URL join request: %(args)s%(extra)s"""
 
369
 
 
370
    _fmt = "Invalid URL join request: %(args)s%(extra)s"
303
371
 
304
372
    def __init__(self, msg, base, args):
305
373
        PathError.__init__(self, base, msg)
307
375
 
308
376
 
309
377
class UnsupportedProtocol(PathError):
310
 
    """Unsupported protocol for url "%(path)s"%(extra)s"""
 
378
 
 
379
    _fmt = 'Unsupported protocol for url "%(path)s"%(extra)s'
311
380
 
312
381
    def __init__(self, url, extra):
313
382
        PathError.__init__(self, url, extra=extra)
314
383
 
315
384
 
316
385
class ShortReadvError(PathError):
317
 
    """readv() read %(actual)s bytes rather than %(length)s bytes at %(offset)s for %(path)s%(extra)s"""
318
 
 
319
 
    is_user_error = False
 
386
 
 
387
    _fmt = "readv() read %(actual)s bytes rather than %(length)s bytes at %(offset)s for %(path)s%(extra)s"
 
388
 
 
389
    internal_error = True
320
390
 
321
391
    def __init__(self, path, offset, length, actual, extra=None):
322
392
        PathError.__init__(self, path, extra=extra)
325
395
        self.actual = actual
326
396
 
327
397
 
328
 
class PathNotChild(BzrNewError):
329
 
    """Path %(path)r is not a child of path %(base)r%(extra)s"""
330
 
 
331
 
    is_user_error = False
 
398
class PathNotChild(BzrError):
 
399
 
 
400
    _fmt = "Path %(path)r is not a child of path %(base)r%(extra)s"
 
401
 
 
402
    internal_error = True
332
403
 
333
404
    def __init__(self, path, base, extra=None):
334
 
        BzrNewError.__init__(self)
 
405
        BzrError.__init__(self)
335
406
        self.path = path
336
407
        self.base = base
337
408
        if extra:
341
412
 
342
413
 
343
414
class InvalidNormalization(PathError):
344
 
    """Path %(path)r is not unicode normalized"""
 
415
 
 
416
    _fmt = "Path %(path)r is not unicode normalized"
345
417
 
346
418
 
347
419
# TODO: This is given a URL; we try to unescape it but doing that from inside
348
420
# the exception object is a bit undesirable.
349
421
# TODO: Probably this behavior of should be a common superclass 
350
422
class NotBranchError(PathError):
351
 
    """Not a branch: %(path)s"""
 
423
 
 
424
    _fmt = "Not a branch: %(path)s"
352
425
 
353
426
    def __init__(self, path):
354
427
       import bzrlib.urlutils as urlutils
356
429
 
357
430
 
358
431
class AlreadyBranchError(PathError):
359
 
    """Already a branch: %(path)s."""
 
432
 
 
433
    _fmt = "Already a branch: %(path)s."
360
434
 
361
435
 
362
436
class BranchExistsWithoutWorkingTree(PathError):
363
 
    """Directory contains a branch, but no working tree \
364
 
(use bzr checkout if you wish to build a working tree): %(path)s"""
 
437
 
 
438
    _fmt = "Directory contains a branch, but no working tree \
 
439
(use bzr checkout if you wish to build a working tree): %(path)s"
365
440
 
366
441
 
367
442
class AtomicFileAlreadyClosed(PathError):
368
 
    """'%(function)s' called on an AtomicFile after it was closed: %(path)s"""
 
443
 
 
444
    _fmt = "'%(function)s' called on an AtomicFile after it was closed: %(path)s"
369
445
 
370
446
    def __init__(self, path, function):
371
447
        PathError.__init__(self, path=path, extra=None)
373
449
 
374
450
 
375
451
class InaccessibleParent(PathError):
376
 
    """Parent not accessible given base %(base)s and relative path %(path)s"""
 
452
 
 
453
    _fmt = "Parent not accessible given base %(base)s and relative path %(path)s"
377
454
 
378
455
    def __init__(self, path, base):
379
456
        PathError.__init__(self, path)
380
457
        self.base = base
381
458
 
382
459
 
383
 
class NoRepositoryPresent(BzrNewError):
384
 
    """No repository present: %(path)r"""
 
460
class NoRepositoryPresent(BzrError):
 
461
 
 
462
    _fmt = "No repository present: %(path)r"
385
463
    def __init__(self, bzrdir):
386
 
        BzrNewError.__init__(self)
 
464
        BzrError.__init__(self)
387
465
        self.path = bzrdir.transport.clone('..').base
388
466
 
389
467
 
390
 
class FileInWrongBranch(BzrNewError):
391
 
    """File %(path)s in not in branch %(branch_base)s."""
 
468
class FileInWrongBranch(BzrError):
 
469
 
 
470
    _fmt = "File %(path)s in not in branch %(branch_base)s."
392
471
 
393
472
    def __init__(self, branch, path):
394
 
        BzrNewError.__init__(self)
 
473
        BzrError.__init__(self)
395
474
        self.branch = branch
396
475
        self.branch_base = branch.base
397
476
        self.path = path
398
477
 
399
478
 
400
 
class UnsupportedFormatError(BzrNewError):
401
 
    """Unsupported branch format: %(format)s"""
402
 
 
403
 
 
404
 
class UnknownFormatError(BzrNewError):
405
 
    """Unknown branch format: %(format)r"""
406
 
 
407
 
 
408
 
class IncompatibleFormat(BzrNewError):
409
 
    """Format %(format)s is not compatible with .bzr version %(bzrdir)s."""
 
479
class UnsupportedFormatError(BzrError):
 
480
    
 
481
    _fmt = "Unsupported branch format: %(format)s"
 
482
 
 
483
 
 
484
class UnknownFormatError(BzrError):
 
485
    
 
486
    _fmt = "Unknown branch format: %(format)r"
 
487
 
 
488
 
 
489
class IncompatibleFormat(BzrError):
 
490
    
 
491
    _fmt = "Format %(format)s is not compatible with .bzr version %(bzrdir)s."
410
492
 
411
493
    def __init__(self, format, bzrdir_format):
412
 
        BzrNewError.__init__(self)
 
494
        BzrError.__init__(self)
413
495
        self.format = format
414
496
        self.bzrdir = bzrdir_format
415
497
 
416
498
 
417
 
class IncompatibleRevision(BzrNewError):
418
 
    """Revision is not compatible with %(repo_format)s"""
 
499
class IncompatibleRevision(BzrError):
 
500
    
 
501
    _fmt = "Revision is not compatible with %(repo_format)s"
419
502
 
420
503
    def __init__(self, repo_format):
421
 
        BzrNewError.__init__(self)
 
504
        BzrError.__init__(self)
422
505
        self.repo_format = repo_format
423
506
 
424
507
 
425
 
class NotVersionedError(BzrNewError):
426
 
    """%(path)s is not versioned"""
 
508
class NotVersionedError(BzrError):
 
509
 
 
510
    _fmt = "%(path)s is not versioned"
 
511
 
427
512
    def __init__(self, path):
428
 
        BzrNewError.__init__(self)
 
513
        BzrError.__init__(self)
429
514
        self.path = path
430
515
 
431
516
 
432
 
class PathsNotVersionedError(BzrNewError):
 
517
class PathsNotVersionedError(BzrError):
433
518
    # used when reporting several paths are not versioned
434
 
    """Path(s) are not versioned: %(paths_as_string)s"""
 
519
 
 
520
    _fmt = "Path(s) are not versioned: %(paths_as_string)s"
435
521
 
436
522
    def __init__(self, paths):
437
523
        from bzrlib.osutils import quotefn
438
 
        BzrNewError.__init__(self)
 
524
        BzrError.__init__(self)
439
525
        self.paths = paths
440
526
        self.paths_as_string = ' '.join([quotefn(p) for p in paths])
441
527
 
442
528
 
443
 
class PathsDoNotExist(BzrNewError):
444
 
    """Path(s) do not exist: %(paths_as_string)s"""
 
529
class PathsDoNotExist(BzrError):
 
530
 
 
531
    _fmt = "Path(s) do not exist: %(paths_as_string)s"
445
532
 
446
533
    # used when reporting that paths are neither versioned nor in the working
447
534
    # tree
449
536
    def __init__(self, paths):
450
537
        # circular import
451
538
        from bzrlib.osutils import quotefn
452
 
        BzrNewError.__init__(self)
 
539
        BzrError.__init__(self)
453
540
        self.paths = paths
454
541
        self.paths_as_string = ' '.join([quotefn(p) for p in paths])
455
542
 
456
543
 
457
 
class BadFileKindError(BzrNewError):
458
 
    """Cannot operate on %(filename)s of unsupported kind %(kind)s"""
459
 
 
460
 
 
461
 
class ForbiddenControlFileError(BzrNewError):
462
 
    """Cannot operate on %(filename)s because it is a control file"""
463
 
 
464
 
 
465
 
class LockError(BzrNewError):
466
 
    """Lock error: %(message)s"""
 
544
class BadFileKindError(BzrError):
 
545
 
 
546
    _fmt = "Cannot operate on %(filename)s of unsupported kind %(kind)s"
 
547
 
 
548
 
 
549
class ForbiddenControlFileError(BzrError):
 
550
 
 
551
    _fmt = "Cannot operate on %(filename)s because it is a control file"
 
552
 
 
553
 
 
554
class LockError(BzrError):
 
555
 
 
556
    _fmt = "Lock error: %(message)s"
 
557
 
 
558
    internal_error = True
 
559
 
467
560
    # All exceptions from the lock/unlock functions should be from
468
561
    # this exception class.  They will be translated as necessary. The
469
562
    # original exception is available as e.original_error
474
567
 
475
568
 
476
569
class CommitNotPossible(LockError):
477
 
    """A commit was attempted but we do not have a write lock open."""
 
570
 
 
571
    _fmt = "A commit was attempted but we do not have a write lock open."
 
572
 
478
573
    def __init__(self):
479
574
        pass
480
575
 
481
576
 
482
577
class AlreadyCommitted(LockError):
483
 
    """A rollback was requested, but is not able to be accomplished."""
 
578
 
 
579
    _fmt = "A rollback was requested, but is not able to be accomplished."
 
580
 
484
581
    def __init__(self):
485
582
        pass
486
583
 
487
584
 
488
585
class ReadOnlyError(LockError):
489
 
    """A write attempt was made in a read only transaction on %(obj)s"""
 
586
 
 
587
    _fmt = "A write attempt was made in a read only transaction on %(obj)s"
 
588
 
490
589
    def __init__(self, obj):
491
590
        self.obj = obj
492
591
 
493
592
 
494
 
class OutSideTransaction(BzrNewError):
495
 
    """A transaction related operation was attempted after the transaction finished."""
 
593
class OutSideTransaction(BzrError):
 
594
 
 
595
    _fmt = "A transaction related operation was attempted after the transaction finished."
496
596
 
497
597
 
498
598
class ObjectNotLocked(LockError):
499
 
    """%(obj)r is not locked"""
500
599
 
501
 
    is_user_error = False
 
600
    _fmt = "%(obj)r is not locked"
502
601
 
503
602
    # this can indicate that any particular object is not locked; see also
504
603
    # LockNotHeld which means that a particular *lock* object is not held by
508
607
 
509
608
 
510
609
class ReadOnlyObjectDirtiedError(ReadOnlyError):
511
 
    """Cannot change object %(obj)r in read only transaction"""
 
610
 
 
611
    _fmt = "Cannot change object %(obj)r in read only transaction"
 
612
 
512
613
    def __init__(self, obj):
513
614
        self.obj = obj
514
615
 
515
616
 
516
617
class UnlockableTransport(LockError):
517
 
    """Cannot lock: transport is read only: %(transport)s"""
 
618
 
 
619
    _fmt = "Cannot lock: transport is read only: %(transport)s"
 
620
 
518
621
    def __init__(self, transport):
519
622
        self.transport = transport
520
623
 
521
624
 
522
625
class LockContention(LockError):
523
 
    """Could not acquire lock %(lock)s"""
524
 
    # TODO: show full url for lock, combining the transport and relative bits?
 
626
 
 
627
    _fmt = "Could not acquire lock %(lock)s"
 
628
    # TODO: show full url for lock, combining the transport and relative
 
629
    # bits?
 
630
 
 
631
    internal_error = False
 
632
    
525
633
    def __init__(self, lock):
526
634
        self.lock = lock
527
635
 
528
636
 
529
637
class LockBroken(LockError):
530
 
    """Lock was broken while still open: %(lock)s - check storage consistency!"""
 
638
 
 
639
    _fmt = "Lock was broken while still open: %(lock)s - check storage consistency!"
 
640
 
 
641
    internal_error = False
 
642
 
531
643
    def __init__(self, lock):
532
644
        self.lock = lock
533
645
 
534
646
 
535
647
class LockBreakMismatch(LockError):
536
 
    """Lock was released and re-acquired before being broken: %(lock)s: held by %(holder)r, wanted to break %(target)r"""
 
648
 
 
649
    _fmt = "Lock was released and re-acquired before being broken: %(lock)s: held by %(holder)r, wanted to break %(target)r"
 
650
 
 
651
    internal_error = False
 
652
 
537
653
    def __init__(self, lock, holder, target):
538
654
        self.lock = lock
539
655
        self.holder = holder
541
657
 
542
658
 
543
659
class LockNotHeld(LockError):
544
 
    """Lock not held: %(lock)s"""
 
660
 
 
661
    _fmt = "Lock not held: %(lock)s"
 
662
 
 
663
    internal_error = False
 
664
 
545
665
    def __init__(self, lock):
546
666
        self.lock = lock
547
667
 
548
668
 
549
 
class PointlessCommit(BzrNewError):
550
 
    """No changes to commit"""
551
 
 
552
 
 
553
 
class UpgradeReadonly(BzrNewError):
554
 
    """Upgrade URL cannot work with readonly URL's."""
555
 
 
556
 
 
557
 
class UpToDateFormat(BzrNewError):
558
 
    """The branch format %(format)s is already at the most recent format."""
 
669
class PointlessCommit(BzrError):
 
670
 
 
671
    _fmt = "No changes to commit"
 
672
 
 
673
 
 
674
class UpgradeReadonly(BzrError):
 
675
 
 
676
    _fmt = "Upgrade URL cannot work with readonly URLs."
 
677
 
 
678
 
 
679
class UpToDateFormat(BzrError):
 
680
 
 
681
    _fmt = "The branch format %(format)s is already at the most recent format."
559
682
 
560
683
    def __init__(self, format):
561
 
        BzrNewError.__init__(self)
 
684
        BzrError.__init__(self)
562
685
        self.format = format
563
686
 
564
687
 
565
688
class StrictCommitFailed(Exception):
566
 
    """Commit refused because there are unknowns in the tree."""
567
 
 
568
 
 
569
 
class NoSuchRevision(BzrNewError):
570
 
    """Branch %(branch)s has no revision %(revision)s"""
571
 
 
572
 
    is_user_error = False
 
689
 
 
690
    _fmt = "Commit refused because there are unknowns in the tree."
 
691
 
 
692
 
 
693
class NoSuchRevision(BzrError):
 
694
 
 
695
    _fmt = "Branch %(branch)s has no revision %(revision)s"
 
696
 
 
697
    internal_error = True
573
698
 
574
699
    def __init__(self, branch, revision):
575
 
        BzrNewError.__init__(self, branch=branch, revision=revision)
 
700
        BzrError.__init__(self, branch=branch, revision=revision)
 
701
 
 
702
 
 
703
class NoSuchRevisionSpec(BzrError):
 
704
 
 
705
    _fmt = "No namespace registered for string: %(spec)r"
 
706
 
 
707
    def __init__(self, spec):
 
708
        BzrError.__init__(self, spec=spec)
576
709
 
577
710
 
578
711
class NoSuchRevisionInTree(NoSuchRevision):
579
 
    """The revision id %(revision_id)s is not present in the tree %(tree)s."""
 
712
    """When using Tree.revision_tree, and the revision is not accessible."""
 
713
    
 
714
    _fmt = "The revision id %(revision_id)s is not present in the tree %(tree)s."
580
715
 
581
716
    def __init__(self, tree, revision_id):
582
 
        BzrNewError.__init__(self)
 
717
        BzrError.__init__(self)
583
718
        self.tree = tree
584
719
        self.revision_id = revision_id
585
720
 
586
721
 
587
 
class NoSuchRevisionSpec(BzrNewError):
588
 
    """No namespace registered for string: %(spec)r"""
589
 
 
590
 
    def __init__(self, spec):
591
 
        BzrNewError.__init__(self, spec=spec)
592
 
 
593
 
 
594
 
class InvalidRevisionSpec(BzrNewError):
595
 
    """Requested revision: '%(spec)s' does not exist in branch:
596
 
%(branch)s%(extra)s"""
 
722
class InvalidRevisionSpec(BzrError):
 
723
 
 
724
    _fmt = "Requested revision: %(spec)r does not exist in branch: %(branch)s%(extra)s"
597
725
 
598
726
    def __init__(self, spec, branch, extra=None):
599
 
        BzrNewError.__init__(self, branch=branch, spec=spec)
 
727
        BzrError.__init__(self, branch=branch, spec=spec)
600
728
        if extra:
601
729
            self.extra = '\n' + str(extra)
602
730
        else:
604
732
 
605
733
 
606
734
class HistoryMissing(BzrError):
607
 
    def __init__(self, branch, object_type, object_id):
608
 
        self.branch = branch
609
 
        BzrError.__init__(self,
610
 
                          '%s is missing %s {%s}'
611
 
                          % (branch, object_type, object_id))
612
 
 
613
 
 
614
 
class DivergedBranches(BzrNewError):
615
 
    "These branches have diverged.  Use the merge command to reconcile them."""
616
 
 
617
 
    is_user_error = True
 
735
 
 
736
    _fmt = "%(branch)s is missing %(object_type)s {%(object_id)s}"
 
737
 
 
738
 
 
739
class DivergedBranches(BzrError):
 
740
    
 
741
    _fmt = "These branches have diverged.  Use the merge command to reconcile them."""
 
742
 
 
743
    internal_error = False
618
744
 
619
745
    def __init__(self, branch1, branch2):
620
746
        self.branch1 = branch1
621
747
        self.branch2 = branch2
622
748
 
623
749
 
624
 
class UnrelatedBranches(BzrNewError):
625
 
    "Branches have no common ancestor, and no merge base revision was specified."
626
 
 
627
 
    is_user_error = True
628
 
 
629
 
 
630
 
class NoCommonAncestor(BzrNewError):
631
 
    "Revisions have no common ancestor: %(revision_a)s %(revision_b)s"
 
750
class UnrelatedBranches(BzrError):
 
751
 
 
752
    _fmt = "Branches have no common ancestor, and no merge base revision was specified."
 
753
 
 
754
    internal_error = False
 
755
 
 
756
 
 
757
class NoCommonAncestor(BzrError):
 
758
    
 
759
    _fmt = "Revisions have no common ancestor: %(revision_a)s %(revision_b)s"
632
760
 
633
761
    def __init__(self, revision_a, revision_b):
634
762
        self.revision_a = revision_a
636
764
 
637
765
 
638
766
class NoCommonRoot(BzrError):
 
767
 
 
768
    _fmt = "Revisions are not derived from the same root: " \
 
769
           "%(revision_a)s %(revision_b)s."
 
770
 
639
771
    def __init__(self, revision_a, revision_b):
640
 
        msg = "Revisions are not derived from the same root: %s %s." \
641
 
            % (revision_a, revision_b) 
642
 
        BzrError.__init__(self, msg)
643
 
 
 
772
        BzrError.__init__(self, revision_a=revision_a, revision_b=revision_b)
644
773
 
645
774
 
646
775
class NotAncestor(BzrError):
 
776
 
 
777
    _fmt = "Revision %(rev_id)s is not an ancestor of %(not_ancestor_id)s"
 
778
 
647
779
    def __init__(self, rev_id, not_ancestor_id):
648
 
        msg = "Revision %s is not an ancestor of %s" % (not_ancestor_id, 
649
 
                                                        rev_id)
650
 
        BzrError.__init__(self, msg)
651
 
        self.rev_id = rev_id
652
 
        self.not_ancestor_id = not_ancestor_id
 
780
        BzrError.__init__(self, rev_id=rev_id,
 
781
            not_ancestor_id=not_ancestor_id)
653
782
 
654
783
 
655
784
class InstallFailed(BzrError):
 
785
 
656
786
    def __init__(self, revisions):
657
 
        msg = "Could not install revisions:\n%s" % " ,".join(revisions)
 
787
        revision_str = ", ".join(str(r) for r in revisions)
 
788
        msg = "Could not install revisions:\n%s" % revision_str
658
789
        BzrError.__init__(self, msg)
659
790
        self.revisions = revisions
660
791
 
661
792
 
662
793
class AmbiguousBase(BzrError):
 
794
 
663
795
    def __init__(self, bases):
664
796
        warn("BzrError AmbiguousBase has been deprecated as of bzrlib 0.8.",
665
797
                DeprecationWarning)
669
801
        self.bases = bases
670
802
 
671
803
 
672
 
class NoCommits(BzrNewError):
673
 
    """Branch %(branch)s has no commits."""
 
804
class NoCommits(BzrError):
 
805
 
 
806
    _fmt = "Branch %(branch)s has no commits."
674
807
 
675
808
    def __init__(self, branch):
676
 
        BzrNewError.__init__(self, branch=branch)
 
809
        BzrError.__init__(self, branch=branch)
677
810
 
678
811
 
679
812
class UnlistableStore(BzrError):
 
813
 
680
814
    def __init__(self, store):
681
815
        BzrError.__init__(self, "Store %s is not listable" % store)
682
816
 
683
817
 
684
818
 
685
819
class UnlistableBranch(BzrError):
 
820
 
686
821
    def __init__(self, br):
687
822
        BzrError.__init__(self, "Stores for branch %s are not listable" % br)
688
823
 
689
824
 
690
 
class BoundBranchOutOfDate(BzrNewError):
691
 
    """Bound branch %(branch)s is out of date with master branch %(master)s."""
 
825
class BoundBranchOutOfDate(BzrError):
 
826
 
 
827
    _fmt = "Bound branch %(branch)s is out of date with master branch %(master)s."
 
828
 
692
829
    def __init__(self, branch, master):
693
 
        BzrNewError.__init__(self)
 
830
        BzrError.__init__(self)
694
831
        self.branch = branch
695
832
        self.master = master
696
833
 
697
834
        
698
 
class CommitToDoubleBoundBranch(BzrNewError):
699
 
    """Cannot commit to branch %(branch)s. It is bound to %(master)s, which is bound to %(remote)s."""
 
835
class CommitToDoubleBoundBranch(BzrError):
 
836
 
 
837
    _fmt = "Cannot commit to branch %(branch)s. It is bound to %(master)s, which is bound to %(remote)s."
 
838
 
700
839
    def __init__(self, branch, master, remote):
701
 
        BzrNewError.__init__(self)
 
840
        BzrError.__init__(self)
702
841
        self.branch = branch
703
842
        self.master = master
704
843
        self.remote = remote
705
844
 
706
845
 
707
 
class OverwriteBoundBranch(BzrNewError):
708
 
    """Cannot pull --overwrite to a branch which is bound %(branch)s"""
 
846
class OverwriteBoundBranch(BzrError):
 
847
 
 
848
    _fmt = "Cannot pull --overwrite to a branch which is bound %(branch)s"
 
849
 
709
850
    def __init__(self, branch):
710
 
        BzrNewError.__init__(self)
 
851
        BzrError.__init__(self)
711
852
        self.branch = branch
712
853
 
713
854
 
714
 
class BoundBranchConnectionFailure(BzrNewError):
715
 
    """Unable to connect to target of bound branch %(branch)s => %(target)s: %(error)s"""
 
855
class BoundBranchConnectionFailure(BzrError):
 
856
 
 
857
    _fmt = "Unable to connect to target of bound branch %(branch)s => %(target)s: %(error)s"
 
858
 
716
859
    def __init__(self, branch, target, error):
717
 
        BzrNewError.__init__(self)
 
860
        BzrError.__init__(self)
718
861
        self.branch = branch
719
862
        self.target = target
720
863
        self.error = error
721
864
 
722
865
 
723
 
class WeaveError(BzrNewError):
724
 
    """Error in processing weave: %(message)s"""
 
866
class WeaveError(BzrError):
 
867
 
 
868
    _fmt = "Error in processing weave: %(message)s"
725
869
 
726
870
    def __init__(self, message=None):
727
 
        BzrNewError.__init__(self)
 
871
        BzrError.__init__(self)
728
872
        self.message = message
729
873
 
730
874
 
731
875
class WeaveRevisionAlreadyPresent(WeaveError):
732
 
    """Revision {%(revision_id)s} already present in %(weave)s"""
 
876
 
 
877
    _fmt = "Revision {%(revision_id)s} already present in %(weave)s"
 
878
 
733
879
    def __init__(self, revision_id, weave):
734
880
 
735
881
        WeaveError.__init__(self)
738
884
 
739
885
 
740
886
class WeaveRevisionNotPresent(WeaveError):
741
 
    """Revision {%(revision_id)s} not present in %(weave)s"""
 
887
 
 
888
    _fmt = "Revision {%(revision_id)s} not present in %(weave)s"
742
889
 
743
890
    def __init__(self, revision_id, weave):
744
891
        WeaveError.__init__(self)
747
894
 
748
895
 
749
896
class WeaveFormatError(WeaveError):
750
 
    """Weave invariant violated: %(what)s"""
 
897
 
 
898
    _fmt = "Weave invariant violated: %(what)s"
751
899
 
752
900
    def __init__(self, what):
753
901
        WeaveError.__init__(self)
755
903
 
756
904
 
757
905
class WeaveParentMismatch(WeaveError):
758
 
    """Parents are mismatched between two revisions."""
 
906
 
 
907
    _fmt = "Parents are mismatched between two revisions."
759
908
    
760
909
 
761
910
class WeaveInvalidChecksum(WeaveError):
762
 
    """Text did not match it's checksum: %(message)s"""
763
 
 
764
 
 
765
 
class WeaveTextDiffers(WeaveError):
766
 
    """Weaves differ on text content. Revision: {%(revision_id)s}, %(weave_a)s, %(weave_b)s"""
767
 
 
768
 
    def __init__(self, revision_id, weave_a, weave_b):
769
 
        WeaveError.__init__(self)
770
 
        self.revision_id = revision_id
771
 
        self.weave_a = weave_a
772
 
        self.weave_b = weave_b
773
 
 
774
 
 
775
 
class WeaveTextDiffers(WeaveError):
776
 
    """Weaves differ on text content. Revision: {%(revision_id)s}, %(weave_a)s, %(weave_b)s"""
777
 
 
778
 
    def __init__(self, revision_id, weave_a, weave_b):
779
 
        WeaveError.__init__(self)
780
 
        self.revision_id = revision_id
781
 
        self.weave_a = weave_a
782
 
        self.weave_b = weave_b
783
 
 
784
 
 
785
 
class VersionedFileError(BzrNewError):
786
 
    """Versioned file error."""
 
911
 
 
912
    _fmt = "Text did not match it's checksum: %(message)s"
 
913
 
 
914
 
 
915
class WeaveTextDiffers(WeaveError):
 
916
 
 
917
    _fmt = "Weaves differ on text content. Revision: {%(revision_id)s}, %(weave_a)s, %(weave_b)s"
 
918
 
 
919
    def __init__(self, revision_id, weave_a, weave_b):
 
920
        WeaveError.__init__(self)
 
921
        self.revision_id = revision_id
 
922
        self.weave_a = weave_a
 
923
        self.weave_b = weave_b
 
924
 
 
925
 
 
926
class WeaveTextDiffers(WeaveError):
 
927
 
 
928
    _fmt = "Weaves differ on text content. Revision: {%(revision_id)s}, %(weave_a)s, %(weave_b)s"
 
929
 
 
930
    def __init__(self, revision_id, weave_a, weave_b):
 
931
        WeaveError.__init__(self)
 
932
        self.revision_id = revision_id
 
933
        self.weave_a = weave_a
 
934
        self.weave_b = weave_b
 
935
 
 
936
 
 
937
class VersionedFileError(BzrError):
 
938
    
 
939
    _fmt = "Versioned file error"
787
940
 
788
941
 
789
942
class RevisionNotPresent(VersionedFileError):
790
 
    """Revision {%(revision_id)s} not present in %(file_id)s."""
 
943
    
 
944
    _fmt = "Revision {%(revision_id)s} not present in %(file_id)s."
791
945
 
792
946
    def __init__(self, revision_id, file_id):
793
947
        VersionedFileError.__init__(self)
796
950
 
797
951
 
798
952
class RevisionAlreadyPresent(VersionedFileError):
799
 
    """Revision {%(revision_id)s} already present in %(file_id)s."""
 
953
    
 
954
    _fmt = "Revision {%(revision_id)s} already present in %(file_id)s."
800
955
 
801
956
    def __init__(self, revision_id, file_id):
802
957
        VersionedFileError.__init__(self)
804
959
        self.file_id = file_id
805
960
 
806
961
 
807
 
class KnitError(BzrNewError):
808
 
    """Knit error"""
 
962
class KnitError(BzrError):
 
963
    
 
964
    _fmt = "Knit error"
 
965
 
 
966
    internal_error = True
809
967
 
810
968
 
811
969
class KnitHeaderError(KnitError):
812
 
    """Knit header error: %(badline)r unexpected"""
813
 
 
814
 
    def __init__(self, badline):
 
970
 
 
971
    _fmt = "Knit header error: %(badline)r unexpected for file %(filename)s"
 
972
 
 
973
    def __init__(self, badline, filename):
815
974
        KnitError.__init__(self)
816
975
        self.badline = badline
 
976
        self.filename = filename
817
977
 
818
978
 
819
979
class KnitCorrupt(KnitError):
820
 
    """Knit %(filename)s corrupt: %(how)s"""
 
980
 
 
981
    _fmt = "Knit %(filename)s corrupt: %(how)s"
821
982
 
822
983
    def __init__(self, filename, how):
823
984
        KnitError.__init__(self)
825
986
        self.how = how
826
987
 
827
988
 
828
 
class NoSuchExportFormat(BzrNewError):
829
 
    """Export format %(format)r not supported"""
 
989
class KnitIndexUnknownMethod(KnitError):
 
990
    """Raised when we don't understand the storage method.
 
991
 
 
992
    Currently only 'fulltext' and 'line-delta' are supported.
 
993
    """
 
994
    
 
995
    _fmt = ("Knit index %(filename)s does not have a known method"
 
996
            " in options: %(options)r")
 
997
 
 
998
    def __init__(self, filename, options):
 
999
        KnitError.__init__(self)
 
1000
        self.filename = filename
 
1001
        self.options = options
 
1002
 
 
1003
 
 
1004
class NoSuchExportFormat(BzrError):
 
1005
    
 
1006
    _fmt = "Export format %(format)r not supported"
 
1007
 
830
1008
    def __init__(self, format):
831
 
        BzrNewError.__init__(self)
 
1009
        BzrError.__init__(self)
832
1010
        self.format = format
833
1011
 
834
1012
 
835
 
class TransportError(BzrNewError):
836
 
    """Transport error: %(msg)s %(orig_error)s"""
 
1013
class TransportError(BzrError):
 
1014
    
 
1015
    _fmt = "Transport error: %(msg)s %(orig_error)s"
837
1016
 
838
1017
    def __init__(self, msg=None, orig_error=None):
839
1018
        if msg is None and orig_error is not None:
844
1023
            msg =  ''
845
1024
        self.msg = msg
846
1025
        self.orig_error = orig_error
847
 
        BzrNewError.__init__(self)
 
1026
        BzrError.__init__(self)
 
1027
 
 
1028
 
 
1029
class TooManyConcurrentRequests(BzrError):
 
1030
 
 
1031
    _fmt = ("The medium '%(medium)s' has reached its concurrent request limit. "
 
1032
            "Be sure to finish_writing and finish_reading on the "
 
1033
            "current request that is open.")
 
1034
 
 
1035
    internal_error = True
 
1036
 
 
1037
    def __init__(self, medium):
 
1038
        self.medium = medium
848
1039
 
849
1040
 
850
1041
class SmartProtocolError(TransportError):
851
 
    """Generic bzr smart protocol error: %(details)s"""
 
1042
 
 
1043
    _fmt = "Generic bzr smart protocol error: %(details)s"
852
1044
 
853
1045
    def __init__(self, details):
854
1046
        self.details = details
856
1048
 
857
1049
# A set of semi-meaningful errors which can be thrown
858
1050
class TransportNotPossible(TransportError):
859
 
    """Transport operation not possible: %(msg)s %(orig_error)s"""
 
1051
 
 
1052
    _fmt = "Transport operation not possible: %(msg)s %(orig_error)s"
860
1053
 
861
1054
 
862
1055
class ConnectionError(TransportError):
863
 
    """Connection error: %(msg)s %(orig_error)s"""
 
1056
 
 
1057
    _fmt = "Connection error: %(msg)s %(orig_error)s"
 
1058
 
 
1059
 
 
1060
class SocketConnectionError(ConnectionError):
 
1061
 
 
1062
    _fmt = "%(msg)s %(host)s%(port)s%(orig_error)s"
 
1063
 
 
1064
    def __init__(self, host, port=None, msg=None, orig_error=None):
 
1065
        if msg is None:
 
1066
            msg = 'Failed to connect to'
 
1067
        if orig_error is None:
 
1068
            orig_error = ''
 
1069
        else:
 
1070
            orig_error = '; ' + str(orig_error)
 
1071
        ConnectionError.__init__(self, msg=msg, orig_error=orig_error)
 
1072
        self.host = host
 
1073
        if port is None:
 
1074
            self.port = ''
 
1075
        else:
 
1076
            self.port = ':%s' % port
864
1077
 
865
1078
 
866
1079
class ConnectionReset(TransportError):
867
 
    """Connection closed: %(msg)s %(orig_error)s"""
 
1080
 
 
1081
    _fmt = "Connection closed: %(msg)s %(orig_error)s"
868
1082
 
869
1083
 
870
1084
class InvalidRange(TransportError):
871
 
    """Invalid range access in %(path)s at %(offset)s."""
 
1085
 
 
1086
    _fmt = "Invalid range access in %(path)s at %(offset)s."
872
1087
    
873
1088
    def __init__(self, path, offset):
874
1089
        TransportError.__init__(self, ("Invalid range access in %s at %d"
878
1093
 
879
1094
 
880
1095
class InvalidHttpResponse(TransportError):
881
 
    """Invalid http response for %(path)s: %(msg)s"""
 
1096
 
 
1097
    _fmt = "Invalid http response for %(path)s: %(msg)s"
882
1098
 
883
1099
    def __init__(self, path, msg, orig_error=None):
884
1100
        self.path = path
886
1102
 
887
1103
 
888
1104
class InvalidHttpRange(InvalidHttpResponse):
889
 
    """Invalid http range "%(range)s" for %(path)s: %(msg)s"""
 
1105
 
 
1106
    _fmt = "Invalid http range %(range)r for %(path)s: %(msg)s"
890
1107
    
891
1108
    def __init__(self, path, range, msg):
892
1109
        self.range = range
894
1111
 
895
1112
 
896
1113
class InvalidHttpContentType(InvalidHttpResponse):
897
 
    """Invalid http Content-type "%(ctype)s" for %(path)s: %(msg)s"""
 
1114
 
 
1115
    _fmt = 'Invalid http Content-type "%(ctype)s" for %(path)s: %(msg)s'
898
1116
    
899
1117
    def __init__(self, path, ctype, msg):
900
1118
        self.ctype = ctype
902
1120
 
903
1121
 
904
1122
class ConflictsInTree(BzrError):
905
 
    def __init__(self):
906
 
        BzrError.__init__(self, "Working tree has conflicts.")
 
1123
 
 
1124
    _fmt = "Working tree has conflicts."
907
1125
 
908
1126
 
909
1127
class ParseConfigError(BzrError):
 
1128
 
910
1129
    def __init__(self, errors, filename):
911
1130
        if filename is None:
912
1131
            filename = ""
915
1134
        BzrError.__init__(self, message)
916
1135
 
917
1136
 
918
 
class NoEmailInUsername(BzrNewError):
919
 
    """%(username)r does not seem to contain a reasonable email address"""
 
1137
class NoEmailInUsername(BzrError):
 
1138
 
 
1139
    _fmt = "%(username)r does not seem to contain a reasonable email address"
920
1140
 
921
1141
    def __init__(self, username):
922
 
        BzrNewError.__init__(self)
 
1142
        BzrError.__init__(self)
923
1143
        self.username = username
924
1144
 
925
1145
 
926
1146
class SigningFailed(BzrError):
 
1147
 
 
1148
    _fmt = "Failed to gpg sign data with command %(command_line)r"
 
1149
 
927
1150
    def __init__(self, command_line):
928
 
        BzrError.__init__(self, "Failed to gpg sign data with command '%s'"
929
 
                               % command_line)
 
1151
        BzrError.__init__(self, command_line=command_line)
930
1152
 
931
1153
 
932
1154
class WorkingTreeNotRevision(BzrError):
 
1155
 
 
1156
    _fmt = ("The working tree for %(basedir)s has changed since" 
 
1157
            " the last commit, but weave merge requires that it be"
 
1158
            " unchanged")
 
1159
 
933
1160
    def __init__(self, tree):
934
 
        BzrError.__init__(self, "The working tree for %s has changed since"
935
 
                          " last commit, but weave merge requires that it be"
936
 
                          " unchanged." % tree.basedir)
937
 
 
938
 
 
939
 
class CantReprocessAndShowBase(BzrNewError):
940
 
    """Can't reprocess and show base.
941
 
Reprocessing obscures relationship of conflicting lines to base."""
942
 
 
943
 
 
944
 
class GraphCycleError(BzrNewError):
945
 
    """Cycle in graph %(graph)r"""
 
1161
        BzrError.__init__(self, basedir=tree.basedir)
 
1162
 
 
1163
 
 
1164
class CantReprocessAndShowBase(BzrError):
 
1165
 
 
1166
    _fmt = "Can't reprocess and show base, because reprocessing obscures " \
 
1167
           "the relationship of conflicting lines to the base"
 
1168
 
 
1169
 
 
1170
class GraphCycleError(BzrError):
 
1171
 
 
1172
    _fmt = "Cycle in graph %(graph)r"
 
1173
 
946
1174
    def __init__(self, graph):
947
 
        BzrNewError.__init__(self)
 
1175
        BzrError.__init__(self)
948
1176
        self.graph = graph
949
1177
 
950
1178
 
951
 
class NotConflicted(BzrNewError):
952
 
    """File %(filename)s is not conflicted."""
 
1179
class WritingCompleted(BzrError):
 
1180
 
 
1181
    _fmt = ("The MediumRequest '%(request)s' has already had finish_writing "
 
1182
            "called upon it - accept bytes may not be called anymore.")
 
1183
 
 
1184
    internal_error = True
 
1185
 
 
1186
    def __init__(self, request):
 
1187
        self.request = request
 
1188
 
 
1189
 
 
1190
class WritingNotComplete(BzrError):
 
1191
 
 
1192
    _fmt = ("The MediumRequest '%(request)s' has not has finish_writing "
 
1193
            "called upon it - until the write phase is complete no "
 
1194
            "data may be read.")
 
1195
 
 
1196
    internal_error = True
 
1197
 
 
1198
    def __init__(self, request):
 
1199
        self.request = request
 
1200
 
 
1201
 
 
1202
class NotConflicted(BzrError):
 
1203
 
 
1204
    _fmt = "File %(filename)s is not conflicted."
953
1205
 
954
1206
    def __init__(self, filename):
955
 
        BzrNewError.__init__(self)
 
1207
        BzrError.__init__(self)
956
1208
        self.filename = filename
957
1209
 
958
1210
 
 
1211
class MediumNotConnected(BzrError):
 
1212
 
 
1213
    _fmt = """The medium '%(medium)s' is not connected."""
 
1214
 
 
1215
    internal_error = True
 
1216
 
 
1217
    def __init__(self, medium):
 
1218
        self.medium = medium
 
1219
 
 
1220
 
959
1221
class MustUseDecorated(Exception):
960
 
    """A decorating function has requested its original command be used.
961
 
    
962
 
    This should never escape bzr, so does not need to be printable.
963
 
    """
964
 
 
965
 
 
966
 
class NoBundleFound(BzrNewError):
967
 
    """No bundle was found in %(filename)s"""
 
1222
    
 
1223
    _fmt = """A decorating function has requested its original command be used."""
 
1224
    
 
1225
 
 
1226
class NoBundleFound(BzrError):
 
1227
 
 
1228
    _fmt = "No bundle was found in %(filename)s"
 
1229
 
968
1230
    def __init__(self, filename):
969
 
        BzrNewError.__init__(self)
 
1231
        BzrError.__init__(self)
970
1232
        self.filename = filename
971
1233
 
972
1234
 
973
 
class BundleNotSupported(BzrNewError):
974
 
    """Unable to handle bundle version %(version)s: %(msg)s"""
 
1235
class BundleNotSupported(BzrError):
 
1236
 
 
1237
    _fmt = "Unable to handle bundle version %(version)s: %(msg)s"
 
1238
 
975
1239
    def __init__(self, version, msg):
976
 
        BzrNewError.__init__(self)
 
1240
        BzrError.__init__(self)
977
1241
        self.version = version
978
1242
        self.msg = msg
979
1243
 
980
1244
 
981
 
class MissingText(BzrNewError):
982
 
    """Branch %(base)s is missing revision %(text_revision)s of %(file_id)s"""
 
1245
class MissingText(BzrError):
 
1246
 
 
1247
    _fmt = "Branch %(base)s is missing revision %(text_revision)s of %(file_id)s"
983
1248
 
984
1249
    def __init__(self, branch, text_revision, file_id):
985
 
        BzrNewError.__init__(self)
 
1250
        BzrError.__init__(self)
986
1251
        self.branch = branch
987
1252
        self.base = branch.base
988
1253
        self.text_revision = text_revision
989
1254
        self.file_id = file_id
990
1255
 
991
1256
 
992
 
class DuplicateKey(BzrNewError):
993
 
    """Key %(key)s is already present in map"""
994
 
 
995
 
 
996
 
class MalformedTransform(BzrNewError):
997
 
    """Tree transform is malformed %(conflicts)r"""
998
 
 
999
 
 
1000
 
class BzrBadParameter(BzrNewError):
1001
 
    """A bad parameter : %(param)s is not usable.
1002
 
    
1003
 
    This exception should never be thrown, but it is a base class for all
1004
 
    parameter-to-function errors.
1005
 
    """
 
1257
class DuplicateKey(BzrError):
 
1258
 
 
1259
    _fmt = "Key %(key)s is already present in map"
 
1260
 
 
1261
 
 
1262
class MalformedTransform(BzrError):
 
1263
 
 
1264
    _fmt = "Tree transform is malformed %(conflicts)r"
 
1265
 
 
1266
 
 
1267
class NoFinalPath(BzrError):
 
1268
 
 
1269
    _fmt = ("No final name for trans_id %(trans_id)r\n"
 
1270
            "file-id: %(file_id)r\n"
 
1271
            "root trans-id: %(root_trans_id)r\n")
 
1272
 
 
1273
    def __init__(self, trans_id, transform):
 
1274
        self.trans_id = trans_id
 
1275
        self.file_id = transform.final_file_id(trans_id)
 
1276
        self.root_trans_id = transform.root
 
1277
 
 
1278
 
 
1279
class BzrBadParameter(BzrError):
 
1280
 
 
1281
    _fmt = "Bad parameter: %(param)r"
 
1282
 
 
1283
    # This exception should never be thrown, but it is a base class for all
 
1284
    # parameter-to-function errors.
 
1285
 
1006
1286
    def __init__(self, param):
1007
 
        BzrNewError.__init__(self)
 
1287
        BzrError.__init__(self)
1008
1288
        self.param = param
1009
1289
 
1010
1290
 
1011
1291
class BzrBadParameterNotUnicode(BzrBadParameter):
1012
 
    """Parameter %(param)s is neither unicode nor utf8."""
1013
 
 
1014
 
 
1015
 
class ReusingTransform(BzrNewError):
1016
 
    """Attempt to reuse a transform that has already been applied."""
1017
 
 
1018
 
 
1019
 
class CantMoveRoot(BzrNewError):
1020
 
    """Moving the root directory is not supported at this time"""
 
1292
 
 
1293
    _fmt = "Parameter %(param)s is neither unicode nor utf8."
 
1294
 
 
1295
 
 
1296
class ReusingTransform(BzrError):
 
1297
 
 
1298
    _fmt = "Attempt to reuse a transform that has already been applied."
 
1299
 
 
1300
 
 
1301
class CantMoveRoot(BzrError):
 
1302
 
 
1303
    _fmt = "Moving the root directory is not supported at this time"
1021
1304
 
1022
1305
 
1023
1306
class BzrBadParameterNotString(BzrBadParameter):
1024
 
    """Parameter %(param)s is not a string or unicode string."""
 
1307
 
 
1308
    _fmt = "Parameter %(param)s is not a string or unicode string."
1025
1309
 
1026
1310
 
1027
1311
class BzrBadParameterMissing(BzrBadParameter):
1028
 
    """Parameter $(param)s is required but not present."""
 
1312
 
 
1313
    _fmt = "Parameter $(param)s is required but not present."
1029
1314
 
1030
1315
 
1031
1316
class BzrBadParameterUnicode(BzrBadParameter):
1032
 
    """Parameter %(param)s is unicode but only byte-strings are permitted."""
 
1317
 
 
1318
    _fmt = "Parameter %(param)s is unicode but only byte-strings are permitted."
1033
1319
 
1034
1320
 
1035
1321
class BzrBadParameterContainsNewline(BzrBadParameter):
1036
 
    """Parameter %(param)s contains a newline."""
1037
 
 
1038
 
 
1039
 
class DependencyNotPresent(BzrNewError):
1040
 
    """Unable to import library "%(library)s": %(error)s"""
 
1322
 
 
1323
    _fmt = "Parameter %(param)s contains a newline."
 
1324
 
 
1325
 
 
1326
class DependencyNotPresent(BzrError):
 
1327
 
 
1328
    _fmt = 'Unable to import library "%(library)s": %(error)s'
1041
1329
 
1042
1330
    def __init__(self, library, error):
1043
 
        BzrNewError.__init__(self, library=library, error=error)
 
1331
        BzrError.__init__(self, library=library, error=error)
1044
1332
 
1045
1333
 
1046
1334
class ParamikoNotPresent(DependencyNotPresent):
1047
 
    """Unable to import paramiko (required for sftp support): %(error)s"""
 
1335
 
 
1336
    _fmt = "Unable to import paramiko (required for sftp support): %(error)s"
1048
1337
 
1049
1338
    def __init__(self, error):
1050
1339
        DependencyNotPresent.__init__(self, 'paramiko', error)
1051
1340
 
1052
1341
 
1053
 
class PointlessMerge(BzrNewError):
1054
 
    """Nothing to merge."""
1055
 
 
1056
 
 
1057
 
class UninitializableFormat(BzrNewError):
1058
 
    """Format %(format)s cannot be initialised by this version of bzr."""
 
1342
class PointlessMerge(BzrError):
 
1343
 
 
1344
    _fmt = "Nothing to merge."
 
1345
 
 
1346
 
 
1347
class UninitializableFormat(BzrError):
 
1348
 
 
1349
    _fmt = "Format %(format)s cannot be initialised by this version of bzr."
1059
1350
 
1060
1351
    def __init__(self, format):
1061
 
        BzrNewError.__init__(self)
 
1352
        BzrError.__init__(self)
1062
1353
        self.format = format
1063
1354
 
1064
1355
 
1065
 
class BadConversionTarget(BzrNewError):
1066
 
    """Cannot convert to format %(format)s.  %(problem)s"""
 
1356
class BadConversionTarget(BzrError):
 
1357
 
 
1358
    _fmt = "Cannot convert to format %(format)s.  %(problem)s"
1067
1359
 
1068
1360
    def __init__(self, problem, format):
1069
 
        BzrNewError.__init__(self)
 
1361
        BzrError.__init__(self)
1070
1362
        self.problem = problem
1071
1363
        self.format = format
1072
1364
 
1073
1365
 
1074
 
class NoDiff(BzrNewError):
1075
 
    """Diff is not installed on this machine: %(msg)s"""
 
1366
class NoDiff(BzrError):
 
1367
 
 
1368
    _fmt = "Diff is not installed on this machine: %(msg)s"
1076
1369
 
1077
1370
    def __init__(self, msg):
1078
 
        BzrNewError.__init__(self, msg=msg)
1079
 
 
1080
 
 
1081
 
class NoDiff3(BzrNewError):
1082
 
    """Diff3 is not installed on this machine."""
1083
 
 
1084
 
 
1085
 
class ExistingLimbo(BzrNewError):
1086
 
    """This tree contains left-over files from a failed operation.
1087
 
    Please examine %(limbo_dir)s to see if it contains any files you wish to
1088
 
    keep, and delete it when you are done.
1089
 
    """
1090
 
    def __init__(self, limbo_dir):
1091
 
       BzrNewError.__init__(self)
1092
 
       self.limbo_dir = limbo_dir
1093
 
 
1094
 
 
1095
 
class ImmortalLimbo(BzrNewError):
1096
 
    """Unable to delete transform temporary directory $(limbo_dir)s.
1097
 
    Please examine %(limbo_dir)s to see if it contains any files you wish to
1098
 
    keep, and delete it when you are done.
1099
 
    """
1100
 
    def __init__(self, limbo_dir):
1101
 
       BzrNewError.__init__(self)
1102
 
       self.limbo_dir = limbo_dir
1103
 
 
1104
 
 
1105
 
class OutOfDateTree(BzrNewError):
1106
 
    """Working tree is out of date, please run 'bzr update'."""
 
1371
        BzrError.__init__(self, msg=msg)
 
1372
 
 
1373
 
 
1374
class NoDiff3(BzrError):
 
1375
 
 
1376
    _fmt = "Diff3 is not installed on this machine."
 
1377
 
 
1378
 
 
1379
class ExistingLimbo(BzrError):
 
1380
 
 
1381
    _fmt = """This tree contains left-over files from a failed operation.
 
1382
    Please examine %(limbo_dir)s to see if it contains any files you wish to
 
1383
    keep, and delete it when you are done."""
 
1384
    
 
1385
    def __init__(self, limbo_dir):
 
1386
       BzrError.__init__(self)
 
1387
       self.limbo_dir = limbo_dir
 
1388
 
 
1389
 
 
1390
class ImmortalLimbo(BzrError):
 
1391
 
 
1392
    _fmt = """Unable to delete transform temporary directory $(limbo_dir)s.
 
1393
    Please examine %(limbo_dir)s to see if it contains any files you wish to
 
1394
    keep, and delete it when you are done."""
 
1395
 
 
1396
    def __init__(self, limbo_dir):
 
1397
       BzrError.__init__(self)
 
1398
       self.limbo_dir = limbo_dir
 
1399
 
 
1400
 
 
1401
class OutOfDateTree(BzrError):
 
1402
 
 
1403
    _fmt = "Working tree is out of date, please run 'bzr update'."
1107
1404
 
1108
1405
    def __init__(self, tree):
1109
 
        BzrNewError.__init__(self)
 
1406
        BzrError.__init__(self)
1110
1407
        self.tree = tree
1111
1408
 
1112
1409
 
1113
 
class MergeModifiedFormatError(BzrNewError):
1114
 
    """Error in merge modified format"""
1115
 
 
1116
 
 
1117
 
class ConflictFormatError(BzrNewError):
1118
 
    """Format error in conflict listings"""
1119
 
 
1120
 
 
1121
 
class CorruptRepository(BzrNewError):
1122
 
    """An error has been detected in the repository %(repo_path)s.
 
1410
class MergeModifiedFormatError(BzrError):
 
1411
 
 
1412
    _fmt = "Error in merge modified format"
 
1413
 
 
1414
 
 
1415
class ConflictFormatError(BzrError):
 
1416
 
 
1417
    _fmt = "Format error in conflict listings"
 
1418
 
 
1419
 
 
1420
class CorruptRepository(BzrError):
 
1421
 
 
1422
    _fmt = """An error has been detected in the repository %(repo_path)s.
1123
1423
Please run bzr reconcile on this repository."""
1124
1424
 
1125
1425
    def __init__(self, repo):
1126
 
        BzrNewError.__init__(self)
 
1426
        BzrError.__init__(self)
1127
1427
        self.repo_path = repo.bzrdir.root_transport.base
1128
1428
 
1129
1429
 
1130
 
class UpgradeRequired(BzrNewError):
1131
 
    """To use this feature you must upgrade your branch at %(path)s."""
 
1430
class UpgradeRequired(BzrError):
 
1431
 
 
1432
    _fmt = "To use this feature you must upgrade your branch at %(path)s."
1132
1433
 
1133
1434
    def __init__(self, path):
1134
 
        BzrNewError.__init__(self)
 
1435
        BzrError.__init__(self)
1135
1436
        self.path = path
1136
1437
 
1137
1438
 
1138
 
class LocalRequiresBoundBranch(BzrNewError):
1139
 
    """Cannot perform local-only commits on unbound branches."""
1140
 
 
1141
 
 
1142
 
class MissingProgressBarFinish(BzrNewError):
1143
 
    """A nested progress bar was not 'finished' correctly."""
1144
 
 
1145
 
 
1146
 
class InvalidProgressBarType(BzrNewError):
1147
 
    """Environment variable BZR_PROGRESS_BAR='%(bar_type)s is not a supported type
 
1439
class LocalRequiresBoundBranch(BzrError):
 
1440
 
 
1441
    _fmt = "Cannot perform local-only commits on unbound branches."
 
1442
 
 
1443
 
 
1444
class MissingProgressBarFinish(BzrError):
 
1445
 
 
1446
    _fmt = "A nested progress bar was not 'finished' correctly."
 
1447
 
 
1448
 
 
1449
class InvalidProgressBarType(BzrError):
 
1450
 
 
1451
    _fmt = """Environment variable BZR_PROGRESS_BAR='%(bar_type)s is not a supported type
1148
1452
Select one of: %(valid_types)s"""
1149
1453
 
1150
1454
    def __init__(self, bar_type, valid_types):
1151
 
        BzrNewError.__init__(self, bar_type=bar_type, valid_types=valid_types)
1152
 
 
1153
 
 
1154
 
class UnsupportedOperation(BzrNewError):
1155
 
    """The method %(mname)s is not supported on objects of type %(tname)s."""
 
1455
        BzrError.__init__(self, bar_type=bar_type, valid_types=valid_types)
 
1456
 
 
1457
 
 
1458
class UnsupportedOperation(BzrError):
 
1459
 
 
1460
    _fmt = "The method %(mname)s is not supported on objects of type %(tname)s."
 
1461
 
1156
1462
    def __init__(self, method, method_self):
1157
1463
        self.method = method
1158
1464
        self.mname = method.__name__
1159
1465
        self.tname = type(method_self).__name__
1160
1466
 
1161
1467
 
1162
 
class BinaryFile(BzrNewError):
1163
 
    """File is binary but should be text."""
1164
 
 
1165
 
 
1166
 
class IllegalPath(BzrNewError):
1167
 
    """The path %(path)s is not permitted on this platform"""
 
1468
class CannotSetRevisionId(UnsupportedOperation):
 
1469
    """Raised when a commit is attempting to set a revision id but cant."""
 
1470
 
 
1471
 
 
1472
class NonAsciiRevisionId(UnsupportedOperation):
 
1473
    """Raised when a commit is attempting to set a non-ascii revision id but cant."""
 
1474
 
 
1475
 
 
1476
class BinaryFile(BzrError):
 
1477
    
 
1478
    _fmt = "File is binary but should be text."
 
1479
 
 
1480
 
 
1481
class IllegalPath(BzrError):
 
1482
 
 
1483
    _fmt = "The path %(path)s is not permitted on this platform"
1168
1484
 
1169
1485
    def __init__(self, path):
1170
 
        BzrNewError.__init__(self)
 
1486
        BzrError.__init__(self)
1171
1487
        self.path = path
1172
1488
 
1173
1489
 
1174
 
class TestamentMismatch(BzrNewError):
1175
 
    """Testament did not match expected value.  
 
1490
class TestamentMismatch(BzrError):
 
1491
 
 
1492
    _fmt = """Testament did not match expected value.  
1176
1493
       For revision_id {%(revision_id)s}, expected {%(expected)s}, measured 
1177
 
       {%(measured)s}
1178
 
    """
 
1494
       {%(measured)s}"""
 
1495
 
1179
1496
    def __init__(self, revision_id, expected, measured):
1180
1497
        self.revision_id = revision_id
1181
1498
        self.expected = expected
1182
1499
        self.measured = measured
1183
1500
 
1184
1501
 
1185
 
class NotABundle(BzrNewError):
1186
 
    """Not a bzr revision-bundle: %(text)r"""
 
1502
class NotABundle(BzrError):
 
1503
    
 
1504
    _fmt = "Not a bzr revision-bundle: %(text)r"
1187
1505
 
1188
1506
    def __init__(self, text):
1189
 
        BzrNewError.__init__(self)
 
1507
        BzrError.__init__(self)
1190
1508
        self.text = text
1191
1509
 
1192
1510
 
1193
 
class BadBundle(BzrNewError): 
1194
 
    """Bad bzr revision-bundle: %(text)r"""
 
1511
class BadBundle(BzrError): 
 
1512
    
 
1513
    _fmt = "Bad bzr revision-bundle: %(text)r"
1195
1514
 
1196
1515
    def __init__(self, text):
1197
 
        BzrNewError.__init__(self)
 
1516
        BzrError.__init__(self)
1198
1517
        self.text = text
1199
1518
 
1200
1519
 
1201
1520
class MalformedHeader(BadBundle): 
1202
 
    """Malformed bzr revision-bundle header: %(text)r"""
1203
 
 
1204
 
    def __init__(self, text):
1205
 
        BzrNewError.__init__(self)
1206
 
        self.text = text
 
1521
    
 
1522
    _fmt = "Malformed bzr revision-bundle header: %(text)r"
1207
1523
 
1208
1524
 
1209
1525
class MalformedPatches(BadBundle): 
1210
 
    """Malformed patches in bzr revision-bundle: %(text)r"""
1211
 
 
1212
 
    def __init__(self, text):
1213
 
        BzrNewError.__init__(self)
1214
 
        self.text = text
 
1526
    
 
1527
    _fmt = "Malformed patches in bzr revision-bundle: %(text)r"
1215
1528
 
1216
1529
 
1217
1530
class MalformedFooter(BadBundle): 
1218
 
    """Malformed footer in bzr revision-bundle: %(text)r"""
1219
 
 
1220
 
    def __init__(self, text):
1221
 
        BzrNewError.__init__(self)
1222
 
        self.text = text
 
1531
    
 
1532
    _fmt = "Malformed footer in bzr revision-bundle: %(text)r"
1223
1533
 
1224
1534
 
1225
1535
class UnsupportedEOLMarker(BadBundle):
1226
 
    """End of line marker was not \\n in bzr revision-bundle"""    
 
1536
    
 
1537
    _fmt = "End of line marker was not \\n in bzr revision-bundle"    
1227
1538
 
1228
1539
    def __init__(self):
1229
 
        BzrNewError.__init__(self)
1230
 
 
1231
 
 
1232
 
class IncompatibleFormat(BzrNewError):
1233
 
    """Bundle format %(bundle_format)s is incompatible with %(other)s"""
 
1540
        # XXX: BadBundle's constructor assumes there's explanatory text, 
 
1541
        # but for this there is not
 
1542
        BzrError.__init__(self)
 
1543
 
 
1544
 
 
1545
class IncompatibleBundleFormat(BzrError):
 
1546
    
 
1547
    _fmt = "Bundle format %(bundle_format)s is incompatible with %(other)s"
1234
1548
 
1235
1549
    def __init__(self, bundle_format, other):
1236
 
        BzrNewError.__init__(self)
 
1550
        BzrError.__init__(self)
1237
1551
        self.bundle_format = bundle_format
1238
1552
        self.other = other
1239
1553
 
1240
1554
 
1241
 
class BadInventoryFormat(BzrNewError):
1242
 
    """Root class for inventory serialization errors"""
 
1555
class BadInventoryFormat(BzrError):
 
1556
    
 
1557
    _fmt = "Root class for inventory serialization errors"
1243
1558
 
1244
1559
 
1245
1560
class UnexpectedInventoryFormat(BadInventoryFormat):
1246
 
    """The inventory was not in the expected format:\n %(msg)s"""
 
1561
 
 
1562
    _fmt = "The inventory was not in the expected format:\n %(msg)s"
1247
1563
 
1248
1564
    def __init__(self, msg):
1249
1565
        BadInventoryFormat.__init__(self, msg=msg)
1250
1566
 
1251
1567
 
 
1568
class NoSmartMedium(BzrError):
 
1569
 
 
1570
    _fmt = "The transport '%(transport)s' cannot tunnel the smart protocol."
 
1571
 
 
1572
    def __init__(self, transport):
 
1573
        self.transport = transport
 
1574
 
 
1575
 
1252
1576
class NoSmartServer(NotBranchError):
1253
 
    """No smart server available at %(url)s"""
 
1577
 
 
1578
    _fmt = "No smart server available at %(url)s"
1254
1579
 
1255
1580
    def __init__(self, url):
1256
1581
        self.url = url
1257
1582
 
1258
1583
 
1259
 
class UnknownSSH(BzrNewError):
1260
 
    """Unrecognised value for BZR_SSH environment variable: %(vendor)s"""
 
1584
class UnknownSSH(BzrError):
 
1585
 
 
1586
    _fmt = "Unrecognised value for BZR_SSH environment variable: %(vendor)s"
1261
1587
 
1262
1588
    def __init__(self, vendor):
1263
 
        BzrNewError.__init__(self)
 
1589
        BzrError.__init__(self)
1264
1590
        self.vendor = vendor
1265
1591
 
1266
1592
 
1267
 
class GhostRevisionUnusableHere(BzrNewError):
1268
 
    """Ghost revision {%(revision_id)s} cannot be used here."""
 
1593
class GhostRevisionUnusableHere(BzrError):
 
1594
 
 
1595
    _fmt = "Ghost revision {%(revision_id)s} cannot be used here."
1269
1596
 
1270
1597
    def __init__(self, revision_id):
1271
 
        BzrNewError.__init__(self)
 
1598
        BzrError.__init__(self)
1272
1599
        self.revision_id = revision_id
1273
1600
 
1274
1601
 
1275
 
class IllegalUseOfScopeReplacer(BzrNewError):
1276
 
    """ScopeReplacer object %(name)r was used incorrectly: %(msg)s%(extra)s"""
1277
 
 
1278
 
    is_user_error = False
 
1602
class IllegalUseOfScopeReplacer(BzrError):
 
1603
 
 
1604
    _fmt = "ScopeReplacer object %(name)r was used incorrectly: %(msg)s%(extra)s"
 
1605
 
 
1606
    internal_error = True
1279
1607
 
1280
1608
    def __init__(self, name, msg, extra=None):
1281
 
        BzrNewError.__init__(self)
 
1609
        BzrError.__init__(self)
1282
1610
        self.name = name
1283
1611
        self.msg = msg
1284
1612
        if extra:
1287
1615
            self.extra = ''
1288
1616
 
1289
1617
 
1290
 
class InvalidImportLine(BzrNewError):
1291
 
    """Not a valid import statement: %(msg)\n%(text)s"""
1292
 
 
1293
 
    is_user_error = False
 
1618
class InvalidImportLine(BzrError):
 
1619
 
 
1620
    _fmt = "Not a valid import statement: %(msg)\n%(text)s"
 
1621
 
 
1622
    internal_error = True
1294
1623
 
1295
1624
    def __init__(self, text, msg):
1296
 
        BzrNewError.__init__(self)
 
1625
        BzrError.__init__(self)
1297
1626
        self.text = text
1298
1627
        self.msg = msg
1299
1628
 
1300
1629
 
1301
 
class ImportNameCollision(BzrNewError):
1302
 
    """Tried to import an object to the same name as an existing object. %(name)s"""
1303
 
 
1304
 
    is_user_error = False
 
1630
class ImportNameCollision(BzrError):
 
1631
 
 
1632
    _fmt = "Tried to import an object to the same name as an existing object. %(name)s"
 
1633
 
 
1634
    internal_error = True
1305
1635
 
1306
1636
    def __init__(self, name):
1307
 
        BzrNewError.__init__(self)
 
1637
        BzrError.__init__(self)
1308
1638
        self.name = name