~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/errors.py

  • Committer: Martin Packman
  • Date: 2011-12-23 19:38:22 UTC
  • mto: This revision was merged to the branch mainline in revision 6405.
  • Revision ID: martin.packman@canonical.com-20111223193822-hesheea4o8aqwexv
Accept and document passing the medium rather than transport for smart connections

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005, 2006, 2007 Canonical Ltd
 
1
# Copyright (C) 2005-2011 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
12
12
#
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
 
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
17
"""Exceptions for bzr, and reporting of them.
18
18
"""
19
19
 
20
 
 
21
 
from bzrlib import (
22
 
    osutils,
23
 
    symbol_versioning,
24
 
    )
25
 
from bzrlib.patches import (
26
 
    MalformedHunkHeader,
27
 
    MalformedLine,
28
 
    MalformedPatchHeader,
29
 
    PatchConflict,
30
 
    PatchSyntax,
31
 
    )
32
 
 
33
 
 
34
20
# TODO: is there any value in providing the .args field used by standard
35
 
# python exceptions?   A list of values with no names seems less useful 
 
21
# python exceptions?   A list of values with no names seems less useful
36
22
# to me.
37
23
 
38
 
# TODO: Perhaps convert the exception to a string at the moment it's 
 
24
# TODO: Perhaps convert the exception to a string at the moment it's
39
25
# constructed to make sure it will succeed.  But that says nothing about
40
26
# exceptions that are never raised.
41
27
 
44
30
# 'unprintable'.
45
31
 
46
32
 
 
33
# return codes from the bzr program
 
34
EXIT_OK = 0
 
35
EXIT_ERROR = 3
 
36
EXIT_INTERNAL_ERROR = 4
 
37
 
 
38
 
47
39
class BzrError(StandardError):
48
40
    """
49
41
    Base class for errors raised by bzrlib.
50
42
 
51
43
    :cvar internal_error: if True this was probably caused by a bzr bug and
52
 
    should be displayed with a traceback; if False (or absent) 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.)
 
44
        should be displayed with a traceback; if False (or absent) this was
 
45
        probably a user or environment error and they don't need the gory
 
46
        details.  (That can be overridden by -Derror on the command line.)
55
47
 
56
48
    :cvar _fmt: Format string to display the error; this is expanded
57
 
    by the instance's dict.
 
49
        by the instance's dict.
58
50
    """
59
 
    
 
51
 
60
52
    internal_error = False
61
53
 
62
54
    def __init__(self, msg=None, **kwds):
67
59
        arguments can be given.  The first is for generic "user" errors which
68
60
        are not intended to be caught and so do not need a specific subclass.
69
61
        The second case is for use with subclasses that provide a _fmt format
70
 
        string to print the arguments.  
 
62
        string to print the arguments.
71
63
 
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 
 
64
        Keyword arguments are taken as parameters to the error, which can
 
65
        be inserted into the format string template.  It's recommended
 
66
        that subclasses override the __init__ method to require specific
75
67
        parameters.
76
68
 
77
69
        :param msg: If given, this is the literal complete text for the error,
78
 
        not subject to expansion.
 
70
           not subject to expansion. 'msg' is used instead of 'message' because
 
71
           python evolved and, in 2.6, forbids the use of 'message'.
79
72
        """
80
73
        StandardError.__init__(self)
81
74
        if msg is not None:
87
80
            for key, value in kwds.items():
88
81
                setattr(self, key, value)
89
82
 
90
 
    def __str__(self):
 
83
    def _format(self):
91
84
        s = getattr(self, '_preformatted_string', None)
92
85
        if s is not None:
93
 
            # contains a preformatted message; must be cast to plain str
94
 
            return str(s)
 
86
            # contains a preformatted message
 
87
            return s
95
88
        try:
96
89
            fmt = self._get_format_string()
97
90
            if fmt:
98
 
                s = fmt % self.__dict__
 
91
                d = dict(self.__dict__)
 
92
                s = fmt % d
99
93
                # __str__() should always return a 'str' object
100
94
                # never a 'unicode' object.
101
 
                if isinstance(s, unicode):
102
 
                    return s.encode('utf8')
103
95
                return s
104
 
        except (AttributeError, TypeError, NameError, ValueError, KeyError), e:
105
 
            return 'Unprintable exception %s: dict=%r, fmt=%r, error=%r' \
106
 
                % (self.__class__.__name__,
107
 
                   self.__dict__,
108
 
                   getattr(self, '_fmt', None),
109
 
                   e)
 
96
        except Exception, e:
 
97
            pass # just bind to 'e' for formatting below
 
98
        else:
 
99
            e = None
 
100
        return 'Unprintable exception %s: dict=%r, fmt=%r, error=%r' \
 
101
            % (self.__class__.__name__,
 
102
               self.__dict__,
 
103
               getattr(self, '_fmt', None),
 
104
               e)
 
105
 
 
106
    def __unicode__(self):
 
107
        u = self._format()
 
108
        if isinstance(u, str):
 
109
            # Try decoding the str using the default encoding.
 
110
            u = unicode(u)
 
111
        elif not isinstance(u, unicode):
 
112
            # Try to make a unicode object from it, because __unicode__ must
 
113
            # return a unicode object.
 
114
            u = unicode(u)
 
115
        return u
 
116
 
 
117
    def __str__(self):
 
118
        s = self._format()
 
119
        if isinstance(s, unicode):
 
120
            s = s.encode('utf8')
 
121
        else:
 
122
            # __str__ must return a str.
 
123
            s = str(s)
 
124
        return s
 
125
 
 
126
    def __repr__(self):
 
127
        return '%s(%s)' % (self.__class__.__name__, str(self))
110
128
 
111
129
    def _get_format_string(self):
112
130
        """Return format string for this exception or None"""
113
131
        fmt = getattr(self, '_fmt', None)
114
132
        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
 
               )
127
 
 
128
 
 
129
 
class BzrNewError(BzrError):
130
 
    """Deprecated error base class."""
131
 
    # base classes should override the docstring with their human-
132
 
    # readable explanation
133
 
 
134
 
    def __init__(self, *args, **kwds):
135
 
        # XXX: Use the underlying BzrError to always generate the args
136
 
        # attribute if it doesn't exist.  We can't use super here, because
137
 
        # exceptions are old-style classes in python2.4 (but new in 2.5).
138
 
        # --bmc, 20060426
139
 
        symbol_versioning.warn('BzrNewError was deprecated in bzr 0.13; '
140
 
             'please convert %s to use BzrError instead'
141
 
             % self.__class__.__name__,
142
 
             DeprecationWarning,
143
 
             stacklevel=2)
144
 
        BzrError.__init__(self, *args)
145
 
        for key, value in kwds.items():
146
 
            setattr(self, key, value)
147
 
 
148
 
    def __str__(self):
149
 
        try:
150
 
            # __str__() should always return a 'str' object
151
 
            # never a 'unicode' object.
152
 
            s = self.__doc__ % self.__dict__
153
 
            if isinstance(s, unicode):
154
 
                return s.encode('utf8')
155
 
            return s
156
 
        except (TypeError, NameError, ValueError, KeyError), e:
157
 
            return 'Unprintable exception %s(%r): %r' \
158
 
                % (self.__class__.__name__,
159
 
                   self.__dict__, e)
 
133
            from bzrlib.i18n import gettext
 
134
            return gettext(unicode(fmt)) # _fmt strings should be ascii
 
135
 
 
136
    def __eq__(self, other):
 
137
        if self.__class__ is not other.__class__:
 
138
            return NotImplemented
 
139
        return self.__dict__ == other.__dict__
 
140
 
 
141
 
 
142
class InternalBzrError(BzrError):
 
143
    """Base class for errors that are internal in nature.
 
144
 
 
145
    This is a convenience class for errors that are internal. The
 
146
    internal_error attribute can still be altered in subclasses, if needed.
 
147
    Using this class is simply an easy way to get internal errors.
 
