~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/errors.py

  • Committer: Alexander Belchenko
  • Date: 2006-12-22 08:52:28 UTC
  • mto: This revision was merged to the branch mainline in revision 2215.
  • Revision ID: bialix@ukr.net-20061222085228-fe80nuencvxluh6v
Don't formats unicode strings in test error messages with '%s': it's unsafe

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005, 2006, 2007, 2008 Canonical Ltd
 
1
# Copyright (C) 2005, 2006 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
12
12
#
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
 
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
16
 
17
17
"""Exceptions for bzr, and reporting of them.
18
18
"""
19
19
 
20
 
from bzrlib import (
21
 
    osutils,
22
 
    symbol_versioning,
23
 
    )
24
 
from bzrlib.patches import (
25
 
    MalformedHunkHeader,
26
 
    MalformedLine,
27
 
    MalformedPatchHeader,
28
 
    PatchConflict,
29
 
    PatchSyntax,
30
 
    )
 
20
 
 
21
from bzrlib import symbol_versioning
 
22
from bzrlib.patches import (PatchSyntax, 
 
23
                            PatchConflict, 
 
24
                            MalformedPatchHeader,
 
25
                            MalformedHunkHeader,
 
26
                            MalformedLine,)
31
27
 
32
28
 
33
29
# TODO: is there any value in providing the .args field used by standard
34
 
# python exceptions?   A list of values with no names seems less useful
 
30
# python exceptions?   A list of values with no names seems less useful 
35
31
# to me.
36
32
 
37
 
# TODO: Perhaps convert the exception to a string at the moment it's
 
33
# TODO: Perhaps convert the exception to a string at the moment it's 
38
34
# constructed to make sure it will succeed.  But that says nothing about
39
35
# exceptions that are never raised.
40
36
 
43
39
# 'unprintable'.
44
40
 
45
41
 
46
 
# return codes from the bzr program
47
 
EXIT_OK = 0
48
 
EXIT_ERROR = 3
49
 
EXIT_INTERNAL_ERROR = 4
50
 
 
51
 
 
52
42
class BzrError(StandardError):
53
43
    """
54
44
    Base class for errors raised by bzrlib.
55
45
 
56
 
    :cvar internal_error: if True this was probably caused by a bzr bug and
57
 
    should be displayed with a traceback; if False (or absent) this was
 
46
    :cvar internal_error: if true (or absent) this was probably caused by a
 
47
    bzr bug and should be displayed with a traceback; if False this was
58
48
    probably a user or environment error and they don't need the gory details.
59
49
    (That can be overridden by -Derror on the command line.)
60
50
 
61
51
    :cvar _fmt: Format string to display the error; this is expanded
62
52
    by the instance's dict.
63
53
    """
64
 
 
 
54
    
65
55
    internal_error = False
66
56
 
67
57
    def __init__(self, msg=None, **kwds):
72
62
        arguments can be given.  The first is for generic "user" errors which
73
63
        are not intended to be caught and so do not need a specific subclass.
74
64
        The second case is for use with subclasses that provide a _fmt format
75
 
        string to print the arguments.
 
65
        string to print the arguments.  
76
66
 
77
 
        Keyword arguments are taken as parameters to the error, which can
78
 
        be inserted into the format string template.  It's recommended
79
 
        that subclasses override the __init__ method to require specific
 
67
        Keyword arguments are taken as parameters to the error, which can 
 
68
        be inserted into the format string template.  It's recommended 
 
69
        that subclasses override the __init__ method to require specific 
80
70
        parameters.
81
71
 
82
72
        :param msg: If given, this is the literal complete text for the error,
83
 
           not subject to expansion. 'msg' is used instead of 'message' because
84
 
           python evolved and, in 2.6, forbids the use of 'message'.
 
73
        not subject to expansion.
85
74
        """
86
75
        StandardError.__init__(self)
87
76
        if msg is not None:
93
82
            for key, value in kwds.items():
94
83
                setattr(self, key, value)
95
84
 
96
 
    def _format(self):
 
85
    def __str__(self):
97
86
        s = getattr(self, '_preformatted_string', None)
98
87
        if s is not None:
99
 
            # contains a preformatted message
100
 
            return s
 
88
            # contains a preformatted message; must be cast to plain str
 
89
            return str(s)
101
90
        try:
102
91
            fmt = self._get_format_string()
103
92
            if fmt:
104
 
                d = dict(self.__dict__)
105
 
                s = fmt % d
 
93
                s = fmt % self.__dict__
106
94
                # __str__() should always return a 'str' object
107
95
                # never a 'unicode' object.
 
96
                if isinstance(s, unicode):
 
97
                    return s.encode('utf8')
108
98
                return s
109
99
        except (AttributeError, TypeError, NameError, ValueError, KeyError), e:
110
 
            return 'Unprintable exception %s: dict=%r, fmt=%r, error=%r' \
 
100
            return 'Unprintable exception %s: dict=%r, fmt=%r, error=%s' \
111
101
                % (self.__class__.__name__,
112
102
                   self.__dict__,
113
103
                   getattr(self, '_fmt', None),
114
 
                   e)
115
 
 
116
 
    def __unicode__(self):
117
 
        u = self._format()
118
 
        if isinstance(u, str):
119
 
            # Try decoding the str using the default encoding.
120
 
            u = unicode(u)
121
 
        elif not isinstance(u, unicode):
122
 
            # Try to make a unicode object from it, because __unicode__ must
123
 
            # return a unicode object.
124
 
            u = unicode(u)
125
 
        return u
126
 
 
127
 
    def __str__(self):
128
 
        s = self._format()
129
 
        if isinstance(s, unicode):
130
 
            s = s.encode('utf8')
131
 
        else:
132
 
            # __str__ must return a str.
133
 
            s = str(s)
134
 
        return s
135
 
 
136
 
    def __repr__(self):
137
 
        return '%s(%s)' % (self.__class__.__name__, str(self))
 
104
                   str(e))
138
105
 
139
106
    def _get_format_string(self):
140
107
        """Return format string for this exception or None"""
153
120
               getattr(self, '_fmt', None),
154
121
               )
155
122
 
156
 
    def __eq__(self, other):
157
 
        if self.__class__ is not other.__class__:
158
 
            return NotImplemented
159
 
        return self.__dict__ == other.__dict__
160
 
 
161
 
 
162
 
class InternalBzrError(BzrError):
163
 
    """Base class for errors that are internal in nature.
164
 
 
165
 
    This is a convenience class for errors that are internal. The
166
 
    internal_error attribute can still be altered in subclasses, if needed.
167
 
    Using this class is simply an easy way to get internal errors.
