/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.

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