148
    """
 
149
 
 
150
    internal_error = True
160
151
 
161
152
 
162
153
class AlreadyBuilding(BzrError):
163
 
    
 
154
 
164
155
    _fmt = "The tree builder is already building a tree."
165
156
 
166
157
 
167
 
class BzrCheckError(BzrError):
168
 
    
169
 
    _fmt = "Internal check failed: %(message)s"
170
 
 
171
 
    internal_error = True
172
 
 
173
 
    def __init__(self, message):
174
 
        BzrError.__init__(self)
175
 
        self.message = message
176
 
 
177
 
 
178
 
class DisabledMethod(BzrError):
 
158
class BranchError(BzrError):
 
159
    """Base class for concrete 'errors about a branch'."""
 
160
 
 
161
    def __init__(self, branch):
 
162
        BzrError.__init__(self, branch=branch)
 
163
 
 
164
 
 
165
class BzrCheckError(InternalBzrError):
 
166
 
 
167
    _fmt = "Internal check failed: %(msg)s"
 
168
 
 
169
    def __init__(self, msg):
 
170
        BzrError.__init__(self)
 
171
        self.msg = msg
 
172
 
 
173
 
 
174
class DirstateCorrupt(BzrError):
 
175
 
 
176
    _fmt = "The dirstate file (%(state)s) appears to be corrupt: %(msg)s"
 
177
 
 
178
    def __init__(self, state, msg):
 
179
        BzrError.__init__(self)
 
180
        self.state = state
 
181
        self.msg = msg
 
182
 
 
183
 
 
184
class DisabledMethod(InternalBzrError):
179
185
 
180
186
    _fmt = "The smart server method '%(class_name)s' is disabled."
181
187
 
182
 
    internal_error = True
183
 
 
184
188
    def __init__(self, class_name):
185
189
        BzrError.__init__(self)
186
190
        self.class_name = class_name
198
202
        self.current = current
199
203
 
200
204
 
201
 
class InvalidEntryName(BzrError):
202
 
    
 
205
class InProcessTransport(BzrError):
 
206
 
 
207
    _fmt = "The transport '%(transport)s' is only accessible within this " \
 
208
        "process."
 
209
 
 
210
    def __init__(self, transport):
 
211
        self.transport = transport
 
212
 
 
213
 
 
214
class InvalidEntryName(InternalBzrError):
 
215
 
203
216
    _fmt = "Invalid entry name: %(name)s"
204
217
 
205
 
    internal_error = True
206
 
 
207
218
    def __init__(self, name):
208
219
        BzrError.__init__(self)
209
220
        self.name = name
210
221
 
211
222
 
212
223
class InvalidRevisionNumber(BzrError):
213
 
    
 
224
 
214
225
    _fmt = "Invalid revision number %(revno)s"
215
226
 
216
227
    def __init__(self, revno):
228
239
        self.revision_id = revision_id
229
240
        self.branch = branch
230
241
 
 
242
 
231
243
class ReservedId(BzrError):
232
244
 
233
245
    _fmt = "Reserved revision-id {%(revision_id)s}"
236
248
        self.revision_id = revision_id
237
249
 
238
250
 
 
251
class RootMissing(InternalBzrError):
 
252
 
 
253
    _fmt = ("The root entry of a tree must be the first entry supplied to "
 
254
        "the commit builder.")
 
255
 
 
256
 
 
257
class NoPublicBranch(BzrError):
 
258
 
 
259
    _fmt = 'There is no public branch set for "%(branch_url)s".'
 
260
 
 
261
    def __init__(self, branch):
 
262
        import bzrlib.urlutils as urlutils
 
263
        public_location = urlutils.unescape_for_display(branch.base, 'ascii')
 
264
        BzrError.__init__(self, branch_url=public_location)
 
265
 
 
266
 
239
267
class NoHelpTopic(BzrError):
240
268
 
241
269
    _fmt = ("No help could be found for '%(topic)s'. "
247
275
 
248
276
class NoSuchId(BzrError):
249
277
 
250
 
    _fmt = "The file id %(file_id)s is not present in the tree %(tree)s."
251
 
    
 
278
    _fmt = 'The file id "%(file_id)s" is not present in the tree %(tree)s.'
 
279
 
252
280
    def __init__(self, tree, file_id):
253
281
        BzrError.__init__(self)
254
282
        self.file_id = file_id
255
283
        self.tree = tree
256
284
 
257
285
 
258
 
class InventoryModified(BzrError):
 
286
class NoSuchIdInRepository(NoSuchId):
 
287
 
 
288
    _fmt = ('The file id "%(file_id)s" is not present in the repository'
 
289
            ' %(repository)r')
 
290
 
 
291
    def __init__(self, repository, file_id):
 
292
        BzrError.__init__(self, repository=repository, file_id=file_id)
 
293
 
 
294
 
 
295
class NotStacked(BranchError):
 
296
 
 
297
    _fmt = "The branch '%(branch)s' is not stacked."
 
298
 
 
299
 
 
300
class InventoryModified(InternalBzrError):
259
301
 
260
302
    _fmt = ("The current inventory for the tree %(tree)r has been modified,"
261
303
            " so a clean inventory cannot be read without data loss.")
262
304
 
263
 
    internal_error = True
264
 
 
265
305
    def __init__(self, tree):
266
306
        self.tree = tree
267
307
 
268
308
 
269
309
class NoWorkingTree(BzrError):
270
310
 
271
 
    _fmt = "No WorkingTree exists for %(base)s."
272
 
    
 
311
    _fmt = 'No WorkingTree exists for "%(base)s".'
 
312
 
273
313
    def __init__(self, base):
274
314
        BzrError.__init__(self)
275
315
        self.base = base
288
328
        self.url = url
289
329
 
290
330
 
291
 
class WorkingTreeAlreadyPopulated(BzrError):
292
 
 
293
 
    _fmt = """Working tree already populated in %(base)s"""
294
 
 
295
 
    internal_error = True
 
331
class WorkingTreeAlreadyPopulated(InternalBzrError):
 
332
 
 
333
    _fmt = 'Working tree already populated in "%(base)s"'
296
334
 
297
335
    def __init__(self, base):
298
336
        self.base = base
299
337
 
 
338
 
300
339
class BzrCommandError(BzrError):
301
340
    """Error from user command"""
302
341
 
303
 
    internal_error = False
304
 
 
305
342
    # Error from malformed user command; please avoid raising this as a
306
343
    # generic exception not caused by user input.
307
344
    #
309
346
    # are not intended to be caught anyway.  UI code need not subclass
310
347
    # BzrCommandError, and non-UI code should not throw a subclass of
311
348
    # BzrCommandError.  ADHB 20051211
312
 
    def __init__(self, msg):
313
 
        # Object.__str__() must return a real string
314
 
        # returning a Unicode string is a python error.
315
 
        if isinstance(msg, unicode):
316
 
            self.msg = msg.encode('utf8')
317
 
        else:
318
 
            self.msg = msg
319
 
 
320
 
    def __str__(self):
321
 
        return self.msg
322
349
 
323
350
 
324
351
class NotWriteLocked(BzrError):
334
361
    _fmt = "Error in command line options"
335
362
 
336
363
 
 
364
class BadIndexFormatSignature(BzrError):
 
365
 
 
366
    _fmt = "%(value)s is not an index of type %(_type)s."
 
367
 
 
368
    def __init__(self, value, _type):
 
369
        BzrError.__init__(self)
 
370
        self.value = value
 
371
        self._type = _type
 
372
 
 
373
 
 
374
class BadIndexData(BzrError):
 
375
 
 
376
    _fmt = "Error in data for index %(value)s."
 
377
 
 
378
    def __init__(self, value):
 
379
        BzrError.__init__(self)
 
380
        self.value = value
 
381
 
 
382
 
 
383
class BadIndexDuplicateKey(BzrError):
 
384
 
 
385
    _fmt = "The key '%(key)s' is already in index '%(index)s'."
 
386
 
 
387
    def __init__(self, key, index):
 
388
        BzrError.__init__(self)
 
389
        self.key = key
 
390
        self.index = index
 
391
 
 
392
 
 
393
class BadIndexKey(BzrError):
 
394
 
 
395
    _fmt = "The key '%(key)s' is not a valid key."
 
396
 
 
397
    def __init__(self, key):
 
398
        BzrError.__init__(self)
 
399
        self.key = key
 
400
 
 
401
 
 
402
class BadIndexOptions(BzrError):
 
403
 
 
404
    _fmt = "Could not parse options for index %(value)s."
 
405
 
 
406
    def __init__(self, value):
 
407
        BzrError.__init__(self)
 
408
        self.value = value
 
409
 
 
410
 
 
411
class BadIndexValue(BzrError):
 
412
 
 
413
    _fmt = "The value '%(value)s' is not a valid value."
 
414
 
 
415
    def __init__(self, value):
 
416
        BzrError.__init__(self)
 
417
        self.value = value
 
418
 
 
419
 
337
420
class BadOptionValue(BzrError):
338
421
 
339
422
    _fmt = """Bad value "%(value)s" for option "%(name)s"."""
341
424
    def __init__(self, name, value):
342
425
        BzrError.__init__(self, name=name, value=value)
343
426
 
344
 
    
 
427
 
345
428
class StrictCommitFailed(BzrError):
346
429
 
347
430
    _fmt = "Commit refused because there are unknown files in the tree"
349
432
 
350
433
# XXX: Should be unified with TransportError; they seem to represent the
351
434
# same thing
 
435
# RBC 20060929: I think that unifiying with TransportError would be a mistake
 
436
# - this is finer than a TransportError - and more useful as such. It
 
437
# differentiates between 'transport has failed' and 'operation on a transport
 
438
# has failed.'
352
439
class PathError(BzrError):
353
 
    
 
440
 
354
441
    _fmt = "Generic path error: %(path)r%(extra)s)"
355
442
 
356
443
    def __init__(self, path, extra=None):
376
463
    """Used when renaming and both source and dest exist."""
377
464
 
378
465
    _fmt = ("Could not rename %(source)s => %(dest)s because both files exist."
379
 
            "%(extra)s")
 
466
            " (Use --after to tell bzr about a rename that has already"
 
467
            " happened)%(extra)s")
380
468
 
381
469
    def __init__(self, source, dest, extra=None):
382
470
        BzrError.__init__(self)
390
478
 
391
479
class NotADirectory(PathError):
392
480
 
393
 
    _fmt = "%(path)r is not a directory %(extra)s"
 
481
    _fmt = '"%(path)s" is not a directory %(extra)s'
394
482
 
395
483
 
396
484
class NotInWorkingDirectory(PathError):
397
485
 
398
 
    _fmt = "%(path)r is not in the working directory %(extra)s"
 
486
    _fmt = '"%(path)s" is not in the working directory %(extra)s'
399
487
 
400
488
 
401
489
class DirectoryNotEmpty(PathError):
402
490
 
403
 
    _fmt = "Directory not empty: %(path)r%(extra)s"
404
 
 
405
 
 
406
 
class ReadingCompleted(BzrError):
407
 
    
 
491
    _fmt = 'Directory not empty: "%(path)s"%(extra)s'
 
492
 
 
493
 
 
494
class HardLinkNotSupported(PathError):
 
495
 
 
496
    _fmt = 'Hard-linking "%(path)s" is not supported'
 
497
 
 
498
 
 
499
class ReadingCompleted(InternalBzrError):
 
500
 
408
501
    _fmt = ("The MediumRequest '%(request)s' has already had finish_reading "
409
502
            "called upon it - the request has been completed and no more "
410
503
            "data may be read.")
411
504
 
412
 
    internal_error = True
413
 
 
414
505
    def __init__(self, request):
415
506
        self.request = request
416
507
 
417
508
 
418
509
class ResourceBusy(PathError):
419
510
 
420
 
    _fmt = "Device or resource busy: %(path)r%(extra)s"
 
511
    _fmt = 'Device or resource busy: "%(path)s"%(extra)s'
421
512
 
422
513
 
423
514
class PermissionDenied(PathError):
424
515
 
425
 
    _fmt = "Permission denied: %(path)r%(extra)s"
 
516
    _fmt = 'Permission denied: "%(path)s"%(extra)s'
426
517
 
427
518
 
428
519
class InvalidURL(PathError):
429
520
 
430
 
    _fmt = "Invalid url supplied to transport: %(path)r%(extra)s"
 
521
    _fmt = 'Invalid url supplied to transport: "%(path)s"%(extra)s'
431
522
 
432
523
 
433
524
class InvalidURLJoin(PathError):
434
525
 
435
 
    _fmt = "Invalid URL join request: %(args)s%(extra)s"
436
 
 
437
 
    def __init__(self, msg, base, args):
438
 
        PathError.__init__(self, base, msg)
439
 
        self.args = [base] + list(args)
 
526
    _fmt = "Invalid URL join request: %(reason)s: %(base)r + %(join_args)r"
 
527
 
 
528
    def __init__(self, reason, base, join_args):
 
529
        self.reason = reason
 
530
        self.base = base
 
531
        self.join_args = join_args
 
532
        PathError.__init__(self, base, reason)
 
533
 
 
534
 
 
535
class InvalidRebaseURLs(PathError):
 
536
 
 
537
    _fmt = "URLs differ by more than path: %(from_)r and %(to)r"
 
538
 
 
539
    def __init__(self, from_, to):
 
540
        self.from_ = from_
 
541
        self.to = to
 
542
        PathError.__init__(self, from_, 'URLs differ by more than path.')
 
543
 
 
544
 
 
545
class UnavailableRepresentation(InternalBzrError):
 
546
 
 
547
    _fmt = ("The encoding '%(wanted)s' is not available for key %(key)s which "
 
548
        "is encoded as '%(native)s'.")
 
549
 
 
550
    def __init__(self, key, wanted, native):
 
551
        InternalBzrError.__init__(self)
 
552
        self.wanted = wanted
 
553
        self.native = native
 
554
        self.key = key
440
555
 
441
556
 
442
557
class UnknownHook(BzrError):
453
568
 
454
569
    _fmt = 'Unsupported protocol for url "%(path)s"%(extra)s'
455
570
 
456
 
    def __init__(self, url, extra):
 
571
    def __init__(self, url, extra=""):
457
572
        PathError.__init__(self, url, extra=extra)
458
573
 
459
574
 
 
575
class UnstackableBranchFormat(BzrError):
 
576
 
 
577
    _fmt = ("The branch '%(url)s'(%(format)s) is not a stackable format. "
 
578
        "You will need to upgrade the branch to permit branch stacking.")
 
579
 
 
580
    def __init__(self, format, url):
 
581
        BzrError.__init__(self)
 
582
        self.format = format
 
583
        self.url = url
 
584
 
 
585
 
 
586
class UnstackableLocationError(BzrError):
 
587
 
 
588
    _fmt = "The branch '%(branch_url)s' cannot be stacked on '%(target_url)s'."
 
589
 
 
590
    def __init__(self, branch_url, target_url):
 
591
        BzrError.__init__(self)
 
592
        self.branch_url = branch_url
 
593
        self.target_url = target_url
 
594
 
 
595
 
 
596
class UnstackableRepositoryFormat(BzrError):
 
597
 
 
598
    _fmt = ("The repository '%(url)s'(%(format)s) is not a stackable format. "
 
599
        "You will need to upgrade the repository to permit branch stacking.")
 
600
 
 
601
    def __init__(self, format, url):
 
602
        BzrError.__init__(self)
 
603
        self.format = format
 
604
        self.url = url
 
605
 
 
606
 
 
607
class ReadError(PathError):
 
608
 
 
609
    _fmt = """Error reading from %(path)r."""
 
610
 
 
611
 
460
612
class ShortReadvError(PathError):
461
613
 
462
 
    _fmt = ("readv() read %(actual)s bytes rather than %(length)s bytes"
463
 
            " at %(offset)s for %(path)s%(extra)s")
 
614
    _fmt = ('readv() read %(actual)s bytes rather than %(length)s bytes'
 
615
            ' at %(offset)s for "%(path)s"%(extra)s')
464
616
 
465
617
    internal_error = True
466
618
 
471
623
        self.actual = actual
472
624
 
473
625
 
474
 
class PathNotChild(BzrError):
475
 
 
476
 
    _fmt = "Path %(path)r is not a child of path %(base)r%(extra)s"
477
 
 
478
 
    internal_error = True
 
626
class PathNotChild(PathError):
 
627
 
 
628
    _fmt = 'Path "%(path)s" is not a child of path "%(base)s"%(extra)s'
 
629
 
 
630
    internal_error = False
479
631
 
480
632
    def __init__(self, path, base, extra=None):
481
633
        BzrError.__init__(self)
489
641
 
490
642
class InvalidNormalization(PathError):
491
643
 
492
 
    _fmt = "Path %(path)r is not unicode normalized"
 
644
    _fmt = 'Path "%(path)s" is not unicode normalized'
493
645
 
494
646
 
495
647
# TODO: This is given a URL; we try to unescape it but doing that from inside
496
648
# the exception object is a bit undesirable.
497
 
# TODO: Probably this behavior of should be a common superclass 
 
649
# TODO: Probably this behavior of should be a common superclass
498
650
class NotBranchError(PathError):
499
651
 
500
 
    _fmt = "Not a branch: %(path)s"
 
652
    _fmt = 'Not a branch: "%(path)s"%(detail)s.'
501
653
 
502
 
    def __init__(self, path):
 
654
    def __init__(self, path, detail=None, bzrdir=None):
503
655
       import bzrlib.urlutils as urlutils
504
 
       self.path = urlutils.unescape_for_display(path, 'ascii')
 
656
       path = urlutils.unescape_for_display(path, 'ascii')
 
657
       if detail is not None:
 
658
           detail = ': ' + detail
 
659
       self.detail = detail
 
660
       self.bzrdir = bzrdir
 
661
       PathError.__init__(self, path=path)
 
662
 
 
663
    def __repr__(self):
 
664
        return '<%s %r>' % (self.__class__.__name__, self.__dict__)
 
665
 
 
666
    def _format(self):
 
667
        # XXX: Ideally self.detail would be a property, but Exceptions in
 
668
        # Python 2.4 have to be old-style classes so properties don't work.
 
669
        # Instead we override _format.
 
670
        if self.detail is None:
 
671
            if self.bzrdir is not None:
 
672
                try:
 
673
                    self.bzrdir.open_repository()
 
674
                except NoRepositoryPresent:
 
675
                    self.detail = ''
 
676
                except Exception:
 
677
                    # Just ignore unexpected errors.  Raising arbitrary errors
 
678
                    # during str(err) can provoke strange bugs.  Concretely
 
679
                    # Launchpad's codehosting managed to raise NotBranchError
 
680
                    # here, and then get stuck in an infinite loop/recursion
 
681
                    # trying to str() that error.  All this error really cares
 
682
                    # about that there's no working repository there, and if
 
683
                    # open_repository() fails, there probably isn't.
 
684
                    self.detail = ''
 
685
                else:
 
686
                    self.detail = ': location is a repository'
 
687
            else:
 
688
                self.detail = ''
 
689
        return PathError._format(self)
505
690
 
506
691
 
507
692
class NoSubmitBranch(PathError):
515
700
 
516
701
class AlreadyBranchError(PathError):
517
702
 
518
 
    _fmt = "Already a branch: %(path)s."
 
703
    _fmt = 'Already a branch: "%(path)s".'
519
704
 
520
705
 
521
706
class BranchExistsWithoutWorkingTree(PathError):
522
707
 
523
 
    _fmt = "Directory contains a branch, but no working tree \
524
 
(use bzr checkout if you wish to build a working tree): %(path)s"
 
708
    _fmt = 'Directory contains a branch, but no working tree \
 
709
(use bzr checkout if you wish to build a working tree): "%(path)s"'
525
710
 
526
711
 
527
712
class AtomicFileAlreadyClosed(PathError):
528
713
 
529
 
    _fmt = ("'%(function)s' called on an AtomicFile after it was closed:"
530
 
            " %(path)s")
 
714
    _fmt = ('"%(function)s" called on an AtomicFile after it was closed:'
 
715
            ' "%(path)s"')
531
716
 
532
717
    def __init__(self, path, function):
533
718
        PathError.__init__(self, path=path, extra=None)
536
721
 
537
722
class InaccessibleParent(PathError):
538
723
 
539
 
    _fmt = ("Parent not accessible given base %(base)s and"
540
 
            " relative path %(path)s")
 
724
    _fmt = ('Parent not accessible given base "%(base)s" and'
 
725
            ' relative path "%(path)s"')
541
726
 
542
727
    def __init__(self, path, base):
543
728
        PathError.__init__(self, path)
546
731
 
547
732
class NoRepositoryPresent(BzrError):
548
733
 
549
 
    _fmt = "No repository present: %(path)r"
 
734
    _fmt = 'No repository present: "%(path)s"'
550
735
    def __init__(self, bzrdir):
551
736
        BzrError.__init__(self)
552
737
        self.path = bzrdir.transport.clone('..').base
553
738
 
554
739
 
555
 
class FileInWrongBranch(BzrError):
556
 
 
557
 
    _fmt = "File %(path)s in not in branch %(branch_base)s."
558
 
 
559
 
    def __init__(self, branch, path):
560
 
        BzrError.__init__(self)
561
 
        self.branch = branch
562
 
        self.branch_base = branch.base
563
 
        self.path = path
564
 
 
565
 
 
566
740
class UnsupportedFormatError(BzrError):
567
741
 
568
742
    _fmt = "Unsupported branch format: %(format)s\nPlease run 'bzr upgrade'"
569
743
 
570
744
 
571
745
class UnknownFormatError(BzrError):
572
 
    
573
 
    _fmt = "Unknown branch format: %(format)r"
 
746
 
 
747
    _fmt = "Unknown %(kind)s format: %(format)r"
 
748
 
 
749
    def __init__(self, format, kind='branch'):
 
750
        self.kind = kind
 
751
        self.format = format
574
752
 
575
753
 
576
754
class IncompatibleFormat(BzrError):
577
 
    
 
755
 
578
756
    _fmt = "Format %(format)s is not compatible with .bzr version %(bzrdir)s."
579
757
 
580
758
    def __init__(self, format, bzrdir_format):
584
762
 
585
763
 
586
764
class IncompatibleRepositories(BzrError):
587
 
 
588
 
    _fmt = "Repository %(target)s is not compatible with repository"\
589
 
        " %(source)s"
590
 
 
591
 
    def __init__(self, source, target):
592
 
        BzrError.__init__(self, target=target, source=source)
 
765
    """Report an error that two repositories are not compatible.
 