168
 
    """
169
 
 
170
 
    internal_error = True
171
 
 
172
123
 
173
124
class BzrNewError(BzrError):
174
125
    """Deprecated error base class."""
176
127
    # readable explanation
177
128
 
178
129
    def __init__(self, *args, **kwds):
179
 
        # XXX: Use the underlying BzrError to always generate the args
180
 
        # attribute if it doesn't exist.  We can't use super here, because
181
 
        # exceptions are old-style classes in python2.4 (but new in 2.5).
182
 
        # --bmc, 20060426
 
130
        # XXX: Use the underlying BzrError to always generate the args attribute
 
131
        # if it doesn't exist.  We can't use super here, because exceptions are
 
132
        # old-style classes in python2.4 (but new in 2.5).  --bmc, 20060426
183
133
        symbol_versioning.warn('BzrNewError was deprecated in bzr 0.13; '
184
 
             'please convert %s to use BzrError instead'
 
134
             'please convert %s to use BzrError instead' 
185
135
             % self.__class__.__name__,
186
136
             DeprecationWarning,
187
137
             stacklevel=2)
198
148
                return s.encode('utf8')
199
149
            return s
200
150
        except (TypeError, NameError, ValueError, KeyError), e:
201
 
            return 'Unprintable exception %s(%r): %r' \
 
151
            return 'Unprintable exception %s(%r): %s' \
202
152
                % (self.__class__.__name__,
203
 
                   self.__dict__, e)
 
153
                   self.__dict__, str(e))
204
154
 
205
155
 
206
156
class AlreadyBuilding(BzrError):
207
 
 
 
157
    
208
158
    _fmt = "The tree builder is already building a tree."
209
159
 
210
160
 
211
 
class BranchError(BzrError):
212
 
    """Base class for concrete 'errors about a branch'."""
213
 
 
214
 
    def __init__(self, branch):
215
 
        BzrError.__init__(self, branch=branch)
216
 
 
217
 
 
218
 
class BzrCheckError(InternalBzrError):
219
 
 
220
 
    _fmt = "Internal check failed: %(msg)s"
221
 
 
222
 
    def __init__(self, msg):
223
 
        BzrError.__init__(self)
224
 
        self.msg = msg
225
 
 
226
 
 
227
 
class DirstateCorrupt(BzrError):
228
 
 
229
 
    _fmt = "The dirstate file (%(state)s) appears to be corrupt: %(msg)s"
230
 
 
231
 
    def __init__(self, state, msg):
232
 
        BzrError.__init__(self)
233
 
        self.state = state
234
 
        self.msg = msg
235
 
 
236
 
 
237
 
class DisabledMethod(InternalBzrError):
238
 
 
239
 
    _fmt = "The smart server method '%(class_name)s' is disabled."
240
 
 
241
 
    def __init__(self, class_name):
242
 
        BzrError.__init__(self)
243
 
        self.class_name = class_name
244
 
 
245
 
 
246
 
class IncompatibleAPI(BzrError):
247
 
 
248
 
    _fmt = 'The API for "%(api)s" is not compatible with "%(wanted)s". '\
249
 
        'It supports versions "%(minimum)s" to "%(current)s".'
250
 
 
251
 
    def __init__(self, api, wanted, minimum, current):
252
 
        self.api = api
253
 
        self.wanted = wanted
254
 
        self.minimum = minimum
255
 
        self.current = current
256
 
 
257
 
 
258
 
class InProcessTransport(BzrError):
259
 
 
260
 
    _fmt = "The transport '%(transport)s' is only accessible within this " \
261
 
        "process."
262
 
 
263
 
    def __init__(self, transport):
264
 
        self.transport = transport
265
 
 
266
 
 
267
 
class InvalidEntryName(InternalBzrError):
268
 
 
 
161
class BzrCheckError(BzrError):
 
162
    
 
163
    _fmt = "Internal check failed: %(message)s"
 
164
 
 
165
    internal_error = True
 
166
 
 
167
    def __init__(self, message):
 
168
        BzrError.__init__(self)
 
169
        self.message = message
 
170
 
 
171
 
 
172
class InvalidEntryName(BzrError):
 
173
    
269
174
    _fmt = "Invalid entry name: %(name)s"
270
175
 
 
176
    internal_error = True
 
177
 
271
178
    def __init__(self, name):
272
179
        BzrError.__init__(self)
273
180
        self.name = name
274
181
 
275
182
 
276
183
class InvalidRevisionNumber(BzrError):
277
 
 
 
184
    
278
185
    _fmt = "Invalid revision number %(revno)s"
279
186
 
280
187
    def __init__(self, revno):
293
200
        self.branch = branch
294
201
 
295
202
 
296
 
class ReservedId(BzrError):
297
 
 
298
 
    _fmt = "Reserved revision-id {%(revision_id)s}"
299
 
 
300
 
    def __init__(self, revision_id):
301
 
        self.revision_id = revision_id
302
 
 
303
 
 
304
 
class RootMissing(InternalBzrError):
305
 
 
306
 
    _fmt = ("The root entry of a tree must be the first entry supplied to "
307
 
        "record_entry_contents.")
308
 
 
309
 
 
310
 
class NoPublicBranch(BzrError):
311
 
 
312
 
    _fmt = 'There is no public branch set for "%(branch_url)s".'
313
 
 
314
 
    def __init__(self, branch):
315
 
        import bzrlib.urlutils as urlutils
316
 
        public_location = urlutils.unescape_for_display(branch.base, 'ascii')
317
 
        BzrError.__init__(self, branch_url=public_location)
318
 
 
319
 
 
320
 
class NoHelpTopic(BzrError):
321
 
 
322
 
    _fmt = ("No help could be found for '%(topic)s'. "
323
 
        "Please use 'bzr help topics' to obtain a list of topics.")
324
 
 
325
 
    def __init__(self, topic):
326
 
        self.topic = topic
327
 
 
328
 
 
329
203
class NoSuchId(BzrError):
330
204
 
331
 
    _fmt = 'The file id "%(file_id)s" is not present in the tree %(tree)s.'
332
 
 
 
205
    _fmt = "The file id %(file_id)s is not present in the tree %(tree)s."
 
206
    
333
207
    def __init__(self, tree, file_id):
334
208
        BzrError.__init__(self)
335
209
        self.file_id = file_id
336
210
        self.tree = tree
337
211
 
338
212
 
339
 
class NoSuchIdInRepository(NoSuchId):
340
 
 
341
 
    _fmt = ('The file id "%(file_id)s" is not present in the repository'
342
 
            ' %(repository)r')
343
 
 
344
 
    def __init__(self, repository, file_id):
345
 
        BzrError.__init__(self, repository=repository, file_id=file_id)
346
 
 
347
 
 
348
 
class NotStacked(BranchError):
349
 
 
350
 
    _fmt = "The branch '%(branch)s' is not stacked."
351
 
 
352
 
 
353
 
class InventoryModified(InternalBzrError):
354
 
 
355
 
    _fmt = ("The current inventory for the tree %(tree)r has been modified,"
356
 
            " so a clean inventory cannot be read without data loss.")
 
213
class InventoryModified(BzrError):
 
214
 
 
215
    _fmt = ("The current inventory for the tree %(tree)r has been modified, "
 
216
            "so a clean inventory cannot be read without data loss.")
 
217
 
 
218
    internal_error = True
357
219
 
358
220
    def __init__(self, tree):
359
221
        self.tree = tree
361
223
 
362
224
class NoWorkingTree(BzrError):
363
225
 
364
 
    _fmt = 'No WorkingTree exists for "%(base)s".'
365
 
 
 
226
    _fmt = "No WorkingTree exists for %(base)s."
 
227
    
366
228
    def __init__(self, base):
367
229
        BzrError.__init__(self)
368
230
        self.base = base
381
243
        self.url = url
382
244
 
383
245
 
384
 
class WorkingTreeAlreadyPopulated(InternalBzrError):
385
 
 
386
 
    _fmt = 'Working tree already populated in "%(base)s"'
 
246
class WorkingTreeAlreadyPopulated(BzrError):
 
247
 
 
248
    _fmt = """Working tree already populated in %(base)s"""
 
249
 
 
250
    internal_error = True
387
251
 
388
252
    def __init__(self, base):
389
253
        self.base = base
390
254
 
391
 
 
392
255
class BzrCommandError(BzrError):
393
256
    """Error from user command"""
394
257
 
 
258
    internal_error = False
 
259
 
395
260
    # Error from malformed user command; please avoid raising this as a
396
261
    # generic exception not caused by user input.
397
262
    #
399
264
    # are not intended to be caught anyway.  UI code need not subclass
400
265
    # BzrCommandError, and non-UI code should not throw a subclass of
401
266
    # BzrCommandError.  ADHB 20051211
 
267
    def __init__(self, msg):
 
268
        # Object.__str__() must return a real string
 
269
        # returning a Unicode string is a python error.
 
270
        if isinstance(msg, unicode):
 
271
            self.msg = msg.encode('utf8')
 
272
        else:
 
273
            self.msg = msg
 
274
 
 
275
    def __str__(self):
 
276
        return self.msg
402
277
 
403
278
 
404
279
class NotWriteLocked(BzrError):
413
288
 
414
289
    _fmt = "Error in command line options"
415
290
 
416
 
 
417
 
class BadIndexFormatSignature(BzrError):
418
 
 
419
 
    _fmt = "%(value)s is not an index of type %(_type)s."
420
 
 
421
 
    def __init__(self, value, _type):
422
 
        BzrError.__init__(self)
423
 
        self.value = value
424
 
        self._type = _type
425
 
 
426
 
 
427
 
class BadIndexData(BzrError):
428
 
 
429
 
    _fmt = "Error in data for index %(value)s."
430
 
 
431
 
    def __init__(self, value):
432
 
        BzrError.__init__(self)
433
 
        self.value = value
434
 
 
435
 
 
436
 
class BadIndexDuplicateKey(BzrError):
437
 
 
438
 
    _fmt = "The key '%(key)s' is already in index '%(index)s'."
439
 
 
440
 
    def __init__(self, key, index):
441
 
        BzrError.__init__(self)
442
 
        self.key = key
443
 
        self.index = index
444
 
 
445
 
 
446
 
class BadIndexKey(BzrError):
447
 
 
448
 
    _fmt = "The key '%(key)s' is not a valid key."
449
 
 
450
 
    def __init__(self, key):
451
 
        BzrError.__init__(self)
452
 
        self.key = key
453
 
 
454
 
 
455
 
class BadIndexOptions(BzrError):
456
 
 
457
 
    _fmt = "Could not parse options for index %(value)s."
458
 
 
459
 
    def __init__(self, value):
460
 
        BzrError.__init__(self)
461
 
        self.value = value
462
 
 
463
 
 
464
 
class BadIndexValue(BzrError):
465
 
 
466
 
    _fmt = "The value '%(value)s' is not a valid value."
467
 
 
468
 
    def __init__(self, value):
469
 
        BzrError.__init__(self)
470
 
        self.value = value
471
 
 
472
 
 
473
 
class BadOptionValue(BzrError):
474
 
 
475
 
    _fmt = """Bad value "%(value)s" for option "%(name)s"."""
476
 
 
477
 
    def __init__(self, name, value):
478
 
        BzrError.__init__(self, name=name, value=value)
479
 
 
480
 
 
 
291
    
481
292
class StrictCommitFailed(BzrError):
482
293
 
483
294
    _fmt = "Commit refused because there are unknown files in the tree"
485
296
 
486
297
# XXX: Should be unified with TransportError; they seem to represent the
487
298
# same thing
488
 
# RBC 20060929: I think that unifiying with TransportError would be a mistake
489
 
# - this is finer than a TransportError - and more useful as such. It
490
 
# differentiates between 'transport has failed' and 'operation on a transport
491
 
# has failed.'
492
299
class PathError(BzrError):
493
 
 
 
300
    
494
301
    _fmt = "Generic path error: %(path)r%(extra)s)"
495
302
 
496
303
    def __init__(self, path, extra=None):
512
319
    _fmt = "File exists: %(path)r%(extra)s"
513
320
 
514
321
 
515
 
class RenameFailedFilesExist(BzrError):
516
 
    """Used when renaming and both source and dest exist."""
517
 
 
518
 
    _fmt = ("Could not rename %(source)s => %(dest)s because both files exist."
519
 
            " (Use --after to tell bzr about a rename that has already"
520
 
            " happened)%(extra)s")
521
 
 
522
 
    def __init__(self, source, dest, extra=None):
523
 
        BzrError.__init__(self)
524
 
        self.source = str(source)
525
 
        self.dest = str(dest)
526
 
        if extra:
527
 
            self.extra = ' ' + str(extra)
528
 
        else:
529
 
            self.extra = ''
530
 
 
531
 
 
532
 
class NotADirectory(PathError):
533
 
 
534
 
    _fmt = '"%(path)s" is not a directory %(extra)s'
535
 
 
536
 
 
537
 
class NotInWorkingDirectory(PathError):
538
 
 
539
 
    _fmt = '"%(path)s" is not in the working directory %(extra)s'
540
 
 
541
 
 
542
322
class DirectoryNotEmpty(PathError):
543
323
 
544
 
    _fmt = 'Directory not empty: "%(path)s"%(extra)s'
545
 
 
546
 
 
547
 
class HardLinkNotSupported(PathError):
548
 
 
549
 
    _fmt = 'Hard-linking "%(path)s" is not supported'
550
 
 
551
 
 
552
 
class ReadingCompleted(InternalBzrError):
553
 
 
 
324
    _fmt = "Directory not empty: %(path)r%(extra)s"
 
325
 
 
326
 
 
327
class ReadingCompleted(BzrError):
 
328
    
554
329
    _fmt = ("The MediumRequest '%(request)s' has already had finish_reading "
555
330
            "called upon it - the request has been completed and no more "
556
331
            "data may be read.")
557
332
 
 
333
    internal_error = True
 
334
 
558
335
    def __init__(self, request):
559
336
        self.request = request
560
337
 
561
338
 
562
339
class ResourceBusy(PathError):
563
340
 
564
 
    _fmt = 'Device or resource busy: "%(path)s"%(extra)s'
 
341
    _fmt = "Device or resource busy: %(path)r%(extra)s"
565
342
 
566
343
 
567
344
class PermissionDenied(PathError):
568
345
 
569
 
    _fmt = 'Permission denied: "%(path)s"%(extra)s'
 
346
    _fmt = "Permission denied: %(path)r%(extra)s"
570
347
 
571
348
 
572
349
class InvalidURL(PathError):
573
350
 
574
 
    _fmt = 'Invalid url supplied to transport: "%(path)s"%(extra)s'
 
351
    _fmt = "Invalid url supplied to transport: %(path)r%(extra)s"
575
352
 
576
353
 
577
354
class InvalidURLJoin(PathError):
578
355
 
579
 
    _fmt = "Invalid URL join request: %(reason)s: %(base)r + %(join_args)r"
580
 
 
581
 
    def __init__(self, reason, base, join_args):
582
 
        self.reason = reason
583
 
        self.base = base
584
 
        self.join_args = join_args
585
 
        PathError.__init__(self, base, reason)
586
 
 
587
 
 
588
 
class InvalidRebaseURLs(PathError):
589
 
 
590
 
    _fmt = "URLs differ by more than path: %(from_)r and %(to)r"
591
 
 
592
 
    def __init__(self, from_, to):
593
 
        self.from_ = from_
594
 
        self.to = to
595
 
        PathError.__init__(self, from_, 'URLs differ by more than path.')
596
 
 
597
 
 
598
 
class UnavailableRepresentation(InternalBzrError):
599
 
 
600
 
    _fmt = ("The encoding '%(wanted)s' is not available for key %(key)s which "
601
 
        "is encoded as '%(native)s'.")
602
 
 
603
 
    def __init__(self, key, wanted, native):
604
 
        InternalBzrError.__init__(self)
605
 
        self.wanted = wanted
606
 
        self.native = native
607
 
        self.key = key
608
 
 
609
 
 
610
 
class UnknownHook(BzrError):
611
 
 
612
 
    _fmt = "The %(type)s hook '%(hook)s' is unknown in this version of bzrlib."
613
 
 
614
 
    def __init__(self, hook_type, hook_name):
615
 
        BzrError.__init__(self)
616
 
        self.type = hook_type
617
 
        self.hook = hook_name
 
356
    _fmt = "Invalid URL join request: %(args)s%(extra)s"
 
357
 
 
358
    def __init__(self, msg, base, args):
 
359
        PathError.__init__(self, base, msg)
 
360
        self.args = [base] + list(args)
618
361
 
619
362
 
620
363
class UnsupportedProtocol(PathError):
625
368
        PathError.__init__(self, url, extra=extra)
626
369
 
627
370
 
628
 
class UnstackableBranchFormat(BzrError):
629
 
 
630
 
    _fmt = ("The branch '%(url)s'(%(format)s) is not a stackable format. "
631
 
        "You will need to upgrade the branch to permit branch stacking.")
632
 
 
633
 
    def __init__(self, format, url):
634
 
        BzrError.__init__(self)
635
 
        self.format = format
636
 
        self.url = url
637
 
 
638
 
 
639
 
class UnstackableRepositoryFormat(BzrError):
640
 
 
641
 
    _fmt = ("The repository '%(url)s'(%(format)s) is not a stackable format. "
642
 
        "You will need to upgrade the repository to permit branch stacking.")
643
 
 
644
 
    def __init__(self, format, url):
645
 
        BzrError.__init__(self)
646
 
        self.format = format
647
 
        self.url = url
648
 
 
649
 
 
650
 
class ReadError(PathError):
651
 
 
652
 
    _fmt = """Error reading from %(path)r."""
653
 
 
654
 
 
655
371
class ShortReadvError(PathError):
656
372
 
657
 
    _fmt = ('readv() read %(actual)s bytes rather than %(length)s bytes'
658
 
            ' at %(offset)s for "%(path)s"%(extra)s')
 
373
    _fmt = "readv() read %(actual)s bytes rather than %(length)s bytes at %(offset)s for %(path)s%(extra)s"
659
374
 
660
375
    internal_error = True
661
376
 
666
381
        self.actual = actual
667
382
 
668
383
 
669
 
class PathNotChild(PathError):
 
384
class PathNotChild(BzrError):
670
385
 
671
 
    _fmt = 'Path "%(path)s" is not a child of path "%(base)s"%(extra)s'
 
386
    _fmt = "Path %(path)r is not a child of path %(base)r%(extra)s"
672
387
 
673
388
    internal_error = True
674
389
 
684
399
 
685
400
class InvalidNormalization(PathError):
686
401
 
687
 
    _fmt = 'Path "%(path)s" is not unicode normalized'
 
402
    _fmt = "Path %(path)r is not unicode normalized"
688
403
 
689
404
 
690
405
# TODO: This is given a URL; we try to unescape it but doing that from inside
691
406
# the exception object is a bit undesirable.
692
 
# TODO: Probably this behavior of should be a common superclass
 
407
# TODO: Probably this behavior of should be a common superclass 
693
408
class NotBranchError(PathError):
694
409
 
695
 
    _fmt = 'Not a branch: "%(path)s".'
 
410
    _fmt = "Not a branch: %(path)s"
696
411
 
697
412
    def __init__(self, path):
698
413
       import bzrlib.urlutils as urlutils
699
414
       self.path = urlutils.unescape_for_display(path, 'ascii')
700
415
 
701
416
 
702
 
class NoSubmitBranch(PathError):
703
 
 
704
 
    _fmt = 'No submit branch available for branch "%(path)s"'
705
 
 
706
 
    def __init__(self, branch):
707
 
       import bzrlib.urlutils as urlutils
708
 
       self.path = urlutils.unescape_for_display(branch.base, 'ascii')
709
 
 
710
 
 
711
417
class AlreadyBranchError(PathError):
712
418
 
713
 
    _fmt = 'Already a branch: "%(path)s".'
 
419
    _fmt = "Already a branch: %(path)s."
714
420
 
715
421
 
716
422
class BranchExistsWithoutWorkingTree(PathError):
717
423
 
718
 
    _fmt = 'Directory contains a branch, but no working tree \
719
 
(use bzr checkout if you wish to build a working tree): "%(path)s"'
 
424
    _fmt = "Directory contains a branch, but no working tree \
 
425
(use bzr checkout if you wish to build a working tree): %(path)s"
720
426
 
721
427
 
722
428
class AtomicFileAlreadyClosed(PathError):
723
429
 
724
 
    _fmt = ('"%(function)s" called on an AtomicFile after it was closed:'
725
 
            ' "%(path)s"')
 
430
    _fmt = "'%(function)s' called on an AtomicFile after it was closed: %(path)s"
726
431
 
727
432
    def __init__(self, path, function):
728
433
        PathError.__init__(self, path=path, extra=None)
731
436
 
732
437
class InaccessibleParent(PathError):
733
438
 
734
 
    _fmt = ('Parent not accessible given base "%(base)s" and'
735
 
            ' relative path "%(path)s"')
 
439
    _fmt = "Parent not accessible given base %(base)s and relative path %(path)s"
736
440
 
737
441
    def __init__(self, path, base):
738
442
        PathError.__init__(self, path)
741
445
 
742
446
class NoRepositoryPresent(BzrError):
743
447
 
744
 
    _fmt = 'No repository present: "%(path)s"'
 
448
    _fmt = "No repository present: %(path)r"
745
449
    def __init__(self, bzrdir):
746
450
        BzrError.__init__(self)
747
451
        self.path = bzrdir.transport.clone('..').base
749
453
 
750
454
class FileInWrongBranch(BzrError):
751
455
 
752
 
    _fmt = 'File "%(path)s" is not in branch %(branch_base)s.'
 
456
    _fmt = "File %(path)s in not in branch %(branch_base)s."
753
457
 
754
458
    def __init__(self, branch, path):
755
459
        BzrError.__init__(self)
759
463
 
760
464
 
761
465
class UnsupportedFormatError(BzrError):
762
 
 
763
 
    _fmt = "Unsupported branch format: %(format)s\nPlease run 'bzr upgrade'"
 
466
    
 
467
    _fmt = "Unsupported branch format: %(format)s"
764
468
 
765
469
 
766
470
class UnknownFormatError(BzrError):
767
 
 
768
 
    _fmt = "Unknown %(kind)s format: %(format)r"
769
 
 
770
 
    def __init__(self, format, kind='branch'):
771
 
        self.kind = kind
772
 
        self.format = format
 
471
    
 
472
    _fmt = "Unknown branch format: %(format)r"
773
473
 
774
474
 
775
475
class IncompatibleFormat(BzrError):
776
 
 
 
476
    
777
477
    _fmt = "Format %(format)s is not compatible with .bzr version %(bzrdir)s."
778
478
 
779
479
    def __init__(self, format, bzrdir_format):
782
482
        self.bzrdir = bzrdir_format
783
483
 
784
484
 
785
 
class IncompatibleRepositories(BzrError):
786
 
 
787
 
    _fmt = "%(target)s\n" \
788
 
            "is not compatible with\n" \
789
 
            "%(source)s\n" \
790
 
            "%(details)s"
791
 
 
792
 
    def __init__(self, source, target, details=None):
793
 
        if details is None:
794
 
            details = "(no details)"
795
 
        BzrError.__init__(self, target=target, source=source, details=details)
796
 
 
797
 
 
798
485
class IncompatibleRevision(BzrError):
799
 
 
 
486
    
800
487
    _fmt = "Revision is not compatible with %(repo_format)s"
801
488
 
802
489
    def __init__(self, repo_format):
804
491
        self.repo_format = repo_format
805
492
 
806
493
 
807
 
class AlreadyVersionedError(BzrError):
808
 
    """Used when a path is expected not to be versioned, but it is."""
809
 
 
810
 
    _fmt = "%(context_info)s%(path)s is already versioned."
811
 
 
812
 
    def __init__(self, path, context_info=None):
813
 
        """Construct a new AlreadyVersionedError.
