/brz/remove-bazaar

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

« back to all changes in this revision

Viewing changes to bzrlib/errors.py

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