766
 
 
767
    Note that the source and target repositories are permitted to be strings:
 
768
    this exception is thrown from the smart server and may refer to a
 
769
    repository the client hasn't opened.
 
770
    """
 
771
 
 
772
    _fmt = "%(target)s\n" \
 
773
            "is not compatible with\n" \
 
774
            "%(source)s\n" \
 
775
            "%(details)s"
 
776
 
 
777
    def __init__(self, source, target, details=None):
 
778
        if details is None:
 
779
            details = "(no details)"
 
780
        BzrError.__init__(self, target=target, source=source, details=details)
593
781
 
594
782
 
595
783
class IncompatibleRevision(BzrError):
596
 
    
 
784
 
597
785
    _fmt = "Revision is not compatible with %(repo_format)s"
598
786
 
599
787
    def __init__(self, repo_format):
604
792
class AlreadyVersionedError(BzrError):
605
793
    """Used when a path is expected not to be versioned, but it is."""
606
794
 
607
 
    _fmt = "%(context_info)s%(path)s is already versioned"
 
795
    _fmt = "%(context_info)s%(path)s is already versioned."
608
796
 
609
797
    def __init__(self, path, context_info=None):
610
798
        """Construct a new AlreadyVersionedError.
611
799
 
612
800
        :param path: This is the path which is versioned,
613
 
        which should be in a user friendly form.
 
801
            which should be in a user friendly form.
614
802
        :param context_info: If given, this is information about the context,
615
 
        which could explain why this is expected to not be versioned.
 
803
            which could explain why this is expected to not be versioned.
616
804
        """
617
805
        BzrError.__init__(self)
618
806
        self.path = path
625
813
class NotVersionedError(BzrError):
626
814
    """Used when a path is expected to be versioned, but it is not."""
627
815
 
628
 
    _fmt = "%(context_info)s%(path)s is not versioned"
 
816
    _fmt = "%(context_info)s%(path)s is not versioned."
629
817
 
630
818
    def __init__(self, path, context_info=None):
631
819
        """Construct a new NotVersionedError.
632
820
 
633
821
        :param path: This is the path which is not versioned,
634
 
        which should be in a user friendly form.
 
822
            which should be in a user friendly form.
635
823
        :param context_info: If given, this is information about the context,
636
 
        which could explain why this is expected to be versioned.
 
824
            which could explain why this is expected to be versioned.
637
825
        """
638
826
        BzrError.__init__(self)
639
827
        self.path = path
682
870
        BzrError.__init__(self, filename=filename, kind=kind)
683
871
 
684
872
 
 
873
class BadFilenameEncoding(BzrError):
 
874
 
 
875
    _fmt = ('Filename %(filename)r is not valid in your current filesystem'
 
876
            ' encoding %(fs_encoding)s')
 
877
 
 
878
    def __init__(self, filename, fs_encoding):
 
879
        BzrError.__init__(self)
 
880
        self.filename = filename
 
881
        self.fs_encoding = fs_encoding
 
882
 
 
883
 
685
884
class ForbiddenControlFileError(BzrError):
686
885
 
687
 
    _fmt = "Cannot operate on %(filename)s because it is a control file"
688
 
 
689
 
 
690
 
class LockError(BzrError):
 
886
    _fmt = 'Cannot operate on "%(filename)s" because it is a control file'
 
887
 
 
888
 
 
889
class LockError(InternalBzrError):
691
890
 
692
891
    _fmt = "Lock error: %(msg)s"
693
892
 
694
 
    internal_error = True
695
 
 
696
893
    # All exceptions from the lock/unlock functions should be from
697
894
    # this exception class.  They will be translated as necessary. The
698
895
    # original exception is available as e.original_error
699
896
    #
700
897
    # New code should prefer to raise specific subclasses
701
 
    def __init__(self, message):
702
 
        # Python 2.5 uses a slot for StandardError.message,
703
 
        # so use a different variable name
704
 
        # so it is exposed in self.__dict__
705
 
        self.msg = message
 
898
    def __init__(self, msg):
 
899
        self.msg = msg
706
900
 
707
901
 
708
902
class LockActive(LockError):
742
936
        self.obj = obj
743
937
 
744
938
 
745
 
class ReadOnlyLockError(LockError):
746
 
 
747
 
    _fmt = "Cannot acquire write lock on %(fname)s. %(msg)s"
748
 
 
749
 
    def __init__(self, fname, msg):
 
939
class LockFailed(LockError):
 
940
 
 
941
    internal_error = False
 
942
 
 
943
    _fmt = "Cannot lock %(lock)s: %(why)s"
 
944
 
 
945
    def __init__(self, lock, why):
750
946
        LockError.__init__(self, '')
751
 
        self.fname = fname
752
 
        self.msg = msg
 
947
        self.lock = lock
 
948
        self.why = why
753
949
 
754
950
 
755
951
class OutSideTransaction(BzrError):
779
975
 
780
976
class UnlockableTransport(LockError):
781
977
 
 
978
    internal_error = False
 
979
 
782
980
    _fmt = "Cannot lock: transport is read only: %(transport)s"
783
981
 
784
982
    def __init__(self, transport):
787
985
 
788
986
class LockContention(LockError):
789
987
 
790
 
    _fmt = "Could not acquire lock %(lock)s"
791
 
    # TODO: show full url for lock, combining the transport and relative
792
 
    # bits?
 
988
    _fmt = 'Could not acquire lock "%(lock)s": %(msg)s'
793
989
 
794
990
    internal_error = False
795
991
 
796
 
    def __init__(self, lock):
 
992
    def __init__(self, lock, msg=''):
797
993
        self.lock = lock
 
994
        self.msg = msg
798
995
 
799
996
 
800
997
class LockBroken(LockError):
821
1018
        self.target = target
822
1019
 
823
1020
 
 
1021
class LockCorrupt(LockError):
 
1022
 
 
1023
    _fmt = ("Lock is apparently held, but corrupted: %(corruption_info)s\n"
 
1024
            "Use 'bzr break-lock' to clear it")
 
1025
 
 
1026
    internal_error = False
 
1027
 
 
1028
    def __init__(self, corruption_info, file_data=None):
 
1029
        self.corruption_info = corruption_info
 
1030
        self.file_data = file_data
 
1031
 
 
1032
 
824
1033
class LockNotHeld(LockError):
825
1034
 
826
1035
    _fmt = "Lock not held: %(lock)s"
835
1044
 
836
1045
    _fmt = "The object %(obj)s does not support token specifying a token when locking."
837
1046
 
838
 
    internal_error = True
839
 
 
840
1047
    def __init__(self, obj):
841
1048
        self.obj = obj
842
1049
 
867
1074
        BzrError.__init__(self, files=files, files_str=files_str)
868
1075
 
869
1076
 
 
1077
class ExcludesUnsupported(BzrError):
 
1078
 
 
1079
    _fmt = ('Excluding paths during commit is not supported by '
 
1080
            'repository at %(repository)r.')
 
1081
 
 
1082
    def __init__(self, repository):
 
1083
        BzrError.__init__(self, repository=repository)
 
1084
 
 
1085
 
 
1086
class BadCommitMessageEncoding(BzrError):
 
1087
 
 
1088
    _fmt = 'The specified commit message contains characters unsupported by '\
 
1089
        'the current encoding.'
 
1090
 
 
1091
 
870
1092
class UpgradeReadonly(BzrError):
871
1093
 
872
1094
    _fmt = "Upgrade URL cannot work with readonly URLs."
886
1108
    _fmt = "Commit refused because there are unknowns in the tree."
887
1109
 
888
1110
 
889
 
class NoSuchRevision(BzrError):
890
 
 
891
 
    _fmt = "Branch %(branch)s has no revision %(revision)s"
892
 
 
893
 
    internal_error = True
 
1111
class NoSuchRevision(InternalBzrError):
 
1112
 
 
1113
    _fmt = "%(branch)s has no revision %(revision)s"
894
1114
 
895
1115
    def __init__(self, branch, revision):
 
1116
        # 'branch' may sometimes be an internal object like a KnitRevisionStore
896
1117
        BzrError.__init__(self, branch=branch, revision=revision)
897
1118
 
898
1119
 
899
 
class NotLeftParentDescendant(BzrError):
900
 
 
901
 
    _fmt = ("Revision %(old_revision)s is not the left parent of"
902
 
            " %(new_revision)s, but branch %(branch_location)s expects this")
903
 
 
904
 
    internal_error = True
905
 
 
906
 
    def __init__(self, branch, old_revision, new_revision):
907
 
        BzrError.__init__(self, branch_location=branch.base,
908
 
                          old_revision=old_revision,
909
 
                          new_revision=new_revision)
 
1120
class RangeInChangeOption(BzrError):
 
1121
 
 
1122
    _fmt = "Option --change does not accept revision ranges"
910
1123
 
911
1124
 
912
1125
class NoSuchRevisionSpec(BzrError):
919
1132
 
920
1133
class NoSuchRevisionInTree(NoSuchRevision):
921
1134
    """When using Tree.revision_tree, and the revision is not accessible."""
922
 
    
923
 
    _fmt = "The revision id %(revision_id)s is not present in the tree %(tree)s."
 
1135
 
 
1136
    _fmt = "The revision id {%(revision_id)s} is not present in the tree %(tree)s."
924
1137
 
925
1138
    def __init__(self, tree, revision_id):
926
1139
        BzrError.__init__(self)
930
1143
 
931
1144
class InvalidRevisionSpec(BzrError):
932
1145
 
933
 
    _fmt = ("Requested revision: %(spec)r does not exist in branch:"
934
 
            " %(branch)s%(extra)s")
 
1146
    _fmt = ("Requested revision: '%(spec)s' does not exist in branch:"
 
1147
            " %(branch_url)s%(extra)s")
935
1148
 
936
1149
    def __init__(self, spec, branch, extra=None):
937
1150
        BzrError.__init__(self, branch=branch, spec=spec)
 
1151
        self.branch_url = getattr(branch, 'user_url', str(branch))
938
1152
        if extra:
939
1153
            self.extra = '\n' + str(extra)
940
1154
        else:
941
1155
            self.extra = ''
942
1156
 
943
1157
 
944
 
class HistoryMissing(BzrError):
945
 
 
946
 
    _fmt = "%(branch)s is missing %(object_type)s {%(object_id)s}"
947
 
 
948
 
 
949
1158
class AppendRevisionsOnlyViolation(BzrError):
950
1159
 
951
1160
    _fmt = ('Operation denied because it would change the main history,'
961
1170
class DivergedBranches(BzrError):
962
1171
 
963
1172
    _fmt = ("These branches have diverged."
964
 
            " Use the merge command to reconcile them.")
965
 
 
966
 
    internal_error = False
 
1173
            " Use the missing command to see how.\n"
 
1174
            "Use the merge command to reconcile them.")
967
1175
 
968
1176
    def __init__(self, branch1, branch2):
969
1177
        self.branch1 = branch1
970
1178
        self.branch2 = branch2
971
1179
 
972
1180
 
973
 
class NotLefthandHistory(BzrError):
 
1181
class NotLefthandHistory(InternalBzrError):
974
1182
 
975
1183
    _fmt = "Supplied history does not follow left-hand parents"
976
1184
 
977
 
    internal_error = True
978
 
 
979
1185
    def __init__(self, history):
980
1186
        BzrError.__init__(self, history=history)
981
1187
 
985
1191
    _fmt = ("Branches have no common ancestor, and"
986
1192
            " no merge base revision was specified.")
987
1193
 
988
 
    internal_error = False
 
1194
 
 
1195
class CannotReverseCherrypick(BzrError):
 
1196
 
 
1197
    _fmt = ('Selected merge cannot perform reverse cherrypicks.  Try merge3'
 
1198
            ' or diff3.')
989
1199
 
990
1200
 
991
1201
class NoCommonAncestor(BzrError):
992
 
    
 
1202
 
993
1203
    _fmt = "Revisions have no common ancestor: %(revision_a)s %(revision_b)s"
994
1204
 
995
1205
    def __init__(self, revision_a, revision_b):
1015
1225
            not_ancestor_id=not_ancestor_id)
1016
1226
 
1017
1227
 
1018
 
class InstallFailed(BzrError):
1019
 
 
1020
 
    def __init__(self, revisions):
1021
 
        revision_str = ", ".join(str(r) for r in revisions)
1022
 
        msg = "Could not install revisions:\n%s" % revision_str
1023
 
        BzrError.__init__(self, msg)
1024
 
        self.revisions = revisions
1025
 
 
1026
 
 
1027
 
class AmbiguousBase(BzrError):
1028
 
 
1029
 
    def __init__(self, bases):
1030
 
        warn("BzrError AmbiguousBase has been deprecated as of bzrlib 0.8.",
1031
 
                DeprecationWarning)
1032
 
        msg = ("The correct base is unclear, because %s are all equally close"
1033
 
                % ", ".join(bases))
1034
 
        BzrError.__init__(self, msg)
1035
 
        self.bases = bases
1036
 
 
1037
 
 
1038
 
class NoCommits(BzrError):
 
1228
class NoCommits(BranchError):
1039
1229
 
1040
1230
    _fmt = "Branch %(branch)s has no commits."
1041
1231
 
1042
 
    def __init__(self, branch):
1043
 
        BzrError.__init__(self, branch=branch)
1044
 
 
1045
1232
 
1046
1233
class UnlistableStore(BzrError):
1047
1234
 
1058
1245
 
1059
1246
class BoundBranchOutOfDate(BzrError):
1060
1247
 
1061
 
    _fmt = ("Bound branch %(branch)s is out of date"
1062
 
            " with master branch %(master)s.")
 
1248
    _fmt = ("Bound branch %(branch)s is out of date with master branch"
 
1249
            " %(master)s.%(extra_help)s")
1063
1250
 
1064
1251
    def __init__(self, branch, master):
1065
1252
        BzrError.__init__(self)
1066
1253
        self.branch = branch
1067
1254
        self.master = master
1068
 
 
1069
 
        
 
1255
        self.extra_help = ''
 
1256
 
 
1257
 
1070
1258
class CommitToDoubleBoundBranch(BzrError):
1071
1259
 
1072
1260
    _fmt = ("Cannot commit to branch %(branch)s."
1102
1290
 
1103
1291
class WeaveError(BzrError):
1104
1292
 
1105
 
    _fmt = "Error in processing weave: %(message)s"
 
1293
    _fmt = "Error in processing weave: %(msg)s"
1106
1294
 
1107
 
    def __init__(self, message=None):
 
1295
    def __init__(self, msg=None):
1108
1296
        BzrError.__init__(self)
1109
 
        self.message = message
 
1297
        self.msg = msg
1110
1298
 
1111
1299
 
1112
1300
class WeaveRevisionAlreadyPresent(WeaveError):
1141
1329
 
1142
1330
class WeaveParentMismatch(WeaveError):
1143
1331
 
1144
 
    _fmt = "Parents are mismatched between two revisions."
1145
 
    
 
1332
    _fmt = "Parents are mismatched between two revisions. %(msg)s"
 
1333
 
1146
1334
 
1147
1335
class WeaveInvalidChecksum(WeaveError):
1148
1336
 
1149
 
    _fmt = "Text did not match it's checksum: %(message)s"
 
1337
    _fmt = "Text did not match its checksum: %(msg)s"
1150
1338
 
1151
1339
 
1152
1340
class WeaveTextDiffers(WeaveError):
1174
1362
 
1175
1363
 
1176
1364
class VersionedFileError(BzrError):
1177
 
    
 
1365
 
1178
1366
    _fmt = "Versioned file error"
1179
1367
 
1180
1368
 
1181
1369
class RevisionNotPresent(VersionedFileError):
1182
 
    
1183
 
    _fmt = "Revision {%(revision_id)s} not present in %(file_id)s."
 
1370
 
 
1371
    _fmt = 'Revision {%(revision_id)s} not present in "%(file_id)s".'
1184
1372
 
1185
1373
    def __init__(self, revision_id, file_id):
1186
1374
        VersionedFileError.__init__(self)
1189
1377
 
1190
1378
 
1191
1379
class RevisionAlreadyPresent(VersionedFileError):
1192
 
    
1193
 
    _fmt = "Revision {%(revision_id)s} already present in %(file_id)s."
 
1380
 
 
1381
    _fmt = 'Revision {%(revision_id)s} already present in "%(file_id)s".'
1194
1382
 
1195
1383
    def __init__(self, revision_id, file_id):
1196
1384
        VersionedFileError.__init__(self)
1198
1386
        self.file_id = file_id
1199
1387
 
1200
1388
 
1201
 
class KnitError(BzrError):
1202
 
    
 
1389
class VersionedFileInvalidChecksum(VersionedFileError):
 
1390
 
 
1391
    _fmt = "Text did not match its checksum: %(msg)s"
 
1392
 
 
1393
 
 
1394
class KnitError(InternalBzrError):
 
1395
 
1203
1396
    _fmt = "Knit error"
1204
1397
 
1205
 
    internal_error = True
1206
 
 
1207
 
 
1208
 
class KnitHeaderError(KnitError):
1209
 
 
1210
 
    _fmt = "Knit header error: %(badline)r unexpected for file %(filename)s"
1211
 
 
1212
 
    def __init__(self, badline, filename):
1213
 
        KnitError.__init__(self)
1214
 
        self.badline = badline
1215
 
        self.filename = filename
1216
 
 
1217
1398
 
1218
1399
class KnitCorrupt(KnitError):
1219
1400
 
1225
1406
        self.how = how
1226
1407
 
1227
1408
 
 
1409
class SHA1KnitCorrupt(KnitCorrupt):
 
1410
 
 
1411
    _fmt = ("Knit %(filename)s corrupt: sha-1 of reconstructed text does not "
 
1412
        "match expected sha-1. key %(key)s expected sha %(expected)s actual "
 
1413
        "sha %(actual)s")
 
1414
 
 
1415
    def __init__(self, filename, actual, expected, key, content):
 
1416
        KnitError.__init__(self)
 
1417
        self.filename = filename
 
1418
        self.actual = actual
 
1419
        self.expected = expected
 
1420
        self.key = key
 
1421
        self.content = content
 
1422
 
 
1423
 
 
1424
class KnitDataStreamIncompatible(KnitError):
 
1425
    # Not raised anymore, as we can convert data streams.  In future we may
 
1426
    # need it again for more exotic cases, so we're keeping it around for now.
 
1427
 
 
1428
    _fmt = "Cannot insert knit data stream of format \"%(stream_format)s\" into knit of format \"%(target_format)s\"."
 
1429
 
 
1430
    def __init__(self, stream_format, target_format):
 
1431
        self.stream_format = stream_format
 
1432
        self.target_format = target_format
 
1433
 
 
1434
 
 
1435
class KnitDataStreamUnknown(KnitError):
 
1436
    # Indicates a data stream we don't know how to handle.
 
1437
 
 
1438
    _fmt = "Cannot parse knit data stream of format \"%(stream_format)s\"."
 
1439
 
 
1440
    def __init__(self, stream_format):
 
1441
        self.stream_format = stream_format
 
1442
 
 
1443
 
 
1444
class KnitHeaderError(KnitError):
 
1445
 
 
1446
    _fmt = 'Knit header error: %(badline)r unexpected for file "%(filename)s".'
 
1447
 
 
1448
    def __init__(self, badline, filename):
 
1449
        KnitError.__init__(self)
 
1450
        self.badline = badline
 
1451
        self.filename = filename
 
1452
 
1228
1453
class KnitIndexUnknownMethod(KnitError):
1229
1454
    """Raised when we don't understand the storage method.