814
 
 
815
 
        :param path: This is the path which is versioned,
816
 
        which should be in a user friendly form.
817
 
        :param context_info: If given, this is information about the context,
818
 
        which could explain why this is expected to not be versioned.
819
 
        """
820
 
        BzrError.__init__(self)
821
 
        self.path = path
822
 
        if context_info is None:
823
 
            self.context_info = ''
824
 
        else:
825
 
            self.context_info = context_info + ". "
826
 
 
827
 
 
828
494
class NotVersionedError(BzrError):
829
 
    """Used when a path is expected to be versioned, but it is not."""
830
 
 
831
 
    _fmt = "%(context_info)s%(path)s is not versioned."
832
 
 
833
 
    def __init__(self, path, context_info=None):
834
 
        """Construct a new NotVersionedError.
835
 
 
836
 
        :param path: This is the path which is not versioned,
837
 
        which should be in a user friendly form.
838
 
        :param context_info: If given, this is information about the context,
839
 
        which could explain why this is expected to be versioned.
840
 
        """
 
495
 
 
496
    _fmt = "%(path)s is not versioned"
 
497
 
 
498
    def __init__(self, path):
841
499
        BzrError.__init__(self)
842
500
        self.path = path
843
 
        if context_info is None:
844
 
            self.context_info = ''
845
 
        else:
846
 
            self.context_info = context_info + ". "
847
501
 
848
502
 
849
503
class PathsNotVersionedError(BzrError):
850
 
    """Used when reporting several paths which are not versioned"""
 
504
    # used when reporting several paths are not versioned
851
505
 
852
506
    _fmt = "Path(s) are not versioned: %(paths_as_string)s"
853
507
 
860
514
 
861
515
class PathsDoNotExist(BzrError):
862
516
 
863
 
    _fmt = "Path(s) do not exist: %(paths_as_string)s%(extra)s"
 
517
    _fmt = "Path(s) do not exist: %(paths_as_string)s"
864
518
 
865
519
    # used when reporting that paths are neither versioned nor in the working
866
520
    # tree
867
521
 
868
 
    def __init__(self, paths, extra=None):
 
522
    def __init__(self, paths):
869
523
        # circular import
870
524
        from bzrlib.osutils import quotefn
871
525
        BzrError.__init__(self)
872
526
        self.paths = paths
873
527
        self.paths_as_string = ' '.join([quotefn(p) for p in paths])
874
 
        if extra:
875
 
            self.extra = ': ' + str(extra)
876
 
        else:
877
 
            self.extra = ''
878
528
 
879
529
 
880
530
class BadFileKindError(BzrError):
881
531
 
882
 
    _fmt = 'Cannot operate on "%(filename)s" of unsupported kind "%(kind)s"'
883
 
 
884
 
    def __init__(self, filename, kind):
885
 
        BzrError.__init__(self, filename=filename, kind=kind)
886
 
 
887
 
 
888
 
class BadFilenameEncoding(BzrError):
889
 
 
890
 
    _fmt = ('Filename %(filename)r is not valid in your current filesystem'
891
 
            ' encoding %(fs_encoding)s')
892
 
 
893
 
    def __init__(self, filename, fs_encoding):
894
 
        BzrError.__init__(self)
895
 
        self.filename = filename
896
 
        self.fs_encoding = fs_encoding
 
532
    _fmt = "Cannot operate on %(filename)s of unsupported kind %(kind)s"
897
533
 
898
534
 
899
535
class ForbiddenControlFileError(BzrError):
900
536
 
901
 
    _fmt = 'Cannot operate on "%(filename)s" because it is a control file'
902
 
 
903
 
 
904
 
class LockError(InternalBzrError):
905
 
 
906
 
    _fmt = "Lock error: %(msg)s"
 
537
    _fmt = "Cannot operate on %(filename)s because it is a control file"
 
538
 
 
539
 
 
540
class LockError(BzrError):
 
541
 
 
542
    _fmt = "Lock error: %(message)s"
907
543
 
908
544
    # All exceptions from the lock/unlock functions should be from
909
545
    # this exception class.  They will be translated as necessary. The
911
547
    #
912
548
    # New code should prefer to raise specific subclasses
913
549
    def __init__(self, message):
914
 
        # Python 2.5 uses a slot for StandardError.message,
915
 
        # so use a different variable name.  We now work around this in
916
 
        # BzrError.__str__, but this member name is kept for compatability.
917
 
        self.msg = message
918
 
 
919
 
 
920
 
class LockActive(LockError):
921
 
 
922
 
    _fmt = "The lock for '%(lock_description)s' is in use and cannot be broken."
923
 
 
924
 
    internal_error = False
925
 
 
926
 
    def __init__(self, lock_description):
927
 
        self.lock_description = lock_description
 
550
        self.message = message
928
551
 
929
552
 
930
553
class CommitNotPossible(LockError):
947
570
 
948
571
    _fmt = "A write attempt was made in a read only transaction on %(obj)s"
949
572
 
950
 
    # TODO: There should also be an error indicating that you need a write
951
 
    # lock and don't have any lock at all... mbp 20070226
952
 
 
953
573
    def __init__(self, obj):
954
574
        self.obj = obj
955
575
 
956
576
 
957
 
class LockFailed(LockError):
958
 
 
959
 
    internal_error = False
960
 
 
961
 
    _fmt = "Cannot lock %(lock)s: %(why)s"
962
 
 
963
 
    def __init__(self, lock, why):
964
 
        LockError.__init__(self, '')
965
 
        self.lock = lock
966
 
        self.why = why
967
 
 
968
 
 
969
577
class OutSideTransaction(BzrError):
970
578
 
971
 
    _fmt = ("A transaction related operation was attempted after"
972
 
            " the transaction finished.")
 
579
    _fmt = "A transaction related operation was attempted after the transaction finished."
973
580
 
974
581
 
975
582
class ObjectNotLocked(LockError):
976
583
 
977
584
    _fmt = "%(obj)r is not locked"
978
585
 
 
586
    internal_error = True
 
587
 
979
588
    # this can indicate that any particular object is not locked; see also
980
589
    # LockNotHeld which means that a particular *lock* object is not held by
981
590
    # the caller -- perhaps they should be unified.
993
602
 
994
603
class UnlockableTransport(LockError):
995
604
 
996
 
    internal_error = False
997
 
 
998
605
    _fmt = "Cannot lock: transport is read only: %(transport)s"
999
606
 
1000
607
    def __init__(self, transport):
1003
610
 
1004
611
class LockContention(LockError):
1005
612
 
1006
 
    _fmt = 'Could not acquire lock "%(lock)s": %(msg)s'
1007
 
    # TODO: show full url for lock, combining the transport and relative
1008
 
    # bits?
1009
 
 
1010
 
    internal_error = False
1011
 
 
1012
 
    def __init__(self, lock, msg=''):
 
613
    _fmt = "Could not acquire lock %(lock)s"
 
614
    # TODO: show full url for lock, combining the transport and relative bits?
 
615
    
 
616
    def __init__(self, lock):
1013
617
        self.lock = lock
1014
 
        self.msg = msg
1015
618
 
1016
619
 
1017
620
class LockBroken(LockError):
1018
621
 
1019
 
    _fmt = ("Lock was broken while still open: %(lock)s"
1020
 
            " - check storage consistency!")
1021
 
 
1022
 
    internal_error = False
 
622
    _fmt = "Lock was broken while still open: %(lock)s - check storage consistency!"
1023
623
 
1024
624
    def __init__(self, lock):
1025
625
        self.lock = lock
1027
627
 
1028
628
class LockBreakMismatch(LockError):
1029
629
 
1030
 
    _fmt = ("Lock was released and re-acquired before being broken:"
1031
 
            " %(lock)s: held by %(holder)r, wanted to break %(target)r")
1032
 
 
1033
 
    internal_error = False
 
630
    _fmt = "Lock was released and re-acquired before being broken: %(lock)s: held by %(holder)r, wanted to break %(target)r"
1034
631
 
1035
632
    def __init__(self, lock, holder, target):
1036
633
        self.lock = lock
1042
639
 
1043
640
    _fmt = "Lock not held: %(lock)s"
1044
641
 
1045
 
    internal_error = False
1046
 
 
1047
642
    def __init__(self, lock):
1048
643
        self.lock = lock
1049
644
 
1050
645
 
1051
 
class TokenLockingNotSupported(LockError):
1052
 
 
1053
 
    _fmt = "The object %(obj)s does not support token specifying a token when locking."
1054
 
 
1055
 
    def __init__(self, obj):
1056
 
        self.obj = obj
1057
 
 
1058
 
 
1059
 
class TokenMismatch(LockBroken):
1060
 
 
1061
 
    _fmt = "The lock token %(given_token)r does not match lock token %(lock_token)r."
1062
 
 
1063
 
    internal_error = True
1064
 
 
1065
 
    def __init__(self, given_token, lock_token):
1066
 
        self.given_token = given_token
1067
 
        self.lock_token = lock_token
1068
 
 
1069
 
 
1070
646
class PointlessCommit(BzrError):
1071
647
 
1072
648
    _fmt = "No changes to commit"
1073
649
 
1074
650
 
1075
 
class CannotCommitSelectedFileMerge(BzrError):
1076
 
 
1077
 
    _fmt = 'Selected-file commit of merges is not supported yet:'\
1078
 
        ' files %(files_str)s'
1079
 
 
1080
 
    def __init__(self, files):
1081
 
        files_str = ', '.join(files)
1082
 
        BzrError.__init__(self, files=files, files_str=files_str)
1083
 
 
1084
 
 
1085
 
class BadCommitMessageEncoding(BzrError):
1086
 
 
1087
 
    _fmt = 'The specified commit message contains characters unsupported by '\
1088
 
        'the current encoding.'
1089
 
 
1090
 
 
1091
651
class UpgradeReadonly(BzrError):
1092
652
 
1093
653
    _fmt = "Upgrade URL cannot work with readonly URLs."
1107
667
    _fmt = "Commit refused because there are unknowns in the tree."
1108
668
 
1109
669
 
1110
 
class NoSuchRevision(InternalBzrError):
1111
 
 
1112
 
    _fmt = "%(branch)s has no revision %(revision)s"
 
670
class NoSuchRevision(BzrError):
 
671
 
 
672
    _fmt = "Branch %(branch)s has no revision %(revision)s"
 
673
 
 
674
    internal_error = True
1113
675
 
1114
676
    def __init__(self, branch, revision):
1115
 
        # 'branch' may sometimes be an internal object like a KnitRevisionStore
1116
677
        BzrError.__init__(self, branch=branch, revision=revision)
1117
678
 
1118
679
 
1119
 
class RangeInChangeOption(BzrError):
1120
 
 
1121
 
    _fmt = "Option --change does not accept revision ranges"
1122
 
 
1123
 
 
1124
680
class NoSuchRevisionSpec(BzrError):
1125
681
 
1126
682
    _fmt = "No namespace registered for string: %(spec)r"
1129
685
        BzrError.__init__(self, spec=spec)
1130
686
 
1131
687
 
1132
 
class NoSuchRevisionInTree(NoSuchRevision):
1133
 
    """When using Tree.revision_tree, and the revision is not accessible."""
1134
 
 
1135
 
    _fmt = "The revision id {%(revision_id)s} is not present in the tree %(tree)s."
1136
 
 
1137
 
    def __init__(self, tree, revision_id):
1138
 
        BzrError.__init__(self)
1139
 
        self.tree = tree
1140
 
        self.revision_id = revision_id
1141
 
 
1142
 
 
1143
688
class InvalidRevisionSpec(BzrError):
1144
689
 
1145
 
    _fmt = ("Requested revision: %(spec)r does not exist in branch:"
1146
 
            " %(branch)s%(extra)s")
 
690
    _fmt = "Requested revision: %(spec)r does not exist in branch: %(branch)s%(extra)s"
1147
691
 
1148
692
    def __init__(self, spec, branch, extra=None):
1149
693
        BzrError.__init__(self, branch=branch, spec=spec)
1158
702
    _fmt = "%(branch)s is missing %(object_type)s {%(object_id)s}"
1159
703
 
1160
704
 
1161
 
class AppendRevisionsOnlyViolation(BzrError):
1162
 
 
1163
 
    _fmt = ('Operation denied because it would change the main history,'
1164
 
           ' which is not permitted by the append_revisions_only setting on'
1165
 
           ' branch "%(location)s".')
1166
 
 
1167
 
    def __init__(self, location):
1168
 
       import bzrlib.urlutils as urlutils
1169
 
       location = urlutils.unescape_for_display(location, 'ascii')
1170
 
       BzrError.__init__(self, location=location)
1171
 
 
1172
 
 
1173
705
class DivergedBranches(BzrError):
 
706
    
 
707
    _fmt = "These branches have diverged.  Use the merge command to reconcile them."""