1230
1455
 
1231
1456
    Currently only 'fulltext' and 'line-delta' are supported.
1232
1457
    """
1233
 
    
 
1458
 
1234
1459
    _fmt = ("Knit index %(filename)s does not have a known method"
1235
1460
            " in options: %(options)r")
1236
1461
 
1240
1465
        self.options = options
1241
1466
 
1242
1467
 
 
1468
class RetryWithNewPacks(BzrError):
 
1469
    """Raised when we realize that the packs on disk have changed.
 
1470
 
 
1471
    This is meant as more of a signaling exception, to trap between where a
 
1472
    local error occurred and the code that can actually handle the error and
 
1473
    code that can retry appropriately.
 
1474
    """
 
1475
 
 
1476
    internal_error = True
 
1477
 
 
1478
    _fmt = ("Pack files have changed, reload and retry. context: %(context)s"
 
1479
            " %(orig_error)s")
 
1480
 
 
1481
    def __init__(self, context, reload_occurred, exc_info):
 
1482
        """create a new RetryWithNewPacks error.
 
1483
 
 
1484
        :param reload_occurred: Set to True if we know that the packs have
 
1485
            already been reloaded, and we are failing because of an in-memory
 
1486
            cache miss. If set to True then we will ignore if a reload says
 
1487
            nothing has changed, because we assume it has already reloaded. If
 
1488
            False, then a reload with nothing changed will force an error.
 
1489
        :param exc_info: The original exception traceback, so if there is a
 
1490
            problem we can raise the original error (value from sys.exc_info())
 
1491
        """
 
1492
        BzrError.__init__(self)
 
1493
        self.context = context
 
1494
        self.reload_occurred = reload_occurred
 
1495
        self.exc_info = exc_info
 
1496
        self.orig_error = exc_info[1]
 
1497
        # TODO: The global error handler should probably treat this by
 
1498
        #       raising/printing the original exception with a bit about
 
1499
        #       RetryWithNewPacks also not being caught
 
1500
 
 
1501
 
 
1502
class RetryAutopack(RetryWithNewPacks):
 
1503
    """Raised when we are autopacking and we find a missing file.
 
1504
 
 
1505
    Meant as a signaling exception, to tell the autopack code it should try
 
1506
    again.
 
1507
    """
 
1508
 
 
1509
    internal_error = True
 
1510
 
 
1511
    _fmt = ("Pack files have changed, reload and try autopack again."
 
1512
            " context: %(context)s %(orig_error)s")
 
1513
 
 
1514
 
1243
1515
class NoSuchExportFormat(BzrError):
1244
 
    
 
1516
 
1245
1517
    _fmt = "Export format %(format)r not supported"
1246
1518
 
1247
1519
    def __init__(self, format):
1250
1522
 
1251
1523
 
1252
1524
class TransportError(BzrError):
1253
 
    
 
1525
 
1254
1526
    _fmt = "Transport error: %(msg)s %(orig_error)s"
1255
1527
 
1256
1528
    def __init__(self, msg=None, orig_error=None):
1265
1537
        BzrError.__init__(self)
1266
1538
 
1267
1539
 
1268
 
class TooManyConcurrentRequests(BzrError):
 
1540
class TooManyConcurrentRequests(InternalBzrError):
1269
1541
 
1270
1542
    _fmt = ("The medium '%(medium)s' has reached its concurrent request limit."
1271
1543
            " Be sure to finish_writing and finish_reading on the"
1272
1544
            " currently open request.")
1273
1545
 
1274
 
    internal_error = True
1275
 
 
1276
1546
    def __init__(self, medium):
1277
1547
        self.medium = medium
1278
1548
 
1285
1555
        self.details = details
1286
1556
 
1287
1557
 
 
1558
class UnexpectedProtocolVersionMarker(TransportError):
 
1559
 
 
1560
    _fmt = "Received bad protocol version marker: %(marker)r"
 
1561
 
 
1562
    def __init__(self, marker):
 
1563
        self.marker = marker
 
1564
 
 
1565
 
 
1566
class UnknownSmartMethod(InternalBzrError):
 
1567
 
 
1568
    _fmt = "The server does not recognise the '%(verb)s' request."
 
1569
 
 
1570
    def __init__(self, verb):
 
1571
        self.verb = verb
 
1572
 
 
1573
 
 
1574
class SmartMessageHandlerError(InternalBzrError):
 
1575
 
 
1576
    _fmt = ("The message handler raised an exception:\n"
 
1577
            "%(traceback_text)s")
 
1578
 
 
1579
    def __init__(self, exc_info):
 
1580
        import traceback
 
1581
        # GZ 2010-08-10: Cycle with exc_tb/exc_info affects at least one test
 
1582
        self.exc_type, self.exc_value, self.exc_tb = exc_info
 
1583
        self.exc_info = exc_info
 
1584
        traceback_strings = traceback.format_exception(
 
1585
                self.exc_type, self.exc_value, self.exc_tb)
 
1586
        self.traceback_text = ''.join(traceback_strings)
 
1587
 
 
1588
 
1288
1589
# A set of semi-meaningful errors which can be thrown
1289
1590
class TransportNotPossible(TransportError):
1290
1591
 
1315
1616
            self.port = ':%s' % port
1316
1617
 
1317
1618
 
 
1619
# XXX: This is also used for unexpected end of file, which is different at the
 
1620
# TCP level from "connection reset".
1318
1621
class ConnectionReset(TransportError):
1319
1622
 
1320
1623
    _fmt = "Connection closed: %(msg)s %(orig_error)s"
1321
1624
 
1322
1625
 
 
1626
class ConnectionTimeout(ConnectionError):
 
1627
 
 
1628
    _fmt = "Connection Timeout: %(msg)s%(orig_error)s"
 
1629
 
 
1630
 
1323
1631
class InvalidRange(TransportError):
1324
1632
 
1325
 
    _fmt = "Invalid range access in %(path)s at %(offset)s."
1326
 
    
1327
 
    def __init__(self, path, offset):
1328
 
        TransportError.__init__(self, ("Invalid range access in %s at %d"
1329
 
                                       % (path, offset)))
 
1633
    _fmt = "Invalid range access in %(path)s at %(offset)s: %(msg)s"
 
1634
 
 
1635
    def __init__(self, path, offset, msg=None):
 
1636
        TransportError.__init__(self, msg)
1330
1637
        self.path = path
1331
1638
        self.offset = offset
1332
1639
 
1333
1640
 
1334
1641
class InvalidHttpResponse(TransportError):
1335
1642
 
1336
 
    _fmt = "Invalid http response for %(path)s: %(msg)s"
 
1643
    _fmt = "Invalid http response for %(path)s: %(msg)s%(orig_error)s"
1337
1644
 
1338
1645
    def __init__(self, path, msg, orig_error=None):
1339
1646
        self.path = path
 
1647
        if orig_error is None:
 
1648
            orig_error = ''
 
1649
        else:
 
1650
            # This is reached for obscure and unusual errors so we want to
 
1651
            # preserve as much info as possible to ease debug.
 
1652
            orig_error = ': %r' % (orig_error,)
1340
1653
        TransportError.__init__(self, msg, orig_error=orig_error)
1341
1654
 
1342
1655
 
1343
1656
class InvalidHttpRange(InvalidHttpResponse):
1344
1657
 
1345
1658
    _fmt = "Invalid http range %(range)r for %(path)s: %(msg)s"
1346
 
    
 
1659
 
1347
1660
    def __init__(self, path, range, msg):
1348
1661
        self.range = range
1349
1662
        InvalidHttpResponse.__init__(self, path, msg)
1350
1663
 
1351
1664
 
 
1665
class HttpBoundaryMissing(InvalidHttpResponse):
 
1666
    """A multipart response ends with no boundary marker.
 
1667
 
 
1668
    This is a special case caused by buggy proxies, described in
 
1669
    <https://bugs.launchpad.net/bzr/+bug/198646>.
 
1670
    """
 
1671
 
 
1672
    _fmt = "HTTP MIME Boundary missing for %(path)s: %(msg)s"
 
1673
 
 
1674
    def __init__(self, path, msg):
 
1675
        InvalidHttpResponse.__init__(self, path, msg)
 
1676
 
 
1677
 
1352
1678
class InvalidHttpContentType(InvalidHttpResponse):
1353
1679
 
1354
1680
    _fmt = 'Invalid http Content-type "%(ctype)s" for %(path)s: %(msg)s'
1355
 
    
 
1681
 
1356
1682
    def __init__(self, path, ctype, msg):
1357
1683
        self.ctype = ctype
1358
1684
        InvalidHttpResponse.__init__(self, path, msg)
1362
1688
 
1363
1689
    _fmt = '%(source)s is%(permanently)s redirected to %(target)s'
1364
1690
 
1365
 
    def __init__(self, source, target, is_permament=False, qual_proto=None):
 
1691
    def __init__(self, source, target, is_permanent=False):
1366
1692
        self.source = source
1367
1693
        self.target = target
1368
 
        if is_permament:
 
1694
        if is_permanent:
1369
1695
            self.permanently = ' permanently'
1370
1696
        else:
1371
1697
            self.permanently = ''
1372
 
        self.is_permament = is_permament
1373
 
        self._qualified_proto = qual_proto
1374
1698
        TransportError.__init__(self)
1375
1699
 
1376
 
    def _requalify_url(self, url):
1377
 
        """Restore the qualified proto in front of the url"""
1378
 
        # When this exception is raised, source and target are in
1379
 
        # user readable format. But some transports may use a
1380
 
        # different proto (http+urllib:// will present http:// to
1381
 
        # the user. If a qualified proto is specified, the code
1382
 
        # trapping the exception can get the qualified urls to
1383
 
        # properly handle the redirection themself (creating a
1384
 
        # new transport object from the target url for example).
1385
 
        # But checking that the scheme of the original and
1386
 
        # redirected urls are the same can be tricky. (see the
1387
 
        # FIXME in BzrDir.open_from_transport for the unique use
1388
 
        # case so far).
1389
 
        if self._qualified_proto is None:
1390
 
            return url
1391
 
 
1392
 
        # The TODO related to NotBranchError mention that doing
1393
 
        # that kind of manipulation on the urls may not be the
1394
 
        # exception object job. On the other hand, this object is
1395
 
        # the interface between the code and the user so
1396
 
        # presenting the urls in different ways is indeed its
1397
 
        # job...
1398
 
        import urlparse
1399
 
        proto, netloc, path, query, fragment = urlparse.urlsplit(url)
1400
 
        return urlparse.urlunsplit((self._qualified_proto, netloc, path,
1401
 
                                   query, fragment))
1402
 
 
1403
 
    def get_source_url(self):
1404
 
        return self._requalify_url(self.source)
1405
 
 
1406
 
    def get_target_url(self):
1407
 
        return self._requalify_url(self.target)
1408
 
 
1409
1700
 
1410
1701
class TooManyRedirections(TransportError):
1411
1702
 
1412
1703
    _fmt = "Too many redirections"
1413
1704
 
 
1705
 
1414
1706
class ConflictsInTree(BzrError):
1415
1707
 
1416
1708
    _fmt = "Working tree has conflicts."
1417
1709
 
1418
1710
 
 
1711
class ConfigContentError(BzrError):
 
1712
 
 
1713
    _fmt = "Config file %(filename)s is not UTF-8 encoded\n"
 
1714
 
 
1715
    def __init__(self, filename):
 
1716
        BzrError.__init__(self)
 
1717
        self.filename = filename
 
1718
 
 
1719
 
1419
1720
class ParseConfigError(BzrError):
1420
1721
 
 
1722
    _fmt = "Error(s) parsing config file %(filename)s:\n%(errors)s"
 
1723
 
1421
1724
    def __init__(self, errors, filename):
1422
 
        if filename is None:
1423
 
            filename = ""
1424
 
        message = "Error(s) parsing config file %s:\n%s" % \
1425
 
            (filename, ('\n'.join(e.message for e in errors)))
1426
 
        BzrError.__init__(self, message)
 
1725
        BzrError.__init__(self)
 
1726
        self.filename = filename
 
1727
        self.errors = '\n'.join(e.msg for e in errors)
 
1728
 
 
1729
 
 
1730
class ConfigOptionValueError(BzrError):
 
1731
 
 
1732
    _fmt = """Bad value "%(value)s" for option "%(name)s"."""
 
1733
 
 
1734
    def __init__(self, name, value):
 
1735
        BzrError.__init__(self, name=name, value=value)
1427
1736
 
1428
1737
 
1429
1738
class NoEmailInUsername(BzrError):
1437
1746
 
1438
1747
class SigningFailed(BzrError):
1439
1748
 
1440
 
    _fmt = "Failed to gpg sign data with command %(command_line)r"
 
1749
    _fmt = 'Failed to GPG sign data with command "%(command_line)s"'
1441
1750
 
1442
1751
    def __init__(self, command_line):
1443
1752
        BzrError.__init__(self, command_line=command_line)
1444
1753
 
1445
1754
 
 
1755
class SignatureVerificationFailed(BzrError):
 
1756
 
 
1757
    _fmt = 'Failed to verify GPG signature data with error "%(error)s"'
 
1758
 
 
1759
    def __init__(self, error):
 
1760
        BzrError.__init__(self, error=error)
 
1761
 
 
1762
 
 
1763
class DependencyNotPresent(BzrError):
 
1764
 
 
1765
    _fmt = 'Unable to import library "%(library)s": %(error)s'
 
1766
 
 
1767
    def __init__(self, library, error):
 
1768
        BzrError.__init__(self, library=library, error=error)
 
1769
 
 
1770
 
 
1771
class GpgmeNotInstalled(DependencyNotPresent):
 
1772
 
 
1773
    _fmt = 'python-gpgme is not installed, it is needed to verify signatures'
 
1774
 
 
1775
    def __init__(self, error):
 
1776
        DependencyNotPresent.__init__(self, 'gpgme', error)
 
1777
 
 
1778
 
1446
1779
class WorkingTreeNotRevision(BzrError):
1447
1780
 
1448
 
    _fmt = ("The working tree for %(basedir)s has changed since" 
 
1781
    _fmt = ("The working tree for %(basedir)s has changed since"
1449
1782
            " the last commit, but weave merge requires that it be"
1450
1783
            " unchanged")
1451
1784
 
1468
1801
        self.graph = graph
1469
1802
 
1470
1803
 
1471
 
class WritingCompleted(BzrError):
 
1804
class WritingCompleted(InternalBzrError):
1472
1805
 
1473
1806
    _fmt = ("The MediumRequest '%(request)s' has already had finish_writing "
1474
1807
            "called upon it - accept bytes may not be called anymore.")
1475
1808
 
1476
 
    internal_error = True
1477
 
 
1478
1809
    def __init__(self, request):
1479
1810
        self.request = request
1480
1811
 
1481
1812
 
1482
 
class WritingNotComplete(BzrError):
 
1813
class WritingNotComplete(InternalBzrError):
1483
1814
 
1484
1815
    _fmt = ("The MediumRequest '%(request)s' has not has finish_writing "
1485
1816
            "called upon it - until the write phase is complete no "
1486
1817
            "data may be read.")
1487
1818
 
1488
 
    internal_error = True
1489
 
 
1490
1819
    def __init__(self, request):
1491
1820
        self.request = request
1492
1821
 
1500
1829
        self.filename = filename
1501
1830
 
1502
1831
 
1503
 
class MediumNotConnected(BzrError):
 
1832
class MediumNotConnected(InternalBzrError):
1504
1833
 
1505
1834
    _fmt = """The medium '%(medium)s' is not connected."""
1506
1835
 
1507
 
    internal_error = True
1508
 
 
1509
1836
    def __init__(self, medium):
1510
1837
        self.medium = medium
1511
1838
 
1517
1844
 
1518
1845
class NoBundleFound(BzrError):
1519
1846
 
1520
 
    _fmt = "No bundle was found in %(filename)s"
 
1847
    _fmt = 'No bundle was found in "%(filename)s".'
1521
1848
 
1522
1849
    def __init__(self, filename):
1523
1850
        BzrError.__init__(self)
1570
1897
        self.prefix = prefix
1571
1898
 
1572
1899
 
1573
 
class MalformedTransform(BzrError):
 
1900
class MalformedTransform(InternalBzrError):
1574
1901
 
1575
1902
    _fmt = "Tree transform is malformed %(conflicts)r"
1576
1903
 
1587
1914
        self.root_trans_id = transform.root
1588
1915
 
1589
1916
 
1590
 
class BzrBadParameter(BzrError):
 
1917
class BzrBadParameter(InternalBzrError):
1591
1918
 
1592
1919
    _fmt = "Bad parameter: %(param)r"
1593
1920
 
1594
 
    internal_error = True
1595
 
 
1596
1921
    # This exception should never be thrown, but it is a base class for all
1597
1922
    # parameter-to-function errors.
1598
1923
 
1616
1941
    _fmt = "Moving the root directory is not supported at this time"
1617
1942
 
1618
1943
 
 
1944
class TransformRenameFailed(BzrError):
 
1945
 
 
1946
    _fmt = "Failed to rename %(from_path)s to %(to_path)s: %(why)s"
 
1947
 
 
1948
    def __init__(self, from_path, to_path, why, errno):
 
1949
        self.from_path = from_path
 
1950
        self.to_path = to_path
 
1951
        self.why = why
 
1952
        self.errno = errno
 
1953
 
 
1954
 
1619
1955
class BzrMoveFailedError(BzrError):
1620
1956
 
1621
 
    _fmt = "Could not move %(from_path)s%(operator)s %(to_path)s%(extra)s"
 
1957
    _fmt = ("Could not move %(from_path)s%(operator)s %(to_path)s"
 
1958
        "%(_has_extra)s%(extra)s")
1622
1959
 
1623
1960
    def __init__(self, from_path='', to_path='', extra=None):
 
1961
        from bzrlib.osutils import splitpath
1624
1962
        BzrError.__init__(self)
1625
1963
        if extra:
1626
 
            self.extra = ': ' + str(extra)
 
1964
            self.extra, self._has_extra = extra, ': '
1627
1965
        else:
1628
 
            self.extra = ''
 
1966
            self.extra = self._has_extra = ''
1629
1967
 
1630
1968
        has_from = len(from_path) > 0
1631
1969
        has_to = len(to_path) > 0
1632
1970
        if has_from:
1633
 
            self.from_path = osutils.splitpath(from_path)[-1]
 
1971
            self.from_path = splitpath(from_path)[-1]
1634
1972
        else:
1635
1973
            self.from_path = ''
1636
1974
 
1637
1975
        if has_to:
1638
 
            self.to_path = osutils.splitpath(to_path)[-1]
 
1976
            self.to_path = splitpath(to_path)[-1]
1639
1977
        else:
1640
1978
            self.to_path = ''
1641
1979
 
1652
1990
 
1653
1991
class BzrRenameFailedError(BzrMoveFailedError):
1654
1992
 
1655
 
    _fmt = "Could not rename %(from_path)s%(operator)s %(to_path)s%(extra)s"
 
1993
    _fmt = ("Could not rename %(from_path)s%(operator)s %(to_path)s"
 
1994
        "%(_has_extra)s%(extra)s")
1656
1995
 
1657
1996
    def __init__(self, from_path, to_path, extra=None):
1658
1997
        BzrMoveFailedError.__init__(self, from_path, to_path, extra)
1659
1998
 
1660
 
class BzrRemoveChangedFilesError(BzrError):
1661
 
    """Used when user is trying to remove changed files."""
1662
 
 
1663
 
    _fmt = ("Can't remove changed or unknown files:\n%(changes_as_text)s"
1664
 
        "Use --keep to not delete them, or --force to delete them regardless.")
1665
 
 
1666
 
    def __init__(self, tree_delta):
1667
 
        BzrError.__init__(self)
1668
 
        self.changes_as_text = tree_delta.get_changes_as_text()
1669
 
        #self.paths_as_string = '\n'.join(changed_files)
1670
 
        #self.paths_as_string = '\n'.join([quotefn(p) for p in changed_files])
1671
 
 
1672
1999
 
1673
2000
class BzrBadParameterNotString(BzrBadParameter):
1674
2001
 
1677
2004
 
1678
2005
class BzrBadParameterMissing(BzrBadParameter):
1679
2006
 
1680
 
    _fmt = "Parameter $(param)s is required but not present."
 
2007
    _fmt = "Parameter %(param)s is required but not present."
1681
2008
 
1682
2009
 
1683
2010
class BzrBadParameterUnicode(BzrBadParameter):
1691
2018
    _fmt = "Parameter %(param)s contains a newline."
1692
2019
 
1693
2020
 
1694
 
class DependencyNotPresent(BzrError):
1695
 
 
1696
 
    _fmt = 'Unable to import library "%(library)s": %(error)s'
1697
 
 
1698
 
    def __init__(self, library, error):
1699
 
        BzrError.__init__(self, library=library, error=error)
1700
 
 
1701
 
 
1702
2021
class ParamikoNotPresent(DependencyNotPresent):
1703
2022
 
1704
2023
    _fmt = "Unable to import paramiko (required for sftp support): %(error)s"
1723
2042
 
1724
2043
class BadConversionTarget(BzrError):
1725
2044
 
1726
 
    _fmt = "Cannot convert to format %(format)s.  %(problem)s"
 
2045
    _fmt = "Cannot convert from format %(from_format)s to format %(format)s." \
 
2046
            "    %(problem)s"
1727
2047
 
1728
 
    def __init__(self, problem, format):
 
2048
    def __init__(self, problem, format, from_format=None):
1729
2049
        BzrError.__init__(self)
1730
2050
        self.problem = problem
1731
2051
        self.format = format
 
2052
        self.from_format = from_format or '(unspecified)'
 
2053
 
 
2054
 
 
2055
class NoDiffFound(BzrError):
 
2056
 
 
2057
    _fmt = 'Could not find an appropriate Differ for file "%(path)s"'
 
2058
 
 
2059
    def __init__(self, path):
 
2060
        BzrError.__init__(self, path)
 
2061
 
 
2062
 
 
2063
class ExecutableMissing(BzrError):
 
2064
 
 
2065
    _fmt = "%(exe_name)s could not be found on this machine"
 
2066
 
 
2067
    def __init__(self, exe_name):
 
2068
        BzrError.__init__(self, exe_name=exe_name)
1732
2069
 
1733
2070
 
1734
2071
class NoDiff(BzrError):
1744
2081
    _fmt = "Diff3 is not installed on this machine."
1745
2082
 
1746
2083
 
 
2084
class ExistingContent(BzrError):
 
2085
    # Added in bzrlib 0.92, used by VersionedFile.add_lines.
 
2086
 
 
2087
    _fmt = "The content being inserted is already present."
 
2088
 
 
2089
 
1747
2090
class ExistingLimbo(BzrError):
1748
2091
 
1749
2092
    _fmt = """This tree contains left-over files from a failed operation.
1750
2093
    Please examine %(limbo_dir)s to see if it contains any files you wish to
1751
2094
    keep, and delete it when you are done."""
1752
 
    
 
2095
 
1753
2096
    def __init__(self, limbo_dir):
1754
2097
       BzrError.__init__(self)
1755
2098
       self.limbo_dir = limbo_dir
1756
2099
 
1757
2100
 
 
2101
class ExistingPendingDeletion(BzrError):
 
2102
 
 
2103
    _fmt = """This tree contains left-over files from a failed operation.
 
2104
    Please examine %(pending_deletion)s to see if it contains any files you
 