1174
708
 
1175
 
    _fmt = ("These branches have diverged."
1176
 
            " Use the merge command to reconcile them.")
 
709
    internal_error = False
1177
710
 
1178
711
    def __init__(self, branch1, branch2):
1179
712
        self.branch1 = branch1
1180
713
        self.branch2 = branch2
1181
714
 
1182
715
 
1183
 
class NotLefthandHistory(InternalBzrError):
1184
 
 
1185
 
    _fmt = "Supplied history does not follow left-hand parents"
1186
 
 
1187
 
    def __init__(self, history):
1188
 
        BzrError.__init__(self, history=history)
1189
 
 
1190
 
 
1191
716
class UnrelatedBranches(BzrError):
1192
717
 
1193
 
    _fmt = ("Branches have no common ancestor, and"
1194
 
            " no merge base revision was specified.")
1195
 
 
1196
 
 
1197
 
class CannotReverseCherrypick(BzrError):
1198
 
 
1199
 
    _fmt = ('Selected merge cannot perform reverse cherrypicks.  Try merge3'
1200
 
            ' or diff3.')
 
718
    _fmt = "Branches have no common ancestor, and no merge base revision was specified."
 
719
 
 
720
    internal_error = False
1201
721
 
1202
722
 
1203
723
class NoCommonAncestor(BzrError):
1204
 
 
 
724
    
1205
725
    _fmt = "Revisions have no common ancestor: %(revision_a)s %(revision_b)s"
1206
726
 
1207
727
    def __init__(self, revision_a, revision_b):
1211
731
 
1212
732
class NoCommonRoot(BzrError):
1213
733
 
1214
 
    _fmt = ("Revisions are not derived from the same root: "
1215
 
           "%(revision_a)s %(revision_b)s.")
 
734
    _fmt = "Revisions are not derived from the same root: " \
 
735
           "%(revision_a)s %(revision_b)s."
1216
736
 
1217
737
    def __init__(self, revision_a, revision_b):
1218
738
        BzrError.__init__(self, revision_a=revision_a, revision_b=revision_b)
1241
761
    def __init__(self, bases):
1242
762
        warn("BzrError AmbiguousBase has been deprecated as of bzrlib 0.8.",
1243
763
                DeprecationWarning)
1244
 
        msg = ("The correct base is unclear, because %s are all equally close"
1245
 
                % ", ".join(bases))
 
764
        msg = "The correct base is unclear, because %s are all equally close" %\
 
765
            ", ".join(bases)
1246
766
        BzrError.__init__(self, msg)
1247
767
        self.bases = bases
1248
768
 
1249
769
 
1250
 
class NoCommits(BranchError):
 
770
class NoCommits(BzrError):
1251
771
 
1252
772
    _fmt = "Branch %(branch)s has no commits."
1253
773
 
 
774
    def __init__(self, branch):
 
775
        BzrError.__init__(self, branch=branch)
 
776
 
1254
777
 
1255
778
class UnlistableStore(BzrError):
1256
779
 
1267
790
 
1268
791
class BoundBranchOutOfDate(BzrError):
1269
792
 
1270
 
    _fmt = ("Bound branch %(branch)s is out of date with master branch"
1271
 
            " %(master)s.")
 
793
    _fmt = "Bound branch %(branch)s is out of date with master branch %(master)s."
1272
794
 
1273
795
    def __init__(self, branch, master):
1274
796
        BzrError.__init__(self)
1275
797
        self.branch = branch
1276
798
        self.master = master
1277
799
 
1278
 
 
 
800
        
1279
801
class CommitToDoubleBoundBranch(BzrError):
1280
802
 
1281
 
    _fmt = ("Cannot commit to branch %(branch)s."
1282
 
            " It is bound to %(master)s, which is bound to %(remote)s.")
 
803
    _fmt = "Cannot commit to branch %(branch)s. It is bound to %(master)s, which is bound to %(remote)s."
1283
804
 
1284
805
    def __init__(self, branch, master, remote):
1285
806
        BzrError.__init__(self)
1299
820
 
1300
821
class BoundBranchConnectionFailure(BzrError):
1301
822
 
1302
 
    _fmt = ("Unable to connect to target of bound branch %(branch)s"
1303
 
            " => %(target)s: %(error)s")
 
823
    _fmt = "Unable to connect to target of bound branch %(branch)s => %(target)s: %(error)s"
1304
824
 
1305
825
    def __init__(self, branch, target, error):
1306
826
        BzrError.__init__(self)
1311
831
 
1312
832
class WeaveError(BzrError):
1313
833
 
1314
 
    _fmt = "Error in processing weave: %(msg)s"
 
834
    _fmt = "Error in processing weave: %(message)s"
1315
835
 
1316
 
    def __init__(self, msg=None):
 
836
    def __init__(self, message=None):
1317
837
        BzrError.__init__(self)
1318
 
        self.msg = msg
 
838
        self.message = message
1319
839
 
1320
840
 
1321
841
class WeaveRevisionAlreadyPresent(WeaveError):
1350
870
 
1351
871
class WeaveParentMismatch(WeaveError):
1352
872
 
1353
 
    _fmt = "Parents are mismatched between two revisions. %(message)s"
1354
 
 
 
873
    _fmt = "Parents are mismatched between two revisions."
 
874
    
1355
875
 
1356
876
class WeaveInvalidChecksum(WeaveError):
1357
877
 
1360
880
 
1361
881
class WeaveTextDiffers(WeaveError):
1362
882
 
1363
 
    _fmt = ("Weaves differ on text content. Revision:"
1364
 
            " {%(revision_id)s}, %(weave_a)s, %(weave_b)s")
 
883
    _fmt = "Weaves differ on text content. Revision: {%(revision_id)s}, %(weave_a)s, %(weave_b)s"
1365
884
 
1366
885
    def __init__(self, revision_id, weave_a, weave_b):
1367
886
        WeaveError.__init__(self)
1372
891
 
1373
892
class WeaveTextDiffers(WeaveError):
1374
893
 
1375
 
    _fmt = ("Weaves differ on text content. Revision:"
1376
 
            " {%(revision_id)s}, %(weave_a)s, %(weave_b)s")
 
894
    _fmt = "Weaves differ on text content. Revision: {%(revision_id)s}, %(weave_a)s, %(weave_b)s"
1377
895
 
1378
896
    def __init__(self, revision_id, weave_a, weave_b):
1379
897
        WeaveError.__init__(self)
1383
901
 
1384
902
 
1385
903
class VersionedFileError(BzrError):
1386
 
 
 
904
    
1387
905
    _fmt = "Versioned file error"
1388
906
 
1389
907
 
1390
908
class RevisionNotPresent(VersionedFileError):
1391
 
 
1392
 
    _fmt = 'Revision {%(revision_id)s} not present in "%(file_id)s".'
 
909
    
 
910
    _fmt = "Revision {%(revision_id)s} not present in %(file_id)s."
1393
911
 
1394
912
    def __init__(self, revision_id, file_id):
1395
913
        VersionedFileError.__init__(self)
1398
916
 
1399
917
 
1400
918
class RevisionAlreadyPresent(VersionedFileError):
1401
 
 
1402
 
    _fmt = 'Revision {%(revision_id)s} already present in "%(file_id)s".'
 
919
    
 
920
    _fmt = "Revision {%(revision_id)s} already present in %(file_id)s."
1403
921
 
1404
922
    def __init__(self, revision_id, file_id):
1405
923
        VersionedFileError.__init__(self)
1407
925
        self.file_id = file_id
1408
926
 
1409
927
 
1410
 
class VersionedFileInvalidChecksum(VersionedFileError):
1411
 
 
1412
 
    _fmt = "Text did not match its checksum: %(message)s"
1413
 
 
1414
 
 
1415
 
class KnitError(InternalBzrError):
1416
 
 
 
928
class KnitError(BzrError):
 
929
    
1417
930
    _fmt = "Knit error"
1418
931
 
1419
932
 
 
933
class KnitHeaderError(KnitError):
 
934
 
 
935
    _fmt = "Knit header error: %(badline)r unexpected for file %(filename)s"
 
936
 
 
937
    def __init__(self, badline, filename):
 
938
        KnitError.__init__(self)
 
939
        self.badline = badline
 
940
        self.filename = filename
 
941
 
 
942
 
1420
943
class KnitCorrupt(KnitError):
1421
944
 
1422
945
    _fmt = "Knit %(filename)s corrupt: %(how)s"
1427
950
        self.how = how
1428
951
 
1429
952
 
1430
 
class SHA1KnitCorrupt(KnitCorrupt):
1431
 
 
1432
 
    _fmt = ("Knit %(filename)s corrupt: sha-1 of reconstructed text does not "
1433
 
        "match expected sha-1. key %(key)s expected sha %(expected)s actual "
1434
 
        "sha %(actual)s")
1435
 
 
1436
 
    def __init__(self, filename, actual, expected, key, content):
1437
 
        KnitError.__init__(self)
1438
 
        self.filename = filename
1439
 
        self.actual = actual
1440
 
        self.expected = expected
1441
 
        self.key = key
1442
 
        self.content = content
1443
 
 
1444
 
 
1445
 
class KnitDataStreamIncompatible(KnitError):
1446
 
    # Not raised anymore, as we can convert data streams.  In future we may
1447
 
    # need it again for more exotic cases, so we're keeping it around for now.
1448
 
 
1449
 
    _fmt = "Cannot insert knit data stream of format \"%(stream_format)s\" into knit of format \"%(target_format)s\"."
1450
 
 
1451
 
    def __init__(self, stream_format, target_format):
1452
 
        self.stream_format = stream_format
1453
 
        self.target_format = target_format
1454
 
 
1455
 
 
1456
 
class KnitDataStreamUnknown(KnitError):
1457
 
    # Indicates a data stream we don't know how to handle.
1458
 
 
1459
 
    _fmt = "Cannot parse knit data stream of format \"%(stream_format)s\"."
1460
 
 
1461
 
    def __init__(self, stream_format):
1462
 
        self.stream_format = stream_format
1463
 
 
1464
 
 
1465
 
class KnitHeaderError(KnitError):
1466
 
 
1467
 
    _fmt = 'Knit header error: %(badline)r unexpected for file "%(filename)s".'
1468
 
 
1469
 
    def __init__(self, badline, filename):
1470
 
        KnitError.__init__(self)
1471
 
        self.badline = badline
1472
 
        self.filename = filename
1473
 
 
1474
 
class KnitIndexUnknownMethod(KnitError):
1475
 
    """Raised when we don't understand the storage method.
1476
 
 
1477
 
    Currently only 'fulltext' and 'line-delta' are supported.
1478
 
    """
1479
 
 
1480
 
    _fmt = ("Knit index %(filename)s does not have a known method"
1481
 
            " in options: %(options)r")
1482
 
 
1483
 
    def __init__(self, filename, options):
1484
 
        KnitError.__init__(self)
1485
 
        self.filename = filename
1486
 
        self.options = options
1487
 
 
1488
 
 
1489
 
class RetryWithNewPacks(BzrError):
1490
 
    """Raised when we realize that the packs on disk have changed.
1491
 
 
1492
 
    This is meant as more of a signaling exception, to trap between where a
1493
 
    local error occurred and the code that can actually handle the error and
1494
 
    code that can retry appropriately.
1495
 
    """
1496
 
 
1497
 
    internal_error = True
1498
 
 
1499
 
    _fmt = ("Pack files have changed, reload and retry. context: %(context)s"
1500
 
            " %(orig_error)s")
1501
 
 
1502
 
    def __init__(self, context, reload_occurred, exc_info):
1503
 
        """create a new RetryWithNewPacks error.
1504
 
 
1505
 
        :param reload_occurred: Set to True if we know that the packs have
1506
 
            already been reloaded, and we are failing because of an in-memory
1507
 
            cache miss. If set to True then we will ignore if a reload says
1508
 
            nothing has changed, because we assume it has already reloaded. If
1509
 
            False, then a reload with nothing changed will force an error.
1510
 
        :param exc_info: The original exception traceback, so if there is a
1511
 
            problem we can raise the original error (value from sys.exc_info())
1512
 
        """