2105
    wish to keep, and delete it when you are done."""
 
2106
 
 
2107
    def __init__(self, pending_deletion):
 
2108
       BzrError.__init__(self, pending_deletion=pending_deletion)
 
2109
 
 
2110
 
1758
2111
class ImmortalLimbo(BzrError):
1759
2112
 
1760
 
    _fmt = """Unable to delete transform temporary directory $(limbo_dir)s.
 
2113
    _fmt = """Unable to delete transform temporary directory %(limbo_dir)s.
1761
2114
    Please examine %(limbo_dir)s to see if it contains any files you wish to
1762
2115
    keep, and delete it when you are done."""
1763
2116
 
1766
2119
       self.limbo_dir = limbo_dir
1767
2120
 
1768
2121
 
 
2122
class ImmortalPendingDeletion(BzrError):
 
2123
 
 
2124
    _fmt = ("Unable to delete transform temporary directory "
 
2125
    "%(pending_deletion)s.  Please examine %(pending_deletion)s to see if it "
 
2126
    "contains any files you wish to keep, and delete it when you are done.")
 
2127
 
 
2128
    def __init__(self, pending_deletion):
 
2129
       BzrError.__init__(self, pending_deletion=pending_deletion)
 
2130
 
 
2131
 
1769
2132
class OutOfDateTree(BzrError):
1770
2133
 
1771
 
    _fmt = "Working tree is out of date, please run 'bzr update'."
 
2134
    _fmt = "Working tree is out of date, please run 'bzr update'.%(more)s"
1772
2135
 
1773
 
    def __init__(self, tree):
 
2136
    def __init__(self, tree, more=None):
 
2137
        if more is None:
 
2138
            more = ''
 
2139
        else:
 
2140
            more = ' ' + more
1774
2141
        BzrError.__init__(self)
1775
2142
        self.tree = tree
 
2143
        self.more = more
1776
2144
 
1777
2145
 
1778
2146
class PublicBranchOutOfDate(BzrError):
1798
2166
    _fmt = "Format error in conflict listings"
1799
2167
 
1800
2168
 
 
2169
class CorruptDirstate(BzrError):
 
2170
 
 
2171
    _fmt = ("Inconsistency in dirstate file %(dirstate_path)s.\n"
 
2172
            "Error: %(description)s")
 
2173
 
 
2174
    def __init__(self, dirstate_path, description):
 
2175
        BzrError.__init__(self)
 
2176
        self.dirstate_path = dirstate_path
 
2177
        self.description = description
 
2178
 
 
2179
 
1801
2180
class CorruptRepository(BzrError):
1802
2181
 