1513
 
        BzrError.__init__(self)
1514
 
        self.reload_occurred = reload_occurred
1515
 
        self.exc_info = exc_info
1516
 
        self.orig_error = exc_info[1]
1517
 
        # TODO: The global error handler should probably treat this by
1518
 
        #       raising/printing the original exception with a bit about
1519
 
        #       RetryWithNewPacks also not being caught
1520
 
 
1521
 
 
1522
 
class RetryAutopack(RetryWithNewPacks):
1523
 
    """Raised when we are autopacking and we find a missing file.
1524
 
 
1525
 
    Meant as a signaling exception, to tell the autopack code it should try
1526
 
    again.
1527
 
    """
1528
 
 
1529
 
    internal_error = True
1530
 
 
1531
 
    _fmt = ("Pack files have changed, reload and try autopack again."
1532
 
            " context: %(context)s %(orig_error)s")
1533
 
 
1534
 
 
1535
953
class NoSuchExportFormat(BzrError):
1536
 
 
 
954
    
1537
955
    _fmt = "Export format %(format)r not supported"
1538
956
 
1539
957
    def __init__(self, format):
1542
960
 
1543
961
 
1544
962
class TransportError(BzrError):
1545
 
 
 
963
    
1546
964
    _fmt = "Transport error: %(msg)s %(orig_error)s"
1547
965
 
1548
966
    def __init__(self, msg=None, orig_error=None):
1557
975
        BzrError.__init__(self)
1558
976
 
1559
977
 
1560
 
class TooManyConcurrentRequests(InternalBzrError):
1561
 
 
1562
 
    _fmt = ("The medium '%(medium)s' has reached its concurrent request limit."
1563
 
            " Be sure to finish_writing and finish_reading on the"
1564
 
            " currently open request.")
 
978
class TooManyConcurrentRequests(BzrError):
 
979
 
 
980
    _fmt = ("The medium '%(medium)s' has reached its concurrent request limit. "
 
981
            "Be sure to finish_writing and finish_reading on the "
 
982
            "current request that is open.")
 
983
 
 
984
    internal_error = True
1565
985
 
1566
986
    def __init__(self, medium):
1567
987
        self.medium = medium
1575
995
        self.details = details
1576
996
 
1577
997
 
1578
 
class UnexpectedProtocolVersionMarker(TransportError):
1579
 
 
1580
 
    _fmt = "Received bad protocol version marker: %(marker)r"
1581
 
 
1582
 
    def __init__(self, marker):
1583
 
        self.marker = marker
1584
 
 
1585
 
 
1586
 
class UnknownSmartMethod(InternalBzrError):
1587
 
 
1588
 
    _fmt = "The server does not recognise the '%(verb)s' request."
1589
 
 
1590
 
    def __init__(self, verb):
1591
 
        self.verb = verb
1592
 
 
1593
 
 
1594
 
class SmartMessageHandlerError(InternalBzrError):
1595
 
 
1596
 
    _fmt = ("The message handler raised an exception:\n"
1597
 
            "%(traceback_text)s")
1598
 
 
1599
 
    def __init__(self, exc_info):
1600
 
        import traceback
1601
 
        self.exc_type, self.exc_value, self.exc_tb = exc_info
1602
 
        self.exc_info = exc_info
1603
 
        traceback_strings = traceback.format_exception(
1604
 
                self.exc_type, self.exc_value, self.exc_tb)
1605
 
        self.traceback_text = ''.join(traceback_strings)
1606
 
 
1607
 
 
1608
998
# A set of semi-meaningful errors which can be thrown
1609
999
class TransportNotPossible(TransportError):
1610
1000
 
1635
1025
            self.port = ':%s' % port
1636
1026
 
1637
1027
 
1638
 
# XXX: This is also used for unexpected end of file, which is different at the
1639
 
# TCP level from "connection reset".
1640
1028
class ConnectionReset(TransportError):
1641
1029
 
1642
1030
    _fmt = "Connection closed: %(msg)s %(orig_error)s"
1644
1032
 
1645
1033
class InvalidRange(TransportError):
1646
1034
 
1647
 
    _fmt = "Invalid range access in %(path)s at %(offset)s: %(msg)s"
1648
 
 
1649
 
    def __init__(self, path, offset, msg=None):
1650
 
        TransportError.__init__(self, msg)
 
1035
    _fmt = "Invalid range access in %(path)s at %(offset)s."
 
1036
    
 
1037
    def __init__(self, path, offset):
 
1038
        TransportError.__init__(self, ("Invalid range access in %s at %d"
 
1039
                                       % (path, offset)))
1651
1040
        self.path = path
1652
1041
        self.offset = offset
1653
1042
 
1664
1053
class InvalidHttpRange(InvalidHttpResponse):
1665
1054
 
1666
1055
    _fmt = "Invalid http range %(range)r for %(path)s: %(msg)s"
1667
 
 
 
1056
    
1668
1057
    def __init__(self, path, range, msg):
1669
1058
        self.range = range
1670
1059
        InvalidHttpResponse.__init__(self, path, msg)
1673
1062
class InvalidHttpContentType(InvalidHttpResponse):
1674
1063
 
1675
1064
    _fmt = 'Invalid http Content-type "%(ctype)s" for %(path)s: %(msg)s'
1676
 
 
 
1065
    
1677
1066
    def __init__(self, path, ctype, msg):
1678
1067
        self.ctype = ctype
1679
1068
        InvalidHttpResponse.__init__(self, path, msg)
1680
1069
 
1681
1070
 
1682
 
class RedirectRequested(TransportError):
1683
 
 
1684
 
    _fmt = '%(source)s is%(permanently)s redirected to %(target)s'
1685
 
 
1686
 
    def __init__(self, source, target, is_permanent=False):
1687
 
        self.source = source
1688
 
        self.target = target
1689
 
        if is_permanent:
1690
 
            self.permanently = ' permanently'
1691
 
        else:
1692
 
            self.permanently = ''
1693
 
        TransportError.__init__(self)
1694
 
 
1695
 
 
1696
 
class TooManyRedirections(TransportError):
1697
 
 
1698
 
    _fmt = "Too many redirections"
1699
 
 
1700
 
 
1701
1071
class ConflictsInTree(BzrError):
1702
1072
 
1703
1073
    _fmt = "Working tree has conflicts."
1709
1079
        if filename is None:
1710
1080
            filename = ""
1711
1081
        message = "Error(s) parsing config file %s:\n%s" % \
1712
 
            (filename, ('\n'.join(e.msg for e in errors)))
 
1082
            (filename, ('\n'.join(e.message for e in errors)))
1713
1083
        BzrError.__init__(self, message)
1714
1084
 
1715
1085
 
1724
1094
 
1725
1095
class SigningFailed(BzrError):
1726
1096
 
1727
 
    _fmt = 'Failed to gpg sign data with command "%(command_line)s"'
 
1097
    _fmt = "Failed to gpg sign data with command %(command_line)r"
1728
1098
 
1729
1099
    def __init__(self, command_line):
1730
1100
        BzrError.__init__(self, command_line=command_line)
1732
1102
 
1733
1103
class WorkingTreeNotRevision(BzrError):
1734
1104
 