1803
2182
    _fmt = ("An error has been detected in the repository %(repo_path)s.\n"
1805
2184
 
1806
2185
    def __init__(self, repo):
1807
2186
        BzrError.__init__(self)
1808
 
        self.repo_path = repo.bzrdir.root_transport.base
 
2187
        self.repo_path = repo.user_url
 
2188
 
 
2189
 
 
2190
class InconsistentDelta(BzrError):
 
2191
    """Used when we get a delta that is not valid."""
 
2192
 
 
2193
    _fmt = ("An inconsistent delta was supplied involving %(path)r,"
 
2194
            " %(file_id)r\nreason: %(reason)s")
 
2195
 
 
2196
    def __init__(self, path, file_id, reason):
 
2197
        BzrError.__init__(self)
 
2198
        self.path = path
 
2199
        self.file_id = file_id
 
2200
        self.reason = reason
 
2201
 
 
2202
 
 
2203
class InconsistentDeltaDelta(InconsistentDelta):
 
2204
    """Used when we get a delta that is not valid."""
 
2205
 
 
2206
    _fmt = ("An inconsistent delta was supplied: %(delta)r"
 
2207
            "\nreason: %(reason)s")
 
2208
 
 
2209
    def __init__(self, delta, reason):
 
2210
        BzrError.__init__(self)
 
2211
        self.delta = delta
 
2212
        self.reason = reason
1809
2213
 
1810
2214
 
1811
2215
class UpgradeRequired(BzrError):
1817
2221
        self.path = path
1818
2222
 
1819
2223
 
 
2224
class RepositoryUpgradeRequired(UpgradeRequired):
 
2225
 
 
2226
    _fmt = "To use this feature you must upgrade your repository at %(path)s."
 
2227
 
 
2228
 
 
2229
class RichRootUpgradeRequired(UpgradeRequired):
 
2230
 
 
2231
    _fmt = ("To use this feature you must upgrade your branch at %(path)s to"
 
2232
           " a format which supports rich roots.")
 
2233
 
 
2234
 
1820
2235
class LocalRequiresBoundBranch(BzrError):
1821
2236
 
1822
2237
    _fmt = "Cannot perform local-only commits on unbound branches."
1823
2238
 
1824
2239
 
1825
 
class MissingProgressBarFinish(BzrError):
1826
 
 
1827
 
    _fmt = "A nested progress bar was not 'finished' correctly."
1828
 
 
1829
 
 
1830
 
class InvalidProgressBarType(BzrError):
1831
 
 
1832
 
    _fmt = ("Environment variable BZR_PROGRESS_BAR='%(bar_type)s"
1833
 
            " is not a supported type Select one of: %(valid_types)s")
1834
 
 
1835
 
    def __init__(self, bar_type, valid_types):
1836
 
        BzrError.__init__(self, bar_type=bar_type, valid_types=valid_types)
1837
 
 
1838
 
 
1839
2240
class UnsupportedOperation(BzrError):
1840
2241
 
1841
2242
    _fmt = ("The method %(mname)s is not supported on"
1857
2258
    """
1858
2259
 
1859
2260
 
 
2261
class GhostTagsNotSupported(BzrError):
 
2262
 
 
2263
    _fmt = "Ghost tags not supported by format %(format)r."
 
2264
 
 
2265
    def __init__(self, format):
 
2266
        self.format = format
 
2267
 
 
2268
 
1860
2269
class BinaryFile(BzrError):
1861
 
    
 
2270
 
1862
2271
    _fmt = "File is binary but should be text."
1863
2272
 
1864
2273
 
1884
2293
 
1885
2294
 
1886
2295
class NotABundle(BzrError):
1887
 
    
 
2296
 
1888
2297
    _fmt = "Not a bzr revision-bundle: %(text)r"
1889
2298
 
1890
2299
    def __init__(self, text):
1892
2301
        self.text = text
1893
2302
 
1894
2303
 
1895
 
class BadBundle(BzrError): 
1896
 
    
 
2304
class BadBundle(BzrError):
 
2305
 
1897
2306
    _fmt = "Bad bzr revision-bundle: %(text)r"
1898
2307
 
1899
2308
    def __init__(self, text):
1901
2310
        self.text = text
1902
2311
 
1903
2312
 
1904
 
class MalformedHeader(BadBundle): 
1905
 
    
 
2313
class MalformedHeader(BadBundle):
 
2314
 
1906
2315
    _fmt = "Malformed bzr revision-bundle header: %(text)r"
1907
2316
 
1908
2317
 
1909
 
class MalformedPatches(BadBundle): 
1910
 
    
 
2318
class MalformedPatches(BadBundle):
 
2319
 
1911
2320
    _fmt = "Malformed patches in bzr revision-bundle: %(text)r"
1912
2321
 
1913
2322
 
1914
 
class MalformedFooter(BadBundle): 
1915
 
    
 
2323
class MalformedFooter(BadBundle):
 
2324
 
1916
2325
    _fmt = "Malformed footer in bzr revision-bundle: %(text)r"
1917
2326
 
1918
2327
 
1919
2328
class UnsupportedEOLMarker(BadBundle):
1920
 
    
1921
 
    _fmt = "End of line marker was not \\n in bzr revision-bundle"    
 
2329
 
 
2330
    _fmt = "End of line marker was not \\n in bzr revision-bundle"
1922
2331
 
1923
2332
    def __init__(self):
1924
 
        # XXX: BadBundle's constructor assumes there's explanatory text, 
 
2333
        # XXX: BadBundle's constructor assumes there's explanatory text,
1925
2334
        # but for this there is not
1926
2335
        BzrError.__init__(self)
1927
2336
 
1928
2337
 
1929
2338
class IncompatibleBundleFormat(BzrError):
1930
 
    
 
2339
 
1931
2340
    _fmt = "Bundle format %(bundle_format)s is incompatible with %(other)s"
1932
2341
 
1933
2342
    def __init__(self, bundle_format, other):
1937
2346
 
1938
2347
 
1939
2348
class BadInventoryFormat(BzrError):
1940
 
    
 
2349
 
1941
2350
    _fmt = "Root class for inventory serialization errors"
1942
2351
 
1943
2352
 
1954
2363
    _fmt = """This operation requires rich root data storage"""
1955
2364
 
1956
2365
 
1957
 
class NoSmartMedium(BzrError):
 
2366
class NoSmartMedium(InternalBzrError):
1958
2367
 
1959
2368
    _fmt = "The transport '%(transport)s' cannot tunnel the smart protocol."
1960
2369
 
1961
 
    internal_error = True
1962
 
 
1963
2370
    def __init__(self, transport):
1964
2371
        self.transport = transport
1965
2372
 
1966
2373
 
1967
 
class NoSmartServer(NotBranchError):
1968
 
 
1969
 
    _fmt = "No smart server available at %(url)s"
1970
 
 
1971
 
    def __init__(self, url):
1972
 
        self.url = url
1973
 
 
1974
 
 
1975
2374
class UnknownSSH(BzrError):
1976
2375
 
1977
2376
    _fmt = "Unrecognised value for BZR_SSH environment variable: %(vendor)s"
1987
2386
            " Please set BZR_SSH environment variable.")
1988
2387
 
1989
2388
 
 
2389
class GhostRevisionsHaveNoRevno(BzrError):
 
2390
    """When searching for revnos, if we encounter a ghost, we are stuck"""
 
2391
 
 
2392
    _fmt = ("Could not determine revno for {%(revision_id)s} because"
 
2393
            " its ancestry shows a ghost at {%(ghost_revision_id)s}")
 
2394
 
 
2395
    def __init__(self, revision_id, ghost_revision_id):
 
2396
        self.revision_id = revision_id
 
2397
        self.ghost_revision_id = ghost_revision_id
 
2398
 
 
2399
 
1990
2400
class GhostRevisionUnusableHere(BzrError):
1991
2401
 
1992
2402
    _fmt = "Ghost revision {%(revision_id)s} cannot be used here."
1996
2406
        self.revision_id = revision_id
1997
2407
 
1998
2408
 
1999
 
class IllegalUseOfScopeReplacer(BzrError):
 
2409
class IllegalUseOfScopeReplacer(InternalBzrError):
2000
2410
 
2001
2411
    _fmt = ("ScopeReplacer object %(name)r was used incorrectly:"
2002
2412
            " %(msg)s%(extra)s")
2003
2413
 
2004
 
    internal_error = True
2005
 
 
2006
2414
    def __init__(self, name, msg, extra=None):
2007
2415
        BzrError.__init__(self)
2008
2416
        self.name = name
2013
2421
            self.extra = ''
2014
2422
 
2015
2423
 
2016
 
class InvalidImportLine(BzrError):
 
2424
class InvalidImportLine(InternalBzrError):
2017
2425
 
2018
2426
    _fmt = "Not a valid import statement: %(msg)\n%(text)s"
2019
2427
 
2020
 
    internal_error = True
2021
 
 
2022
2428
    def __init__(self, text, msg):
2023
2429
        BzrError.__init__(self)
2024
2430
        self.text = text
2025
2431
        self.msg = msg
2026
2432
 
2027
2433
 
2028
 
class ImportNameCollision(BzrError):
 
2434
class ImportNameCollision(InternalBzrError):
2029
2435
 
2030
2436
    _fmt = ("Tried to import an object to the same name as"
2031
2437
            " an existing object. %(name)s")
2032
2438
 
2033
 
    internal_error = True
2034
 
 
2035
2439
    def __init__(self, name):
2036
2440
        BzrError.__init__(self)
2037
2441
        self.name = name
2050
2454
        " branch location."
2051
2455
 
2052
2456
 
 
2457
class IllegalMergeDirectivePayload(BzrError):
 
2458
    """A merge directive contained something other than a patch or bundle"""
 
2459
 
 
2460
    _fmt = "Bad merge directive payload %(start)r"
 
2461
 
 
2462
    def __init__(self, start):
 
2463
        BzrError(self)
 
2464
        self.start = start
 
2465
 
 
2466
 
 
2467
class PatchVerificationFailed(BzrError):
 
2468
    """A patch from a merge directive could not be verified"""
 
2469
 
 
2470
    _fmt = "Preview patch does not match requested changes."
 
2471
 
 
2472
 
2053
2473
class PatchMissing(BzrError):
2054
2474
    """Raise a patch type was specified but no patch supplied"""
2055
2475
 
2056
 
    _fmt = "patch_type was %(patch_type)s, but no patch was supplied."
 
2476
    _fmt = "Patch_type was %(patch_type)s, but no patch was supplied."
2057
2477
 
2058
2478
    def __init__(self, patch_type):
2059
2479
        BzrError.__init__(self)
2060
2480
        self.patch_type = patch_type
2061
2481
 
2062
2482
 
 
2483
class TargetNotBranch(BzrError):
 
2484
    """A merge directive's target branch is required, but isn't a branch"""
 
2485
 
 
2486
    _fmt = ("Your branch does not have all of the revisions required in "
 
2487
            "order to merge this merge directive and the target "
 
2488
            "location specified in the merge directive is not a branch: "
 
2489
            "%(location)s.")
 
2490
 
 
2491
    def __init__(self, location):
 
2492
        BzrError.__init__(self)
 
2493
        self.location = location
 
2494
 
 
2495
 
2063
2496
class UnsupportedInventoryKind(BzrError):
2064
 
    
 
2497
 
2065
2498
    _fmt = """Unsupported entry kind %(kind)s"""
2066
2499
 
2067
2500
    def __init__(self, kind):
2070
2503
 
2071
2504
class BadSubsumeSource(BzrError):
2072
2505
 
2073
 
    _fmt = """Can't subsume %(other_tree)s into %(tree)s.  %(reason)s"""
 
2506
    _fmt = "Can't subsume %(other_tree)s into %(tree)s. %(reason)s"
2074
2507
 
2075
2508
    def __init__(self, tree, other_tree, reason):
2076
2509
        self.tree = tree
2079
2512
 
2080
2513
 
2081
2514
class SubsumeTargetNeedsUpgrade(BzrError):
2082
 
    
 
2515
 
2083
2516
    _fmt = """Subsume target %(other_tree)s needs to be upgraded."""
2084
2517
 
2085
2518
    def __init__(self, other_tree):
2086
2519
        self.other_tree = other_tree
2087
2520
 
2088
2521
 
2089
 
class BadReferenceTarget(BzrError):
2090
 
 
2091
 
    _fmt = "Can't add reference to %(other_tree)s into %(tree)s.  %(reason)s"
2092
 
 
2093
 
    internal_error = True
 
2522
class BadReferenceTarget(InternalBzrError):
 
2523
 
 
2524
    _fmt = "Can't add reference to %(other_tree)s into %(tree)s." \
 
2525
           "%(reason)s"
2094
2526
 
2095
2527
    def __init__(self, tree, other_tree, reason):
2096
2528
        self.tree = tree
2109
2541
class TagsNotSupported(BzrError):
2110
2542
 
2111
2543
    _fmt = ("Tags not supported by %(branch)s;"
2112
 
            " you may be able to use bzr upgrade --dirstate-tags.")
 
2544
            " you may be able to use bzr upgrade.")
2113
2545
 
2114
2546
    def __init__(self, branch):
2115
2547
        self.branch = branch
2116
2548
 
2117
 
        
 
2549
 
2118
2550
class TagAlreadyExists(BzrError):
2119
2551
 
2120
2552
    _fmt = "Tag %(tag_name)s already exists."
2125
2557
 
2126
2558
class MalformedBugIdentifier(BzrError):
2127
2559
 
2128
 
    _fmt = "Did not understand bug identifier %(bug_id)s: %(reason)s"
 
2560
    _fmt = ('Did not understand bug identifier %(bug_id)s: %(reason)s. '
 
2561
            'See "bzr help bugs" for more information on this feature.')
2129
2562
 
2130
2563
    def __init__(self, bug_id, reason):
2131
2564
        self.bug_id = bug_id
2132
2565
        self.reason = reason
2133
2566
 
2134
2567
 
 
2568
class InvalidBugTrackerURL(BzrError):
 
2569
 
 
2570
    _fmt = ("The URL for bug tracker \"%(abbreviation)s\" doesn't "
 
2571
            "contain {id}: %(url)s")
 
2572
 
 
2573
    def __init__(self, abbreviation, url):
 
2574
        self.abbreviation = abbreviation
 
2575
        self.url = url
 
2576
 
 
2577
 
2135
2578
class UnknownBugTrackerAbbreviation(BzrError):
2136
2579
 
2137
2580
    _fmt = ("Cannot find registered bug tracker called %(abbreviation)s "
2142
2585
        self.branch = branch
2143
2586
 
2144
2587
 
 
2588
class InvalidLineInBugsProperty(BzrError):
 
2589
 
 
2590
    _fmt = ("Invalid line in bugs property: '%(line)s'")
 
2591
 
 
2592
    def __init__(self, line):
 
2593
        self.line = line
 
2594
 
 
2595
 
 
2596
class InvalidBugStatus(BzrError):
 
2597
 
 
2598
    _fmt = ("Invalid bug status: '%(status)s'")
 
2599
 
 
2600
    def __init__(self, status):
 
2601
        self.status = status
 
2602
 
 
2603
 
2145
2604
class UnexpectedSmartServerResponse(BzrError):
2146
2605
 
2147
2606
    _fmt = "Could not understand response from smart server: %(response_tuple)r"
2150
2609
        self.response_tuple = response_tuple
2151
2610
 
2152
2611
 
2153
 
class NoDestinationAddress(BzrError):
 
2612
class ErrorFromSmartServer(BzrError):
 
2613
    """An error was received from a smart server.
 
2614
 
 
2615
    :seealso: UnknownErrorFromSmartServer
 
2616
    """
 
2617
 
 
2618
    _fmt = "Error received from smart server: %(error_tuple)r"
 
2619
 
 
2620
    internal_error = True
 
2621
 
 
2622
    def __init__(self, error_tuple):
 
2623
        self.error_tuple = error_tuple
 
2624
        try:
 
2625
            self.error_verb = error_tuple[0]
 
2626
        except IndexError:
 
2627
            self.error_verb = None
 
2628
        self.error_args = error_tuple[1:]
 
2629
 
 
2630
 
 
2631
class UnknownErrorFromSmartServer(BzrError):
 
2632
    """An ErrorFromSmartServer could not be translated into a typical bzrlib
 
2633
    error.
 
2634
 
 
2635
    This is distinct from ErrorFromSmartServer so that it is possible to
 
2636
    distinguish between the following two cases:
 
2637
 
 
2638
    - ErrorFromSmartServer was uncaught.  This is logic error in the client
 
2639
      and so should provoke a traceback to the user.
 
2640
    - ErrorFromSmartServer was caught but its error_tuple could not be
 
2641
      translated.  This is probably because the server sent us garbage, and
 
2642
      should not provoke a traceback.
 
2643
    """
 
2644
 
 
2645
    _fmt = "Server sent an unexpected error: %(error_tuple)r"
 
2646
 
 
2647
    internal_error = False
 
2648
 
 
2649
    def __init__(self, error_from_smart_server):
 
2650
        """Constructor.
 
2651
 
 
2652
        :param error_from_smart_server: An ErrorFromSmartServer instance.
 
2653
        """
 
2654
        self.error_from_smart_server = error_from_smart_server
 
2655
        self.error_tuple = error_from_smart_server.error_tuple
 
2656
 
 
2657
 
 
2658
class ContainerError(BzrError):
 
2659
    """Base class of container errors."""
 
2660
 
 
2661
 
 
2662
class UnknownContainerFormatError(ContainerError):
 
2663
 
 
2664
    _fmt = "Unrecognised container format: %(container_format)r"
 
2665
 
 
2666
    def __init__(self, container_format):
 
2667
        self.container_format = container_format
 
2668
 
 
2669
 
 
2670
class UnexpectedEndOfContainerError(ContainerError):
 
2671
 
 
2672
    _fmt = "Unexpected end of container stream"
 
2673
 
 
2674
 
 
2675
class UnknownRecordTypeError(ContainerError):
 
2676
 
 
2677
    _fmt = "Unknown record type: %(record_type)r"
 
2678
 
 
2679
    def __init__(self, record_type):
 
2680
        self.record_type = record_type
 
2681
 
 
2682
 
 
2683
class InvalidRecordError(ContainerError):
 
2684
 
 
2685
    _fmt = "Invalid record: %(reason)s"
 
2686
 
 
2687
    def __init__(self, reason):
 
2688
        self.reason = reason
 
2689
 
 
2690
 
 
2691
class ContainerHasExcessDataError(ContainerError):
 
2692
 
 
2693
    _fmt = "Container has data after end marker: %(excess)r"
 
2694
 
 
2695
    def __init__(self, excess):
 
2696
        self.excess = excess
 
2697
 
 
2698
 
 
2699
class DuplicateRecordNameError(ContainerError):
 
2700
 
 
2701
    _fmt = "Container has multiple records with the same name: %(name)s"
 
2702
 
 
2703
    def __init__(self, name):
 
2704
        self.name = name.decode("utf-8")
 
2705
 
 
2706
 
 
2707
class NoDestinationAddress(InternalBzrError):
2154
2708
 
2155
2709
    _fmt = "Message does not have a destination address."
2156
2710
 
2157
 
    internal_error = True
 
2711
 
 
2712
class RepositoryDataStreamError(BzrError):
 
2713
 
 
2714
    _fmt = "Corrupt or incompatible data stream: %(reason)s"
 
2715
 
 
2716
    def __init__(self, reason):
 
2717
        self.reason = reason
2158
2718
 
2159
2719
 
2160
2720
class SMTPError(BzrError):
2163
2723
 
2164
2724
    def __init__(self, error):
2165
2725
        self.error = error
 
2726
 
 
2727
 
 
2728
class NoMessageSupplied(BzrError):
 
2729
 
 
2730
    _fmt = "No message supplied."
 
2731
 
 
2732
 
 
2733
class NoMailAddressSpecified(BzrError):
 
2734
 
 
2735
    _fmt = "No mail-to address (--mail-to) or output (-o) specified."
 
2736
 
 
2737
 
 
2738
class UnknownMailClient(BzrError):
 
2739
 
 
2740
    _fmt = "Unknown mail client: %(mail_client)s"
 
2741
 
 
2742
    def __init__(self, mail_client):
 
2743
        BzrError.__init__(self, mail_client=mail_client)
 
2744
 
 
2745
 
 
2746
class MailClientNotFound(BzrError):
 
2747
 
 
2748
    _fmt = "Unable to find mail client with the following names:"\
 
2749
        " %(mail_command_list_string)s"
 
2750
 
 
2751
    def __init__(self, mail_command_list):
 
2752
        mail_command_list_string = ', '.join(mail_command_list)
 
2753
        BzrError.__init__(self, mail_command_list=mail_command_list,
 
2754
                          mail_command_list_string=mail_command_list_string)
 
2755
 
 
2756
class SMTPConnectionRefused(SMTPError):
 
2757
 
 
2758
    _fmt = "SMTP connection to %(host)s refused"
 
2759
 
 
2760
    def __init__(self, error, host):
 
2761
        self.error = error
 
2762
        self.host = host
 
2763
 
 
2764
 
 
2765
class DefaultSMTPConnectionRefused(SMTPConnectionRefused):
 
2766
 
 
2767
    _fmt = "Please specify smtp_server.  No server at default %(host)s."
 
2768
 
 
2769
 
 
2770
class BzrDirError(BzrError):
 
2771
 
 
2772
    def __init__(self, bzrdir):
 
2773
        import bzrlib.urlutils as urlutils
 
2774
        display_url = urlutils.unescape_for_display(bzrdir.user_url,
 
2775
                                                    'ascii')
 
2776
        BzrError.__init__(self, bzrdir=bzrdir, display_url=display_url)
 
2777
 
 
2778
 
 
2779
class UnsyncedBranches(BzrDirError):
 
2780
 
 
2781
    _fmt = ("'%(display_url)s' is not in sync with %(target_url)s.  See"
 
2782
            " bzr help sync-for-reconfigure.")
 
2783
 
 
2784
    def __init__(self, bzrdir, target_branch):
 
2785
        BzrDirError.__init__(self, bzrdir)
 
2786
        import bzrlib.urlutils as urlutils
 
2787
        self.target_url = urlutils.unescape_for_display(target_branch.base,
 
2788
                                                        'ascii')
 
2789
 
 
2790
 
 
2791
class AlreadyBranch(BzrDirError):
 
2792
 
 
2793
    _fmt = "'%(display_url)s' is already a branch."
 
2794
 
 
2795
 
 
2796
class AlreadyTree(BzrDirError):
 
2797
 
 
2798
    _fmt = "'%(display_url)s' is already a tree."
 
2799
 
 
2800
 
 
2801
class AlreadyCheckout(BzrDirError):
 
2802
 
 
2803
    _fmt = "'%(display_url)s' is already a checkout."
 
2804
 
 
2805
 
 
2806
class AlreadyLightweightCheckout(BzrDirError):
 
2807
 
 
2808
    _fmt = "'%(display_url)s' is already a lightweight checkout."
 
2809
 
 
2810
 
 
2811
class AlreadyUsingShared(BzrDirError):
 
2812
 
 
2813
    _fmt = "'%(display_url)s' is already using a shared repository."
 
2814
 
 
2815
 
 
2816
class AlreadyStandalone(BzrDirError):
 
2817
 
 
2818
    _fmt = "'%(display_url)s' is already standalone."
 
2819
 
 
2820
 
 
2821
class AlreadyWithTrees(BzrDirError):
 
2822
 
 
2823
    _fmt = ("Shared repository '%(display_url)s' already creates "
 
2824
            "working trees.")
 
2825
 
 
2826
 
 
2827
class AlreadyWithNoTrees(BzrDirError):
 
2828
 
 
2829
    _fmt = ("Shared repository '%(display_url)s' already doesn't create "
 
2830
            "working trees.")
 
2831
 
 
2832
 
 
2833
class ReconfigurationNotSupported(BzrDirError):
 
2834
 
 
2835
    _fmt = "Requested reconfiguration of '%(display_url)s' is not supported."
 
2836
 
 
2837
 
 
2838
class NoBindLocation(BzrDirError):
 
2839
 
 
2840
    _fmt = "No location could be found to bind to at %(display_url)s."
 
2841
 
 
2842
 
 
2843
class UncommittedChanges(BzrError):
 
2844
 
 
2845
    _fmt = ('Working tree "%(display_url)s" has uncommitted changes'
 
2846
            ' (See bzr status).%(more)s')
 
2847
 
 
2848
    def __init__(self, tree, more=None):
 
2849
        if more is None:
 
2850
            more = ''
 
2851
        else:
 
2852
            more = ' ' + more
 
2853
        import bzrlib.urlutils as urlutils
 
2854
        user_url = getattr(tree, "user_url", None)
 
2855
        if user_url is None:
 
2856
            display_url = str(tree)
 
2857
        else:
 
2858
            display_url = urlutils.unescape_for_display(user_url, 'ascii')
 
2859
        BzrError.__init__(self, tree=tree, display_url=display_url, more=more)
 
2860
 
 
2861
 
 
2862
class ShelvedChanges(UncommittedChanges):
 
2863
 
 
2864
    _fmt = ('Working tree "%(display_url)s" has shelved changes'
 
2865
            ' (See bzr shelve --list).%(more)s')
 
2866
 
 
2867
 
 
2868
class MissingTemplateVariable(BzrError):
 
2869
 
 
2870
    _fmt = 'Variable {%(name)s} is not available.'
 
2871
 
 
2872
    def __init__(self, name):
 
2873
        self.name = name
 
2874
 
 
2875
 
 
2876
class NoTemplate(BzrError):
 
2877
 
 
2878
    _fmt = 'No template specified.'
 
2879
 
 
2880
 
 
2881
class UnableCreateSymlink(BzrError):
 
2882
 
 
2883
    _fmt = 'Unable to create symlink %(path_str)son this platform'
 
2884
 
 
2885
    def __init__(self, path=None):
 
2886
        path_str = ''
 
2887
        if path:
 
2888
            try:
 
2889
                path_str = repr(str(path))
 
2890
            except UnicodeEncodeError:
 
2891
                path_str = repr(path)
 
2892
            path_str += ' '
 
2893
        self.path_str = path_str
 
2894
 
 
2895
 
 
2896
class UnsupportedTimezoneFormat(BzrError):
 
2897
 
 
2898
    _fmt = ('Unsupported timezone format "%(timezone)s", '
 
2899
            'options are "utc", "original", "local".')
 
2900
 
 
2901
    def __init__(self, timezone):
 
2902
        self.timezone = timezone
 
2903
 
 
2904
 
 
2905
class CommandAvailableInPlugin(StandardError):
 
2906
 
 
2907
    internal_error = False
 
2908
 
 
2909
    def __init__(self, cmd_name, plugin_metadata, provider):
 
2910
 
 
2911
        self.plugin_metadata = plugin_metadata
 
2912
        self.cmd_name = cmd_name
 
2913
        self.provider = provider
 
2914
 
 
2915
    def __str__(self):
 
2916
 
 
2917
        _fmt = ('"%s" is not a standard bzr command. \n'
 
2918
                'However, the following official plugin provides this command: %s\n'
 
2919
                'You can install it by going to: %s'
 
2920
                % (self.cmd_name, self.plugin_metadata['name'],
 
2921
                    self.plugin_metadata['url']))
 
2922
 
 
2923
        return _fmt
 
2924
 
 
2925
 
 
2926
class NoPluginAvailable(BzrError):
 
2927
    pass
 
2928
 
 
2929
 
 
2930
class UnableEncodePath(BzrError):
 
2931
 
 
2932
    _fmt = ('Unable to encode %(kind)s path %(path)r in '
 
2933
            'user encoding %(user_encoding)s')
 
2934
 
 
2935
    def __init__(self, path, kind):
 
2936
        from bzrlib.osutils import get_user_encoding
 
2937
        self.path = path
 
2938
        self.kind = kind
 
2939
        self.user_encoding = get_user_encoding()
 
2940
 
 
2941
 
 
2942
class NoSuchConfig(BzrError):
 
2943
 
 
2944
    _fmt = ('The "%(config_id)s" configuration does not exist.')
 
2945
 
 
2946
    def __init__(self, config_id):
 
2947
        BzrError.__init__(self, config_id=config_id)
 
2948
 
 
2949
 
 
2950
class NoSuchConfigOption(BzrError):
 
2951
 
 
2952
    _fmt = ('The "%(option_name)s" configuration option does not exist.')
 
2953
 
 
2954
    def __init__(self, option_name):
 
2955
        BzrError.__init__(self, option_name=option_name)
 
2956
 
 
2957
 
 
2958
class NoSuchAlias(BzrError):
 
2959
 
 
2960
    _fmt = ('The alias "%(alias_name)s" does not exist.')
 
2961
 
 
2962
    def __init__(self, alias_name):
 
2963
        BzrError.__init__(self, alias_name=alias_name)
 
2964
 
 
2965
 
 
2966
class DirectoryLookupFailure(BzrError):
 
2967
    """Base type for lookup errors."""
 
2968
 
 
2969
    pass
 
2970
 
 
2971
 
 
2972
class InvalidLocationAlias(DirectoryLookupFailure):
 
2973
 
 
2974
    _fmt = '"%(alias_name)s" is not a valid location alias.'
 
2975
 
 
2976
    def __init__(self, alias_name):
 
2977
        DirectoryLookupFailure.__init__(self, alias_name=alias_name)
 
2978
 
 
2979
 
 
2980
class UnsetLocationAlias(DirectoryLookupFailure):
 
2981
 
 
2982
    _fmt = 'No %(alias_name)s location assigned.'
 
2983
 
 
2984
    def __init__(self, alias_name):
 
2985
        DirectoryLookupFailure.__init__(self, alias_name=alias_name[1:])
 
2986
 
 
2987
 
 
2988
class CannotBindAddress(BzrError):
 
2989
 
 
2990
    _fmt = 'Cannot bind address "%(host)s:%(port)i": %(orig_error)s.'
 
2991
 
 
2992
    def __init__(self, host, port, orig_error):
 
2993
        # nb: in python2.4 socket.error doesn't have a useful repr
 
2994
        BzrError.__init__(self, host=host, port=port,
 
2995
            orig_error=repr(orig_error.args))
 
2996
 
 
2997
 
 
2998
class UnknownRules(BzrError):
 
2999
 
 
3000
    _fmt = ('Unknown rules detected: %(unknowns_str)s.')
 
3001
 
 
3002
    def __init__(self, unknowns):
 
3003
        BzrError.__init__(self, unknowns_str=", ".join(unknowns))
 
3004
 
 
3005
 
 
3006
class TipChangeRejected(BzrError):
 
3007
    """A pre_change_branch_tip hook function may raise this to cleanly and
 
3008
    explicitly abort a change to a branch tip.
 
3009
    """
 
3010
 
 
3011
    _fmt = u"Tip change rejected: %(msg)s"
 
3012
 
 
3013
    def __init__(self, msg):
 
3014
        self.msg = msg
 
3015
 
 
3016
 
 
3017
class ShelfCorrupt(BzrError):
 
3018
 
 
3019
    _fmt = "Shelf corrupt."
 
3020
 
 
3021
 
 
3022
class DecompressCorruption(BzrError):
 
3023
 
 
3024
    _fmt = "Corruption while decompressing repository file%(orig_error)s"
 
3025
 
 
3026
    def __init__(self, orig_error=None):
 
3027
        if orig_error is not None:
 
3028
            self.orig_error = ", %s" % (orig_error,)
 
3029
        else:
 
3030
            self.orig_error = ""
 
3031
        BzrError.__init__(self)
 
3032
 
 
3033
 
 
3034
class NoSuchShelfId(BzrError):
 
3035
 
 
3036
    _fmt = 'No changes are shelved with id "%(shelf_id)d".'
 
3037
 
 
3038
    def __init__(self, shelf_id):
 
3039
        BzrError.__init__(self, shelf_id=shelf_id)
 
3040
 
 
3041
 
 
3042
class InvalidShelfId(BzrError):
 
3043
 
 
3044
    _fmt = '"%(invalid_id)s" is not a valid shelf id, try a number instead.'
 
3045
 
 
3046
    def __init__(self, invalid_id):
 
3047
        BzrError.__init__(self, invalid_id=invalid_id)
 
3048
 
 
3049
 
 
3050
class JailBreak(BzrError):
 
3051
 
 
3052
    _fmt = "An attempt to access a url outside the server jail was made: '%(url)s'."
 
3053
 
 
3054
    def __init__(self, url):
 
3055
        BzrError.__init__(self, url=url)
 
3056
 
 
3057
 
 
3058
class UserAbort(BzrError):
 
3059
 
 
3060
    _fmt = 'The user aborted the operation.'
 
3061
 
 
3062
 
 
3063
class MustHaveWorkingTree(BzrError):
 
3064
 
 
3065
    _fmt = ("Branching '%(url)s'(%(format)s) must create a working tree.")
 
3066
 
 
3067
    def __init__(self, format, url):
 
3068
        BzrError.__init__(self, format=format, url=url)
 
3069
 
 
3070
 
 
3071
class NoSuchView(BzrError):
 
3072
    """A view does not exist.
 
3073
    """
 
3074
 
 
3075
    _fmt = u"No such view: %(view_name)s."
 
3076
 
 
3077
    def __init__(self, view_name):
 
3078
        self.view_name = view_name
 
3079
 
 
3080
 
 
3081
class ViewsNotSupported(BzrError):
 
3082
    """Views are not supported by a tree format.
 
3083
    """
 
3084
 
 
3085
    _fmt = ("Views are not supported by %(tree)s;"
 
3086
            " use 'bzr upgrade' to change your tree to a later format.")
 
3087
 
 
3088
    def __init__(self, tree):
 
3089
        self.tree = tree
 
3090
 
 
3091
 
 
3092
class FileOutsideView(BzrError):
 
3093
 
 
3094
    _fmt = ('Specified file "%(file_name)s" is outside the current view: '
 
3095
            '%(view_str)s')
 
3096
 
 
3097
    def __init__(self, file_name, view_files):
 
3098
        self.file_name = file_name
 
3099
        self.view_str = ", ".join(view_files)
 
3100
 
 
3101
 
 
3102
class UnresumableWriteGroup(BzrError):
 
3103
 
 
3104
    _fmt = ("Repository %(repository)s cannot resume write group "
 
3105
            "%(write_groups)r: %(reason)s")
 
3106
 
 
3107
    internal_error = True
 
3108
 
 
3109
    def __init__(self, repository, write_groups, reason):
 
3110
        self.repository = repository
 
3111
        self.write_groups = write_groups
 
3112
        self.reason = reason
 
3113
 
 
3114
 
 
3115
class UnsuspendableWriteGroup(BzrError):
 
3116
 
 
3117
    _fmt = ("Repository %(repository)s cannot suspend a write group.")
 
3118
 
 
3119
    internal_error = True
 
3120
 
 
3121
    def __init__(self, repository):
 
3122
        self.repository = repository
 
3123
 
 
3124
 
 
3125
class LossyPushToSameVCS(BzrError):
 
3126
 
 
3127
    _fmt = ("Lossy push not possible between %(source_branch)r and "
 
3128
            "%(target_branch)r that are in the same VCS.")
 
3129
 
 
3130
    internal_error = True
 
3131
 
 
3132
    def __init__(self, source_branch, target_branch):
 
3133
        self.source_branch = source_branch
 
3134
        self.target_branch = target_branch
 
3135
 
 
3136
 
 
3137
class NoRoundtrippingSupport(BzrError):
 
3138
 
 
3139
    _fmt = ("Roundtripping is not supported between %(source_branch)r and "
 
3140
            "%(target_branch)r.")
 
3141
 
 
3142
    internal_error = True
 
3143
 
 
3144
    def __init__(self, source_branch, target_branch):
 
3145
        self.source_branch = source_branch
 
3146
        self.target_branch = target_branch
 
3147
 
 
3148
 
 
3149
class FileTimestampUnavailable(BzrError):
 
3150
 
 
3151
    _fmt = "The filestamp for %(path)s is not available."
 
3152
 
 
3153
    internal_error = True
 
3154
 
 
3155
    def __init__(self, path):
 
3156
        self.path = path
 
3157
 
 
3158
 
 
3159
class NoColocatedBranchSupport(BzrError):
 
3160
 
 
3161
    _fmt = ("%(bzrdir)r does not support co-located branches.")
 
3162
 
 
3163
    def __init__(self, bzrdir):
 
3164
        self.bzrdir = bzrdir
 
3165
 
 
3166
 
 
3167
class NoWhoami(BzrError):
 
3168
 
 
3169
    _fmt = ('Unable to determine your name.\n'
 
3170
        "Please, set your name with the 'whoami' command.\n"
 
3171
        'E.g. bzr whoami "Your Name <name@example.com>"')
 
3172
 
 
3173
 
 
3174
class InvalidPattern(BzrError):
 
3175
 
 
3176
    _fmt = ('Invalid pattern(s) found. %(msg)s')
 
3177
 
 
3178
    def __init__(self, msg):
 
3179
        self.msg = msg
 
3180
 
 
3181
 
 
3182
class RecursiveBind(BzrError):
 
3183
 
 
3184
    _fmt = ('Branch "%(branch_url)s" appears to be bound to itself. '
 
3185
        'Please use `bzr unbind` to fix.')
 
3186
 
 
3187
    def __init__(self, branch_url):
 
3188
        self.branch_url = branch_url
 
3189
 
 
3190
 
 
3191
# FIXME: I would prefer to define the config related exception classes in
 
3192
# config.py but the lazy import mechanism proscribes this -- vila 20101222
 
3193
class OptionExpansionLoop(BzrError):
 
3194
 
 
3195
    _fmt = 'Loop involving %(refs)r while expanding "%(string)s".'
 
3196
 
 
3197
    def __init__(self, string, refs):
 
3198
        self.string = string
 
3199
        self.refs = '->'.join(refs)
 
3200
 
 
3201
 
 
3202
class ExpandingUnknownOption(BzrError):
 
3203
 
 
3204
    _fmt = 'Option %(name)s is not defined while expanding "%(string)s".'
 
3205
 
 
3206
    def __init__(self, name, string):
 
3207
        self.name = name
 
3208
        self.string = string
 
3209
 
 
3210
 
 
3211
class NoCompatibleInter(BzrError):
 
3212
 
 
3213
    _fmt = ('No compatible object available for operations from %(source)r '
 
3214
            'to %(target)r.')
 
3215
 
 
3216
    def __init__(self, source, target):
 
3217
        self.source = source
 
3218
        self.target = target
 
3219
 
 
3220
 
 
3221
class HpssVfsRequestNotAllowed(BzrError):
 
3222
 
 
3223
    _fmt = ("VFS requests over the smart server are not allowed. Encountered: "
 
3224
            "%(method)s, %(arguments)s.")
 
3225
 
 
3226
    def __init__(self, method, arguments):
 
3227
        self.method = method
 
3228
        self.arguments = arguments
 
3229
 
 
3230
 
 
3231
class UnsupportedKindChange(BzrError):
 
3232
 
 
3233
    _fmt = ("Kind change from %(from_kind)s to %(to_kind)s for "
 
3234
            "%(path)s not supported by format %(format)r")
 
3235
 
 
3236
    def __init__(self, path, from_kind, to_kind, format):
 
3237
        self.path = path
 
3238
        self.from_kind = from_kind
 
3239
        self.to_kind = to_kind
 
3240
        self.format = format
 
3241
 
 
3242
 
 
3243
class PatchSyntax(BzrError):
 
3244
    """Base class for patch syntax errors."""
 
3245
 
 
3246
 
 
3247
class BinaryFiles(BzrError):
 
3248
 
 
3249
    _fmt = 'Binary files section encountered.'
 
3250
 
 
3251
    def __init__(self, orig_name, mod_name):
 
3252
        self.orig_name = orig_name
 
3253
        self.mod_name = mod_name
 
3254
 
 
3255
 
 
3256
class MalformedPatchHeader(PatchSyntax):
 
3257
 
 
3258
    _fmt = "Malformed patch header.  %(desc)s\n%(line)r"
 
3259
 
 
3260
    def __init__(self, desc, line):
 
3261
        self.desc = desc
 
3262
        self.line = line
 
3263
 
 
3264
 
 
3265
class MalformedHunkHeader(PatchSyntax):
 
3266
 
 
3267
    _fmt = "Malformed hunk header.  %(desc)s\n%(line)r"
 
3268
 
 
3269
    def __init__(self, desc, line):
 
3270
        self.desc = desc
 
3271
        self.line = line
 
3272
 
 
3273
 
 
3274
class MalformedLine(PatchSyntax):
 
3275
 
 
3276
    _fmt = "Malformed line.  %(desc)s\n%(line)r"
 
3277
 
 
3278
    def __init__(self, desc, line):
 
3279
        self.desc = desc
 
3280
        self.line = line
 
3281
 
 
3282
 
 
3283
class PatchConflict(BzrError):
 
3284
 
 
3285
    _fmt = ('Text contents mismatch at line %(line_no)d.  Original has '
 
3286
            '"%(orig_line)s", but patch says it should be "%(patch_line)s"')
 
3287
 
 
3288
    def __init__(self, line_no, orig_line, patch_line):
 
3289
        self.line_no = line_no
 
3290
        self.orig_line = orig_line.rstrip('\n')
 
3291
        self.patch_line = patch_line.rstrip('\n')