1735
 
    _fmt = ("The working tree for %(basedir)s has changed since"
 
1105
    _fmt = ("The working tree for %(basedir)s has changed since" 
1736
1106
            " the last commit, but weave merge requires that it be"
1737
1107
            " unchanged")
1738
1108
 
1742
1112
 
1743
1113
class CantReprocessAndShowBase(BzrError):
1744
1114
 
1745
 
    _fmt = ("Can't reprocess and show base, because reprocessing obscures "
1746
 
           "the relationship of conflicting lines to the base")
 
1115
    _fmt = "Can't reprocess and show base, because reprocessing obscures " \
 
1116
           "the relationship of conflicting lines to the base"
1747
1117
 
1748
1118
 
1749
1119
class GraphCycleError(BzrError):
1755
1125
        self.graph = graph
1756
1126
 
1757
1127
 
1758
 
class WritingCompleted(InternalBzrError):
 
1128
class WritingCompleted(BzrError):
1759
1129
 
1760
1130
    _fmt = ("The MediumRequest '%(request)s' has already had finish_writing "
1761
1131
            "called upon it - accept bytes may not be called anymore.")
1762
1132
 
 
1133
    internal_error = True
 
1134
 
1763
1135
    def __init__(self, request):
1764
1136
        self.request = request
1765
1137
 
1766
1138
 
1767
 
class WritingNotComplete(InternalBzrError):
 
1139
class WritingNotComplete(BzrError):
1768
1140
 
1769
1141
    _fmt = ("The MediumRequest '%(request)s' has not has finish_writing "
1770
1142
            "called upon it - until the write phase is complete no "
1771
1143
            "data may be read.")
1772
1144
 
 
1145
    internal_error = True
 
1146
 
1773
1147
    def __init__(self, request):
1774
1148
        self.request = request
1775
1149
 
1783
1157
        self.filename = filename
1784
1158
 
1785
1159
 
1786
 
class MediumNotConnected(InternalBzrError):
 
1160
class MediumNotConnected(BzrError):
1787
1161
 
1788
1162
    _fmt = """The medium '%(medium)s' is not connected."""
1789
1163
 
 
1164
    internal_error = True
 
1165
 
1790
1166
    def __init__(self, medium):
1791
1167
        self.medium = medium
1792
1168
 
1793
1169
 
1794
1170
class MustUseDecorated(Exception):
1795
 
 
1796
 
    _fmt = "A decorating function has requested its original command be used."
1797
 
 
 
1171
    
 
1172
    _fmt = """A decorating function has requested its original command be used."""
 
1173
    
1798
1174
 
1799
1175
class NoBundleFound(BzrError):
1800
1176
 
1801
 
    _fmt = 'No bundle was found in "%(filename)s".'
 
1177
    _fmt = "No bundle was found in %(filename)s"
1802
1178
 
1803
1179
    def __init__(self, filename):
1804
1180
        BzrError.__init__(self)
1817
1193
 
1818
1194
class MissingText(BzrError):
1819
1195
 
1820
 
    _fmt = ("Branch %(base)s is missing revision"
1821
 
            " %(text_revision)s of %(file_id)s")
 
1196
    _fmt = "Branch %(base)s is missing revision %(text_revision)s of %(file_id)s"
1822
1197
 
1823
1198
    def __init__(self, branch, text_revision, file_id):
1824
1199
        BzrError.__init__(self)
1828
1203
        self.file_id = file_id
1829
1204
 
1830
1205
 
1831
 
class DuplicateFileId(BzrError):
1832
 
 
1833
 
    _fmt = "File id {%(file_id)s} already exists in inventory as %(entry)s"
1834
 
 
1835
 
    def __init__(self, file_id, entry):
1836
 
        BzrError.__init__(self)
1837
 
        self.file_id = file_id
1838
 
        self.entry = entry
1839
 
 
1840
 
 
1841
1206
class DuplicateKey(BzrError):
1842
1207
 
1843
1208
    _fmt = "Key %(key)s is already present in map"
1844
1209
 
1845
1210
 
1846
 
class DuplicateHelpPrefix(BzrError):
1847
 
 
1848
 
    _fmt = "The prefix %(prefix)s is in the help search path twice."
1849
 
 
1850
 
    def __init__(self, prefix):
1851
 
        self.prefix = prefix
1852
 
 
1853
 
 
1854
1211
class MalformedTransform(BzrError):
1855
1212
 
1856
1213
    _fmt = "Tree transform is malformed %(conflicts)r"
1868
1225
        self.root_trans_id = transform.root
1869
1226
 
1870
1227
 
1871
 
class BzrBadParameter(InternalBzrError):
 
1228
class BzrBadParameter(BzrError):
1872
1229
 
1873
1230
    _fmt = "Bad parameter: %(param)r"
1874
1231
 
1895
1252
    _fmt = "Moving the root directory is not supported at this time"
1896
1253
 
1897
1254
 
1898
 
class BzrMoveFailedError(BzrError):
1899
 
 
1900
 
    _fmt = "Could not move %(from_path)s%(operator)s %(to_path)s%(extra)s"
1901
 
 
1902
 
    def __init__(self, from_path='', to_path='', extra=None):
1903
 
        from bzrlib.osutils import splitpath
1904
 
        BzrError.__init__(self)
1905
 
        if extra:
1906
 
            self.extra = ': ' + str(extra)
1907
 
        else:
1908
 
            self.extra = ''
1909
 
 
1910
 
        has_from = len(from_path) > 0
1911
 
        has_to = len(to_path) > 0
1912
 
        if has_from:
1913
 
            self.from_path = splitpath(from_path)[-1]
1914
 
        else:
1915
 
            self.from_path = ''
1916
 
 
1917
 
        if has_to:
1918
 
            self.to_path = splitpath(to_path)[-1]
1919
 
        else:
1920
 
            self.to_path = ''
1921
 
 
1922
 
        self.operator = ""
1923
 
        if has_from and has_to:
1924
 
            self.operator = " =>"
1925
 
        elif has_from:
1926
 
            self.from_path = "from " + from_path
1927
 
        elif has_to:
1928
 
            self.operator = "to"
1929
 
        else:
1930
 
            self.operator = "file"
1931
 
 
1932
 
 
1933
 
class BzrRenameFailedError(BzrMoveFailedError):
1934
 
 
1935
 
    _fmt = "Could not rename %(from_path)s%(operator)s %(to_path)s%(extra)s"
1936
 
 
1937
 
    def __init__(self, from_path, to_path, extra=None):
1938
 
        BzrMoveFailedError.__init__(self, from_path, to_path, extra)
1939
 
 
1940
 
class BzrRemoveChangedFilesError(BzrError):
1941
 
    """Used when user is trying to remove changed files."""
1942
 
 
1943
 
    _fmt = ("Can't safely remove modified or unknown files:\n"
1944
 
        "%(changes_as_text)s"
1945
 
        "Use --keep to not delete them, or --force to delete them regardless.")
1946
 
 
1947
 
    def __init__(self, tree_delta):
1948
 
        BzrError.__init__(self)
1949
 
        self.changes_as_text = tree_delta.get_changes_as_text()
1950
 
        #self.paths_as_string = '\n'.join(changed_files)
1951
 
        #self.paths_as_string = '\n'.join([quotefn(p) for p in changed_files])
1952
 
 
1953
 
 
1954
1255
class BzrBadParameterNotString(BzrBadParameter):
1955
1256
 
1956
1257
    _fmt = "Parameter %(param)s is not a string or unicode string."
1963
1264
 
1964
1265
class BzrBadParameterUnicode(BzrBadParameter):
1965
1266
 
1966
 
    _fmt = ("Parameter %(param)s is unicode but"
1967
 
            " only byte-strings are permitted.")
 
1267
    _fmt = "Parameter %(param)s is unicode but only byte-strings are permitted."
1968
1268
 
1969
1269
 
1970
1270
class BzrBadParameterContainsNewline(BzrBadParameter):
2012
1312
        self.format = format
2013
1313
 
2014
1314
 
2015
 
class NoDiffFound(BzrError):
2016
 
 
2017
 
    _fmt = 'Could not find an appropriate Differ for file "%(path)s"'
2018
 
 
2019
 
    def __init__(self, path):
2020
 
        BzrError.__init__(self, path)
2021
 
 
2022
 
 
2023
 
class ExecutableMissing(BzrError):
2024
 
 
2025
 
    _fmt = "%(exe_name)s could not be found on this machine"
2026
 
 
2027
 
    def __init__(self, exe_name):
2028
 
        BzrError.__init__(self, exe_name=exe_name)
2029
 
 
2030
 
 
2031
1315
class NoDiff(BzrError):
2032
1316
 
2033
1317
    _fmt = "Diff is not installed on this machine: %(msg)s"
2041
1325
    _fmt = "Diff3 is not installed on this machine."
2042
1326
 
2043
1327
 
2044
 
class ExistingContent(BzrError):
2045
 
    # Added in bzrlib 0.92, used by VersionedFile.add_lines.
2046
 
 
2047
 
    _fmt = "The content being inserted is already present."
2048
 
 
2049
 
 
2050
1328
class ExistingLimbo(BzrError):
2051
1329
 
2052
1330
    _fmt = """This tree contains left-over files from a failed operation.
2053
1331
    Please examine %(limbo_dir)s to see if it contains any files you wish to
2054
1332
    keep, and delete it when you are done."""
2055
 
 
 
1333
    
2056
1334
    def __init__(self, limbo_dir):
2057
1335
       BzrError.__init__(self)
2058
1336
       self.limbo_dir = limbo_dir
2059
1337
 
2060
1338
 
2061
 
class ExistingPendingDeletion(BzrError):
2062
 
 
2063
 
    _fmt = """This tree contains left-over files from a failed operation.
2064
 
    Please examine %(pending_deletion)s to see if it contains any files you
2065
 
    wish to keep, and delete it when you are done."""
2066
 
 
2067
 
    def __init__(self, pending_deletion):
2068
 
       BzrError.__init__(self, pending_deletion=pending_deletion)
2069
 
 
2070
 
 
2071
1339
class ImmortalLimbo(BzrError):
2072
1340
 
2073
 
    _fmt = """Unable to delete transform temporary directory %(limbo_dir)s.
 
1341
    _fmt = """Unable to delete transform temporary directory $(limbo_dir)s.
2074
1342
    Please examine %(limbo_dir)s to see if it contains any files you wish to
2075
1343
    keep, and delete it when you are done."""
2076
1344
 
2079
1347
       self.limbo_dir = limbo_dir
2080
1348
 
2081
1349
 
2082
 
class ImmortalPendingDeletion(BzrError):
2083
 
 
2084
 
    _fmt = ("Unable to delete transform temporary directory "
2085
 
    "%(pending_deletion)s.  Please examine %(pending_deletion)s to see if it "
2086
 
    "contains any files you wish to keep, and delete it when you are done.")
2087
 
 
2088
 
    def __init__(self, pending_deletion):
2089
 
       BzrError.__init__(self, pending_deletion=pending_deletion)
2090
 
 
2091
 
 
2092
1350
class OutOfDateTree(BzrError):
2093
1351
 
2094
1352
    _fmt = "Working tree is out of date, please run 'bzr update'."
2098
1356
        self.tree = tree
2099
1357
 
2100
1358
 
2101
 
class PublicBranchOutOfDate(BzrError):
2102
 
 
2103
 
    _fmt = 'Public branch "%(public_location)s" lacks revision '\
2104
 
        '"%(revstring)s".'
2105
 
 
2106
 
    def __init__(self, public_location, revstring):
2107
 
        import bzrlib.urlutils as urlutils
2108
 
        public_location = urlutils.unescape_for_display(public_location,
2109
 
                                                        'ascii')
2110
 
        BzrError.__init__(self, public_location=public_location,
2111
 
                          revstring=revstring)
2112
 
 
2113
 
 
2114
1359
class MergeModifiedFormatError(BzrError):
2115
1360
 
2116
1361
    _fmt = "Error in merge modified format"
2121
1366
    _fmt = "Format error in conflict listings"
2122
1367
 
2123
1368
 
2124
 
class CorruptDirstate(BzrError):
2125
 
 
2126
 
    _fmt = ("Inconsistency in dirstate file %(dirstate_path)s.\n"
2127
 
            "Error: %(description)s")
2128
 
 
2129
 
    def __init__(self, dirstate_path, description):
2130
 
        BzrError.__init__(self)
2131
 
        self.dirstate_path = dirstate_path
2132
 
        self.description = description
2133
 
 
2134
 
 
2135
1369
class CorruptRepository(BzrError):
2136
1370
 
2137
 
    _fmt = ("An error has been detected in the repository %(repo_path)s.\n"
2138
 
            "Please run bzr reconcile on this repository.")
 
1371
    _fmt = """An error has been detected in the repository %(repo_path)s.
 
1372
Please run bzr reconcile on this repository."""
2139
1373
 
2140
1374
    def __init__(self, repo):
2141
1375
        BzrError.__init__(self)
2142
1376
        self.repo_path = repo.bzrdir.root_transport.base
2143
1377
 
2144
1378
 
2145
 
class InconsistentDelta(BzrError):
2146
 
    """Used when we get a delta that is not valid."""
2147
 
 
2148
 
    _fmt = ("An inconsistent delta was supplied involving %(path)r,"
2149
 
            " %(file_id)r\nreason: %(reason)s")
2150
 
 
2151
 
    def __init__(self, path, file_id, reason):
2152
 
        BzrError.__init__(self)
2153
 
        self.path = path
2154
 
        self.file_id = file_id
2155
 
        self.reason = reason
2156
 
 
2157
 
 
2158
1379
class UpgradeRequired(BzrError):
2159
1380
 
2160
1381
    _fmt = "To use this feature you must upgrade your branch at %(path)s."
2164
1385
        self.path = path
2165
1386
 
2166
1387
 
2167
 
class RepositoryUpgradeRequired(UpgradeRequired):
2168
 
 
2169
 
    _fmt = "To use this feature you must upgrade your repository at %(path)s."
2170
 
 
2171
 
 
2172
1388
class LocalRequiresBoundBranch(BzrError):
2173
1389
 
2174
1390
    _fmt = "Cannot perform local-only commits on unbound branches."
2175
1391
 
2176
1392
 
 
1393
class MissingProgressBarFinish(BzrError):
 
1394
 
 
1395
    _fmt = "A nested progress bar was not 'finished' correctly."
 
1396
 
 
1397
 
2177
1398
class InvalidProgressBarType(BzrError):
2178
1399
 
2179
 
    _fmt = ("Environment variable BZR_PROGRESS_BAR='%(bar_type)s"
2180
 
            " is not a supported type Select one of: %(valid_types)s")
 
1400
    _fmt = """Environment variable BZR_PROGRESS_BAR='%(bar_type)s is not a supported type
 
1401
Select one of: %(valid_types)s"""
2181
1402
 
2182
1403
    def __init__(self, bar_type, valid_types):
2183
1404
        BzrError.__init__(self, bar_type=bar_type, valid_types=valid_types)
2185
1406
 
2186
1407
class UnsupportedOperation(BzrError):
2187
1408
 
2188
 
    _fmt = ("The method %(mname)s is not supported on"
2189
 
            " objects of type %(tname)s.")
 
1409
    _fmt = "The method %(mname)s is not supported on objects of type %(tname)s."
2190
1410
 
2191
1411
    def __init__(self, method, method_self):
2192
1412
        self.method = method
2199
1419
 
2200
1420
 
2201
1421
class NonAsciiRevisionId(UnsupportedOperation):
2202
 
    """Raised when a commit is attempting to set a non-ascii revision id
2203
 
       but cant.
2204
 
    """
 
1422
    """Raised when a commit is attempting to set a non-ascii revision id but cant."""
2205
1423
 
2206
1424
 
2207
1425
class BinaryFile(BzrError):
2208
 
 
 
1426
    
2209
1427
    _fmt = "File is binary but should be text."
2210
1428
 
2211
1429
 
2220
1438
 
2221
1439
class TestamentMismatch(BzrError):
2222
1440
 
2223
 
    _fmt = """Testament did not match expected value.
2224
 
       For revision_id {%(revision_id)s}, expected {%(expected)s}, measured
 
1441
    _fmt = """Testament did not match expected value.  
 
1442
       For revision_id {%(revision_id)s}, expected {%(expected)s}, measured 
2225
1443
       {%(measured)s}"""
2226
1444
 
2227
1445
    def __init__(self, revision_id, expected, measured):
2231
1449
 
2232
1450
 
2233
1451
class NotABundle(BzrError):
2234
 
 
 
1452
    
2235
1453
    _fmt = "Not a bzr revision-bundle: %(text)r"
2236
1454
 
2237
1455
    def __init__(self, text):
2239
1457
        self.text = text
2240
1458
 
2241
1459
 
2242
 
class BadBundle(BzrError):
2243
 
 
 
1460
class BadBundle(BzrError): 
 
1461
    
2244
1462
    _fmt = "Bad bzr revision-bundle: %(text)r"
2245
1463
 
2246
1464
    def __init__(self, text):
2248
1466
        self.text = text
2249
1467
 
2250
1468
 
2251
 
class MalformedHeader(BadBundle):
2252
 
 
 
1469
class MalformedHeader(BadBundle): 
 
1470
    
2253
1471
    _fmt = "Malformed bzr revision-bundle header: %(text)r"
2254
1472
 
2255
1473
 
2256
 
class MalformedPatches(BadBundle):
2257
 
 
 
1474
class MalformedPatches(BadBundle): 
 
1475
    
2258
1476
    _fmt = "Malformed patches in bzr revision-bundle: %(text)r"
2259
1477
 
2260
1478
 
2261
 
class MalformedFooter(BadBundle):
2262
 
 
 
1479
class MalformedFooter(BadBundle): 
 
1480
    
2263
1481
    _fmt = "Malformed footer in bzr revision-bundle: %(text)r"
2264
1482
 
2265
1483
 
2266
1484
class UnsupportedEOLMarker(BadBundle):
2267
 
 
2268
 
    _fmt = "End of line marker was not \\n in bzr revision-bundle"
 
1485
    
 
1486
    _fmt = "End of line marker was not \\n in bzr revision-bundle"    
2269
1487
 
2270
1488
    def __init__(self):
2271
 
        # XXX: BadBundle's constructor assumes there's explanatory text,
 
1489
        # XXX: BadBundle's constructor assumes there's explanatory text, 
2272
1490
        # but for this there is not
2273
1491
        BzrError.__init__(self)
2274
1492
 
2275
1493
 
2276
1494
class IncompatibleBundleFormat(BzrError):
2277
 
 
 
1495
    
2278
1496
    _fmt = "Bundle format %(bundle_format)s is incompatible with %(other)s"
2279
1497
 
2280
1498
    def __init__(self, bundle_format, other):
2284
1502
 
2285
1503
 
2286
1504
class BadInventoryFormat(BzrError):
2287
 
 
 
1505
    
2288
1506
    _fmt = "Root class for inventory serialization errors"
2289
1507
 
2290
1508
 
2296
1514
        BadInventoryFormat.__init__(self, msg=msg)
2297
1515
 
2298
1516
 
2299
 
class RootNotRich(BzrError):
2300
 
 
2301
 
    _fmt = """This operation requires rich root data storage"""
2302
 
 
2303
 
 
2304
 
class NoSmartMedium(InternalBzrError):
 
1517
class NoSmartMedium(BzrError):
2305
1518
 
2306
1519
    _fmt = "The transport '%(transport)s' cannot tunnel the smart protocol."
2307
1520
 
2309
1522
        self.transport = transport
2310
1523
 
2311
1524
 
 
1525
class NoSmartServer(NotBranchError):
 
1526
 
 
1527
    _fmt = "No smart server available at %(url)s"
 
1528
 
 
1529
    def __init__(self, url):
 
1530
        self.url = url
 
1531
 
 
1532
 
2312
1533
class UnknownSSH(BzrError):
2313
1534
 
2314
1535
    _fmt = "Unrecognised value for BZR_SSH environment variable: %(vendor)s"
2318
1539
        self.vendor = vendor
2319
1540
 
2320
1541
 
2321
 
class SSHVendorNotFound(BzrError):
2322
 
 
2323
 
    _fmt = ("Don't know how to handle SSH connections."
2324
 
            " Please set BZR_SSH environment variable.")
2325
 
 
2326
 
 
2327
 
class GhostRevisionsHaveNoRevno(BzrError):
2328
 
    """When searching for revnos, if we encounter a ghost, we are stuck"""
2329
 
 
2330
 
    _fmt = ("Could not determine revno for {%(revision_id)s} because"
2331
 
            " its ancestry shows a ghost at {%(ghost_revision_id)s}")
2332
 
 
2333
 
    def __init__(self, revision_id, ghost_revision_id):
2334
 
        self.revision_id = revision_id
2335
 
        self.ghost_revision_id = ghost_revision_id
2336
 
 
2337
 
 
2338
1542
class GhostRevisionUnusableHere(BzrError):
2339
1543
 
2340
1544
    _fmt = "Ghost revision {%(revision_id)s} cannot be used here."
2344
1548
        self.revision_id = revision_id
2345
1549
 
2346
1550
 
2347
 
class IllegalUseOfScopeReplacer(InternalBzrError):
2348
 
 
2349
 
    _fmt = ("ScopeReplacer object %(name)r was used incorrectly:"
2350
 
            " %(msg)s%(extra)s")
 
1551
class IllegalUseOfScopeReplacer(BzrError):
 
1552
 
 
1553
    _fmt = "ScopeReplacer object %(name)r was used incorrectly: %(msg)s%(extra)s"
 
1554
 
 
1555
    internal_error = True
2351
1556
 
2352
1557
    def __init__(self, name, msg, extra=None):
2353
1558
        BzrError.__init__(self)
2359
1564
            self.extra = ''
2360
1565
 
2361
1566
 
2362
 
class InvalidImportLine(InternalBzrError):
 
1567
class InvalidImportLine(BzrError):
2363
1568
 
2364
1569
    _fmt = "Not a valid import statement: %(msg)\n%(text)s"
2365
1570
 
 
1571
    internal_error = True
 
1572
 
2366
1573
    def __init__(self, text, msg):
2367
1574
        BzrError.__init__(self)
2368
1575
        self.text = text
2369
1576
        self.msg = msg
2370
1577
 
2371
1578
 
2372
 
class ImportNameCollision(InternalBzrError):
2373
 
 
2374
 
    _fmt = ("Tried to import an object to the same name as"
2375
 
            " an existing object. %(name)s")
2376
 
 
2377
 
    def __init__(self, name):
2378
 
        BzrError.__init__(self)
2379
 
        self.name = name
2380
 
 
2381
 
 
2382
 
class NotAMergeDirective(BzrError):
2383
 
    """File starting with %(firstline)r is not a merge directive"""
2384
 
    def __init__(self, firstline):
2385
 
        BzrError.__init__(self, firstline=firstline)
2386
 
 
2387
 
 
2388
 
class NoMergeSource(BzrError):
2389
 
    """Raise if no merge source was specified for a merge directive"""
2390
 
 
2391
 
    _fmt = "A merge directive must provide either a bundle or a public"\
2392
 
        " branch location."
2393
 
 
2394
 
 
2395
 
class IllegalMergeDirectivePayload(BzrError):
2396
 
    """A merge directive contained something other than a patch or bundle"""
2397
 
 
2398
 
    _fmt = "Bad merge directive payload %(start)r"
2399
 
 
2400
 
    def __init__(self, start):
2401
 
        BzrError(self)
2402
 
        self.start = start
2403
 
 
2404
 
 
2405
 
class PatchVerificationFailed(BzrError):
2406
 
    """A patch from a merge directive could not be verified"""
2407
 
 
2408
 
    _fmt = "Preview patch does not match requested changes."
2409
 
 
2410
 
 
2411
 
class PatchMissing(BzrError):
2412
 
    """Raise a patch type was specified but no patch supplied"""
2413
 
 
2414
 
    _fmt = "Patch_type was %(patch_type)s, but no patch was supplied."
2415
 
 
2416
 
    def __init__(self, patch_type):
2417
 
        BzrError.__init__(self)
2418
 
        self.patch_type = patch_type
2419
 
 
2420
 
 
2421
 
class TargetNotBranch(BzrError):
2422
 
    """A merge directive's target branch is required, but isn't a branch"""
2423
 
 
2424
 
    _fmt = ("Your branch does not have all of the revisions required in "
2425
 
            "order to merge this merge directive and the target "
2426
 
            "location specified in the merge directive is not a branch: "
2427
 
            "%(location)s.")
2428
 
 
2429
 
    def __init__(self, location):
2430
 
        BzrError.__init__(self)
2431
 
        self.location = location
2432
 
 
2433
 
 
2434
 
class UnsupportedInventoryKind(BzrError):
2435
 
 
2436
 
    _fmt = """Unsupported entry kind %(kind)s"""
2437
 
 
2438
 
    def __init__(self, kind):
2439
 
        self.kind = kind
2440
 
 
2441
 
 
2442
 
class BadSubsumeSource(BzrError):
2443
 
 
2444
 
    _fmt = "Can't subsume %(other_tree)s into %(tree)s. %(reason)s"
2445
 
 
2446
 
    def __init__(self, tree, other_tree, reason):
2447
 
        self.tree = tree
2448
 
        self.other_tree = other_tree
2449
 
        self.reason = reason
2450
 
 
2451
 
 
2452
 
class SubsumeTargetNeedsUpgrade(BzrError):
2453
 
 
2454
 
    _fmt = """Subsume target %(other_tree)s needs to be upgraded."""
2455
 
 
2456
 
    def __init__(self, other_tree):
2457
 
        self.other_tree = other_tree
2458
 
 
2459
 
 
2460
 
class BadReferenceTarget(InternalBzrError):
2461
 
 
2462
 
    _fmt = "Can't add reference to %(other_tree)s into %(tree)s." \
2463
 
           "%(reason)s"
2464
 
 
2465
 
    def __init__(self, tree, other_tree, reason):
2466
 
        self.tree = tree
2467
 
        self.other_tree = other_tree
2468
 
        self.reason = reason
2469
 
 
2470
 
 
2471
 
class NoSuchTag(BzrError):
2472
 
 
2473
 
    _fmt = "No such tag: %(tag_name)s"
2474
 
 
2475
 
    def __init__(self, tag_name):
2476
 
        self.tag_name = tag_name
2477
 
 
2478
 
 
2479
 
class TagsNotSupported(BzrError):
2480
 
 
2481
 
    _fmt = ("Tags not supported by %(branch)s;"
2482
 
            " you may be able to use bzr upgrade.")
2483
 
 
2484
 
    def __init__(self, branch):
2485
 
        self.branch = branch
2486
 
 
2487
 
 
2488
 
class TagAlreadyExists(BzrError):
2489
 
 
2490
 
    _fmt = "Tag %(tag_name)s already exists."
2491
 
 
2492
 
    def __init__(self, tag_name):
2493
 
        self.tag_name = tag_name
2494
 
 
2495
 
 
2496
 
class MalformedBugIdentifier(BzrError):
2497
 
 
2498
 
    _fmt = ('Did not understand bug identifier %(bug_id)s: %(reason)s. '
2499
 
            'See "bzr help bugs" for more information on this feature.')
2500
 
 
2501
 
    def __init__(self, bug_id, reason):
2502
 
        self.bug_id = bug_id
2503
 
        self.reason = reason
2504
 
 
2505
 
 
2506
 
class InvalidBugTrackerURL(BzrError):
2507
 
 
2508
 
    _fmt = ("The URL for bug tracker \"%(abbreviation)s\" doesn't "
2509
 
            "contain {id}: %(url)s")
2510
 
 
2511
 
    def __init__(self, abbreviation, url):
2512
 
        self.abbreviation = abbreviation
2513
 
        self.url = url
2514
 
 
2515
 
 
2516
 
class UnknownBugTrackerAbbreviation(BzrError):
2517
 
 
2518
 
    _fmt = ("Cannot find registered bug tracker called %(abbreviation)s "
2519
 
            "on %(branch)s")
2520
 
 
2521
 
    def __init__(self, abbreviation, branch):
2522
 
        self.abbreviation = abbreviation
2523
 
        self.branch = branch
2524
 
 
2525
 
 
2526
 
class InvalidLineInBugsProperty(BzrError):
2527
 
 
2528
 
    _fmt = ("Invalid line in bugs property: '%(line)s'")
2529
 
 
2530
 
    def __init__(self, line):
2531
 
        self.line = line
2532
 
 
2533
 
 
2534
 
class InvalidBugStatus(BzrError):
2535
 
 
2536
 
    _fmt = ("Invalid bug status: '%(status)s'")
2537
 
 
2538
 
    def __init__(self, status):
2539
 
        self.status = status
2540
 
 
2541
 
 
2542
 
class UnexpectedSmartServerResponse(BzrError):
2543
 
 
2544
 
    _fmt = "Could not understand response from smart server: %(response_tuple)r"
2545
 
 
2546
 
    def __init__(self, response_tuple):
2547
 
        self.response_tuple = response_tuple
2548
 
 
2549
 
 
2550
 
class ErrorFromSmartServer(BzrError):
2551
 
    """An error was received from a smart server.
2552
 
 
2553
 
    :seealso: UnknownErrorFromSmartServer
2554
 
    """
2555
 
 
2556
 
    _fmt = "Error received from smart server: %(error_tuple)r"
2557
 
 
2558
 
    internal_error = True
2559
 
 
2560
 
    def __init__(self, error_tuple):
2561
 
        self.error_tuple = error_tuple
2562
 
        try:
2563
 
            self.error_verb = error_tuple[0]
2564
 
        except IndexError:
2565
 
            self.error_verb = None
2566
 
        self.error_args = error_tuple[1:]
2567
 
 
2568
 
 
2569
 
class UnknownErrorFromSmartServer(BzrError):
2570
 
    """An ErrorFromSmartServer could not be translated into a typical bzrlib
2571
 
    error.
2572
 
 
2573
 
    This is distinct from ErrorFromSmartServer so that it is possible to
2574
 
    distinguish between the following two cases:
2575
 
      - ErrorFromSmartServer was uncaught.  This is logic error in the client
2576
 
        and so should provoke a traceback to the user.
2577
 
      - ErrorFromSmartServer was caught but its error_tuple could not be
2578
 
        translated.  This is probably because the server sent us garbage, and
2579
 
        should not provoke a traceback.
2580
 
    """
2581
 
 
2582
 
    _fmt = "Server sent an unexpected error: %(error_tuple)r"
2583
 
 
2584
 
    internal_error = False
2585
 
 
2586
 
    def __init__(self, error_from_smart_server):
2587
 
        """Constructor.
2588
 
 
2589
 
        :param error_from_smart_server: An ErrorFromSmartServer instance.
2590
 
        """
2591
 
        self.error_from_smart_server = error_from_smart_server
2592
 
        self.error_tuple = error_from_smart_server.error_tuple
2593
 
 
2594
 
 
2595
 
class ContainerError(BzrError):
2596
 
    """Base class of container errors."""
2597
 
 
2598
 
 
2599
 
class UnknownContainerFormatError(ContainerError):
2600
 
 
2601
 
    _fmt = "Unrecognised container format: %(container_format)r"
2602
 
 
2603
 
    def __init__(self, container_format):
2604
 
        self.container_format = container_format
2605
 
 
2606
 
 
2607
 
class UnexpectedEndOfContainerError(ContainerError):
2608
 
 
2609
 
    _fmt = "Unexpected end of container stream"
2610
 
 
2611
 
 
2612
 
class UnknownRecordTypeError(ContainerError):
2613
 
 
2614
 
    _fmt = "Unknown record type: %(record_type)r"
2615
 
 
2616
 
    def __init__(self, record_type):
2617
 
        self.record_type = record_type
2618
 
 
2619
 
 
2620
 
class InvalidRecordError(ContainerError):
2621
 
 
2622
 
    _fmt = "Invalid record: %(reason)s"
2623
 
 
2624
 
    def __init__(self, reason):
2625
 
        self.reason = reason
2626
 
 
2627
 
 
2628
 
class ContainerHasExcessDataError(ContainerError):
2629
 
 
2630
 
    _fmt = "Container has data after end marker: %(excess)r"
2631
 
 
2632
 
    def __init__(self, excess):
2633
 
        self.excess = excess
2634
 
 
2635
 
 
2636
 
class DuplicateRecordNameError(ContainerError):
2637
 
 
2638
 
    _fmt = "Container has multiple records with the same name: %(name)s"
2639
 
 
2640
 
    def __init__(self, name):
2641
 
        self.name = name
2642
 
 
2643
 
 
2644
 
class NoDestinationAddress(InternalBzrError):
2645
 
 
2646
 
    _fmt = "Message does not have a destination address."
2647
 
 
2648
 
 
2649
 
class RepositoryDataStreamError(BzrError):
2650
 
 
2651
 
    _fmt = "Corrupt or incompatible data stream: %(reason)s"
2652
 
 
2653
 
    def __init__(self, reason):
2654
 
        self.reason = reason
2655
 
 
2656
 
 
2657
 
class SMTPError(BzrError):
2658
 
 
2659
 
    _fmt = "SMTP error: %(error)s"
2660
 
 
2661
 
    def __init__(self, error):
2662
 
        self.error = error
2663
 
 
2664
 
 
2665
 
class NoMessageSupplied(BzrError):
2666
 
 
2667
 
    _fmt = "No message supplied."
2668
 
 
2669
 
 
2670
 
class NoMailAddressSpecified(BzrError):
2671
 
 
2672
 
    _fmt = "No mail-to address (--mail-to) or output (-o) specified."
2673
 
 
2674
 
 
2675
 
class UnknownMailClient(BzrError):
2676
 
 
2677
 
    _fmt = "Unknown mail client: %(mail_client)s"
2678
 
 
2679
 
    def __init__(self, mail_client):
2680
 
        BzrError.__init__(self, mail_client=mail_client)
2681
 
 
2682
 
 
2683
 
class MailClientNotFound(BzrError):
2684
 
 
2685
 
    _fmt = "Unable to find mail client with the following names:"\
2686
 
        " %(mail_command_list_string)s"
2687
 
 
2688
 
    def __init__(self, mail_command_list):
2689
 
        mail_command_list_string = ', '.join(mail_command_list)
2690
 
        BzrError.__init__(self, mail_command_list=mail_command_list,
2691
 
                          mail_command_list_string=mail_command_list_string)
2692
 
 
2693
 
class SMTPConnectionRefused(SMTPError):
2694
 
 
2695
 
    _fmt = "SMTP connection to %(host)s refused"
2696
 
 
2697
 
    def __init__(self, error, host):
2698
 
        self.error = error
2699
 
        self.host = host
2700
 
 
2701
 
 
2702
 
class DefaultSMTPConnectionRefused(SMTPConnectionRefused):
2703
 
 
2704
 
    _fmt = "Please specify smtp_server.  No server at default %(host)s."
2705
 
 
2706
 
 
2707
 
class BzrDirError(BzrError):
2708
 
 
2709
 
    def __init__(self, bzrdir):
2710
 
        import bzrlib.urlutils as urlutils
2711
 
        display_url = urlutils.unescape_for_display(bzrdir.root_transport.base,
2712
 
                                                    'ascii')
2713
 
        BzrError.__init__(self, bzrdir=bzrdir, display_url=display_url)
2714
 
 
2715
 
 
2716
 
class UnsyncedBranches(BzrDirError):
2717
 
 
2718
 
    _fmt = ("'%(display_url)s' is not in sync with %(target_url)s.  See"
2719
 
            " bzr help sync-for-reconfigure.")
2720
 
 
2721
 
    def __init__(self, bzrdir, target_branch):
2722
 
        BzrDirError.__init__(self, bzrdir)
2723
 
        import bzrlib.urlutils as urlutils
2724
 
        self.target_url = urlutils.unescape_for_display(target_branch.base,
2725
 
                                                        'ascii')
2726
 
 
2727
 
 
2728
 
class AlreadyBranch(BzrDirError):
2729
 
 
2730
 
    _fmt = "'%(display_url)s' is already a branch."
2731
 
 
2732
 
 
2733
 
class AlreadyTree(BzrDirError):
2734
 
 
2735
 
    _fmt = "'%(display_url)s' is already a tree."
2736
 
 
2737
 
 
2738
 
class AlreadyCheckout(BzrDirError):
2739
 
 
2740
 
    _fmt = "'%(display_url)s' is already a checkout."
2741
 
 
2742
 
 
2743
 
class AlreadyLightweightCheckout(BzrDirError):
2744
 
 
2745
 
    _fmt = "'%(display_url)s' is already a lightweight checkout."
2746
 
 
2747
 
 
2748
 
class AlreadyUsingShared(BzrDirError):
2749
 
 
2750
 
    _fmt = "'%(display_url)s' is already using a shared repository."
2751
 
 
2752
 
 
2753
 
class AlreadyStandalone(BzrDirError):
2754
 
 
2755
 
    _fmt = "'%(display_url)s' is already standalone."
2756
 
 
2757
 
 
2758
 
class AlreadyWithTrees(BzrDirError):
2759
 
 
2760
 
    _fmt = ("Shared repository '%(display_url)s' already creates "
2761
 
            "working trees.")
2762
 
 
2763
 
 
2764
 
class AlreadyWithNoTrees(BzrDirError):
2765
 
 
2766
 
    _fmt = ("Shared repository '%(display_url)s' already doesn't create "
2767
 
            "working trees.")
2768
 
 
2769
 
 
2770
 
class ReconfigurationNotSupported(BzrDirError):
2771
 
 
2772
 
    _fmt = "Requested reconfiguration of '%(display_url)s' is not supported."
2773
 
 
2774
 
 
2775
 
class NoBindLocation(BzrDirError):
2776
 
 
2777
 
    _fmt = "No location could be found to bind to at %(display_url)s."
2778
 
 
2779
 
 
2780
 
class UncommittedChanges(BzrError):
2781
 
 
2782
 
    _fmt = 'Working tree "%(display_url)s" has uncommitted changes.'
2783
 
 
2784
 
    def __init__(self, tree):
2785
 
        import bzrlib.urlutils as urlutils
2786
 
        display_url = urlutils.unescape_for_display(
2787
 
            tree.bzrdir.root_transport.base, 'ascii')
2788
 
        BzrError.__init__(self, tree=tree, display_url=display_url)
2789
 
 
2790
 
 
2791
 
class MissingTemplateVariable(BzrError):
2792
 
 
2793
 
    _fmt = 'Variable {%(name)s} is not available.'
2794
 
 
2795
 
    def __init__(self, name):
2796
 
        self.name = name
2797
 
 
2798
 
 
2799
 
class NoTemplate(BzrError):
2800
 
 
2801
 
    _fmt = 'No template specified.'
2802
 
 
2803
 
 
2804
 
class UnableCreateSymlink(BzrError):
2805
 
 
2806
 
    _fmt = 'Unable to create symlink %(path_str)son this platform'
2807
 
 
2808
 
    def __init__(self, path=None):
2809
 
        path_str = ''
2810
 
        if path:
2811
 
            try:
2812
 
                path_str = repr(str(path))
2813
 
            except UnicodeEncodeError:
2814
 
                path_str = repr(path)
2815
 
            path_str += ' '
2816
 
        self.path_str = path_str
2817
 
 
2818
 
 
2819
 
class UnsupportedTimezoneFormat(BzrError):
2820
 
 
2821
 
    _fmt = ('Unsupported timezone format "%(timezone)s", '
2822
 
            'options are "utc", "original", "local".')
2823
 
 
2824
 
    def __init__(self, timezone):
2825
 
        self.timezone = timezone
2826
 
 
2827
 
 
2828
 
class CommandAvailableInPlugin(StandardError):
2829
 
 
2830
 
    internal_error = False
2831
 
 
2832
 
    def __init__(self, cmd_name, plugin_metadata, provider):
2833
 
 
2834
 
        self.plugin_metadata = plugin_metadata
2835
 
        self.cmd_name = cmd_name
2836
 
        self.provider = provider
2837
 
 
2838
 
    def __str__(self):
2839
 
 
2840
 
        _fmt = ('"%s" is not a standard bzr command. \n'
2841
 
                'However, the following official plugin provides this command: %s\n'
2842
 
                'You can install it by going to: %s'
2843
 
                % (self.cmd_name, self.plugin_metadata['name'],
2844
 
                    self.plugin_metadata['url']))
2845
 
 
2846
 
        return _fmt
2847
 
 
2848
 
 
2849
 
class NoPluginAvailable(BzrError):
2850
 
    pass
2851
 
 
2852
 
 
2853
 
class UnableEncodePath(BzrError):
2854
 
 
2855
 
    _fmt = ('Unable to encode %(kind)s path %(path)r in '
2856
 
            'user encoding %(user_encoding)s')
2857
 
 
2858
 
    def __init__(self, path, kind):
2859
 
        from bzrlib.osutils import get_user_encoding
2860
 
        self.path = path
2861
 
        self.kind = kind
2862
 
        self.user_encoding = osutils.get_user_encoding()
2863
 
 
2864
 
 
2865
 
class NoSuchAlias(BzrError):
2866
 
 
2867
 
    _fmt = ('The alias "%(alias_name)s" does not exist.')
2868
 
 
2869
 
    def __init__(self, alias_name):
2870
 
        BzrError.__init__(self, alias_name=alias_name)
2871
 
 
2872
 
 
2873
 
class DirectoryLookupFailure(BzrError):
2874
 
    """Base type for lookup errors."""
2875
 
 
2876
 
    pass
2877
 
 
2878
 
 
2879
 
class InvalidLocationAlias(DirectoryLookupFailure):
2880
 
 
2881
 
    _fmt = '"%(alias_name)s" is not a valid location alias.'
2882
 
 
2883
 
    def __init__(self, alias_name):
2884
 
        DirectoryLookupFailure.__init__(self, alias_name=alias_name)
2885
 
 
2886
 
 
2887
 
class UnsetLocationAlias(DirectoryLookupFailure):
2888
 
 
2889
 
    _fmt = 'No %(alias_name)s location assigned.'
2890
 
 
2891
 
    def __init__(self, alias_name):
2892
 
        DirectoryLookupFailure.__init__(self, alias_name=alias_name[1:])
2893
 
 
2894
 
 
2895
 
class CannotBindAddress(BzrError):
2896
 
 
2897
 
    _fmt = 'Cannot bind address "%(host)s:%(port)i": %(orig_error)s.'
2898
 
 
2899
 
    def __init__(self, host, port, orig_error):
2900
 
        BzrError.__init__(self, host=host, port=port,
2901
 
            orig_error=orig_error[1])
2902
 
 
2903
 
 
2904
 
class UnknownRules(BzrError):
2905
 
 
2906
 
    _fmt = ('Unknown rules detected: %(unknowns_str)s.')
2907
 
 
2908
 
    def __init__(self, unknowns):
2909
 
        BzrError.__init__(self, unknowns_str=", ".join(unknowns))
2910
 
 
2911
 
 
2912
 
class HookFailed(BzrError):
2913
 
    """Raised when a pre_change_branch_tip hook function fails anything other
2914
 
    than TipChangeRejected.
2915
 
    """
2916
 
 
2917
 
    _fmt = ("Hook '%(hook_name)s' during %(hook_stage)s failed:\n"
2918
 
            "%(traceback_text)s%(exc_value)s")
2919
 
 
2920
 
    def __init__(self, hook_stage, hook_name, exc_info):
2921
 
        import traceback
2922
 
        self.hook_stage = hook_stage
2923
 
        self.hook_name = hook_name
2924
 
        self.exc_info = exc_info
2925
 
        self.exc_type = exc_info[0]
2926
 
        self.exc_value = exc_info[1]
2927
 
        self.exc_tb = exc_info[2]
2928
 
        self.traceback_text = ''.join(traceback.format_tb(self.exc_tb))
2929
 
 
2930
 
 
2931
 
class TipChangeRejected(BzrError):
2932
 
    """A pre_change_branch_tip hook function may raise this to cleanly and
2933
 
    explicitly abort a change to a branch tip.
2934
 
    """
2935
 
 
2936
 
    _fmt = u"Tip change rejected: %(msg)s"
2937
 
 
2938
 
    def __init__(self, msg):
2939
 
        self.msg = msg
2940
 
 
2941
 
 
2942
 
class ShelfCorrupt(BzrError):
2943
 
 
2944
 
    _fmt = "Shelf corrupt."
2945
 
 
2946
 
 
2947
 
class NoSuchShelfId(BzrError):
2948
 
 
2949
 
    _fmt = 'No changes are shelved with id "%(shelf_id)d".'
2950
 
 
2951
 
    def __init__(self, shelf_id):
2952
 
        BzrError.__init__(self, shelf_id=shelf_id)
2953
 
 
2954
 
 
2955
 
class InvalidShelfId(BzrError):
2956
 
 
2957
 
    _fmt = '"%(invalid_id)s" is not a valid shelf id, try a number instead.'
2958
 
 
2959
 
    def __init__(self, invalid_id):
2960
 
        BzrError.__init__(self, invalid_id=invalid_id)
2961
 
 
2962
 
 
2963
 
class UserAbort(BzrError):
2964
 
 
2965
 
    _fmt = 'The user aborted the operation.'
2966
 
 
2967
 
 
2968
 
class MustHaveWorkingTree(BzrError):
2969
 
 
2970
 
    _fmt = ("Branching '%(url)s'(%(format)s) must create a working tree.")
2971
 
 
2972
 
    def __init__(self, format, url):
2973
 
        BzrError.__init__(self, format=format, url=url)
2974
 
 
2975
 
 
2976
 
class NoSuchView(BzrError):
2977
 
    """A view does not exist.
2978
 
    """
2979
 
 
2980
 
    _fmt = u"No such view: %(view_name)s."
2981
 
 
2982
 
    def __init__(self, view_name):
2983
 
        self.view_name = view_name
2984
 
 
2985
 
 
2986
 
class ViewsNotSupported(BzrError):
2987
 
    """Views are not supported by a tree format.
2988
 
    """
2989
 
 
2990
 
    _fmt = ("Views are not supported by %(tree)s;"
2991
 
            " use 'bzr upgrade' to change your tree to a later format.")
2992
 
 
2993
 
    def __init__(self, tree):
2994
 
        self.tree = tree
2995
 
 
2996
 
 
2997
 
class FileOutsideView(BzrError):
2998
 
 
2999
 
    _fmt = ('Specified file "%(file_name)s" is outside the current view: '
3000
 
            '%(view_str)s')
3001
 
 
3002
 
    def __init__(self, file_name, view_files):
3003
 
        self.file_name = file_name
3004
 
        self.view_str = ", ".join(view_files)
3005
 
 
3006
 
 
3007
 
class UnresumableWriteGroup(BzrError):
3008
 
 
3009
 
    _fmt = ("Repository %(repository)s cannot resume write group "
3010
 
            "%(write_groups)r: %(reason)s")
3011
 
 
3012
 
    internal_error = True
3013
 
 
3014
 
    def __init__(self, repository, write_groups, reason):
3015
 
        self.repository = repository
3016
 
        self.write_groups = write_groups
3017
 
        self.reason = reason
3018
 
 
3019
 
 
3020
 
class UnsuspendableWriteGroup(BzrError):
3021
 
 
3022
 
    _fmt = ("Repository %(repository)s cannot suspend a write group.")
3023
 
 
3024
 
    internal_error = True
3025
 
 
3026
 
    def __init__(self, repository):
3027
 
        self.repository = repository
 
1579
class ImportNameCollision(BzrError):
 
1580
 
 
1581
    _fmt = "Tried to import an object to the same name as an existing object. %(name)s"
 
1582
 
 
1583
    internal_error = True
 
1584
 
 
1585
    def __init__(self, name):
 
1586
        BzrError.__init__(self)
 
1587
        self.name = name