~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/errors.py

  • Committer: Danny van Heumen
  • Date: 2010-03-09 21:42:11 UTC
  • mto: (4634.139.5 2.0)
  • mto: This revision was merged to the branch mainline in revision 5160.
  • Revision ID: danny@dannyvanheumen.nl-20100309214211-iqh42x6qcikgd9p3
Reverted now-useless TODO list.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005, 2006, 2007 Canonical Ltd
 
1
# Copyright (C) 2005, 2006, 2007, 2008 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
12
12
#
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
 
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
17
"""Exceptions for bzr, and reporting of them.
18
18
"""
19
19
 
20
 
 
21
20
from bzrlib import (
22
21
    osutils,
23
22
    symbol_versioning,
32
31
 
33
32
 
34
33
# TODO: is there any value in providing the .args field used by standard
35
 
# python exceptions?   A list of values with no names seems less useful 
 
34
# python exceptions?   A list of values with no names seems less useful
36
35
# to me.
37
36
 
38
 
# TODO: Perhaps convert the exception to a string at the moment it's 
 
37
# TODO: Perhaps convert the exception to a string at the moment it's
39
38
# constructed to make sure it will succeed.  But that says nothing about
40
39
# exceptions that are never raised.
41
40
 
44
43
# 'unprintable'.
45
44
 
46
45
 
 
46
# return codes from the bzr program
 
47
EXIT_OK = 0
 
48
EXIT_ERROR = 3
 
49
EXIT_INTERNAL_ERROR = 4
 
50
 
 
51
 
47
52
class BzrError(StandardError):
48
53
    """
49
54
    Base class for errors raised by bzrlib.
56
61
    :cvar _fmt: Format string to display the error; this is expanded
57
62
    by the instance's dict.
58
63
    """
59
 
    
 
64
 
60
65
    internal_error = False
61
66
 
62
67
    def __init__(self, msg=None, **kwds):
67
72
        arguments can be given.  The first is for generic "user" errors which
68
73
        are not intended to be caught and so do not need a specific subclass.
69
74
        The second case is for use with subclasses that provide a _fmt format
70
 
        string to print the arguments.  
 
75
        string to print the arguments.
71
76
 
72
 
        Keyword arguments are taken as parameters to the error, which can 
73
 
        be inserted into the format string template.  It's recommended 
74
 
        that subclasses override the __init__ method to require specific 
 
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
75
80
        parameters.
76
81
 
77
82
        :param msg: If given, this is the literal complete text for the error,
78
 
        not subject to expansion.
 
83
           not subject to expansion. 'msg' is used instead of 'message' because
 
84
           python evolved and, in 2.6, forbids the use of 'message'.
79
85
        """
80
86
        StandardError.__init__(self)
81
87
        if msg is not None:
87
93
            for key, value in kwds.items():
88
94
                setattr(self, key, value)
89
95
 
90
 
    def __str__(self):
 
96
    def _format(self):
91
97
        s = getattr(self, '_preformatted_string', None)
92
98
        if s is not None:
93
 
            # contains a preformatted message; must be cast to plain str
94
 
            return str(s)
 
99
            # contains a preformatted message
 
100
            return s
95
101
        try:
96
102
            fmt = self._get_format_string()
97
103
            if fmt:
98
 
                s = fmt % self.__dict__
 
104
                d = dict(self.__dict__)
 
105
                s = fmt % d
99
106
                # __str__() should always return a 'str' object
100
107
                # never a 'unicode' object.
101
 
                if isinstance(s, unicode):
102
 
                    return s.encode('utf8')
103
108
                return s
104
109
        except (AttributeError, TypeError, NameError, ValueError, KeyError), e:
105
110
            return 'Unprintable exception %s: dict=%r, fmt=%r, error=%r' \
108
113
                   getattr(self, '_fmt', None),
109
114
                   e)
110
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))
 
138
 
111
139
    def _get_format_string(self):
112
140
        """Return format string for this exception or None"""
113
141
        fmt = getattr(self, '_fmt', None)
125
153
               getattr(self, '_fmt', None),
126
154
               )
127
155
 
 
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
 
128
172
 
129
173
class BzrNewError(BzrError):
130
174
    """Deprecated error base class."""
160
204
 
161
205
 
162
206
class AlreadyBuilding(BzrError):
163
 
    
 
207
 
164
208
    _fmt = "The tree builder is already building a tree."
165
209
 
166
210
 
167
 
class BzrCheckError(BzrError):
168
 
    
169
 
    _fmt = "Internal check failed: %(message)s"
170
 
 
171
 
    internal_error = True
172
 
 
173
 
    def __init__(self, message):
174
 
        BzrError.__init__(self)
175
 
        self.message = message
176
 
 
177
 
 
178
 
class DisabledMethod(BzrError):
 
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):
179
238
 
180
239
    _fmt = "The smart server method '%(class_name)s' is disabled."
181
240
 
182
 
    internal_error = True
183
 
 
184
241
    def __init__(self, class_name):
185
242
        BzrError.__init__(self)
186
243
        self.class_name = class_name
207
264
        self.transport = transport
208
265
 
209
266
 
210
 
class InvalidEntryName(BzrError):
211
 
    
 
267
class InvalidEntryName(InternalBzrError):
 
268
 
212
269
    _fmt = "Invalid entry name: %(name)s"
213
270
 
214
 
    internal_error = True
215
 
 
216
271
    def __init__(self, name):
217
272
        BzrError.__init__(self)
218
273
        self.name = name
219
274
 
220
275
 
221
276
class InvalidRevisionNumber(BzrError):
222
 
    
 
277
 
223
278
    _fmt = "Invalid revision number %(revno)s"
224
279
 
225
280
    def __init__(self, revno):
237
292
        self.revision_id = revision_id
238
293
        self.branch = branch
239
294
 
 
295
 
240
296
class ReservedId(BzrError):
241
297
 
242
298
    _fmt = "Reserved revision-id {%(revision_id)s}"
245
301
        self.revision_id = revision_id
246
302
 
247
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
 
248
320
class NoHelpTopic(BzrError):
249
321
 
250
322
    _fmt = ("No help could be found for '%(topic)s'. "
256
328
 
257
329
class NoSuchId(BzrError):
258
330
 
259
 
    _fmt = "The file id %(file_id)s is not present in the tree %(tree)s."
260
 
    
 
331
    _fmt = 'The file id "%(file_id)s" is not present in the tree %(tree)s.'
 
332
 
261
333
    def __init__(self, tree, file_id):
262
334
        BzrError.__init__(self)
263
335
        self.file_id = file_id
264
336
        self.tree = tree
265
337
 
266
338
 
267
 
class InventoryModified(BzrError):
 
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):
268
354
 
269
355
    _fmt = ("The current inventory for the tree %(tree)r has been modified,"
270
356
            " so a clean inventory cannot be read without data loss.")
271
357
 
272
 
    internal_error = True
273
 
 
274
358
    def __init__(self, tree):
275
359
        self.tree = tree
276
360
 
277
361
 
278
362
class NoWorkingTree(BzrError):
279
363
 
280
 
    _fmt = "No WorkingTree exists for %(base)s."
281
 
    
 
364
    _fmt = 'No WorkingTree exists for "%(base)s".'
 
365
 
282
366
    def __init__(self, base):
283
367
        BzrError.__init__(self)
284
368
        self.base = base
297
381
        self.url = url
298
382
 
299
383
 
300
 
class WorkingTreeAlreadyPopulated(BzrError):
301
 
 
302
 
    _fmt = """Working tree already populated in %(base)s"""
303
 
 
304
 
    internal_error = True
 
384
class WorkingTreeAlreadyPopulated(InternalBzrError):
 
385
 
 
386
    _fmt = 'Working tree already populated in "%(base)s"'
305
387
 
306
388
    def __init__(self, base):
307
389
        self.base = base
308
390
 
 
391
 
309
392
class BzrCommandError(BzrError):
310
393
    """Error from user command"""
311
394
 
312
 
    internal_error = False
313
 
 
314
395
    # Error from malformed user command; please avoid raising this as a
315
396
    # generic exception not caused by user input.
316
397
    #
318
399
    # are not intended to be caught anyway.  UI code need not subclass
319
400
    # BzrCommandError, and non-UI code should not throw a subclass of
320
401
    # BzrCommandError.  ADHB 20051211
321
 
    def __init__(self, msg):
322
 
        # Object.__str__() must return a real string
323
 
        # returning a Unicode string is a python error.
324
 
        if isinstance(msg, unicode):
325
 
            self.msg = msg.encode('utf8')
326
 
        else:
327
 
            self.msg = msg
328
 
 
329
 
    def __str__(self):
330
 
        return self.msg
331
402
 
332
403
 
333
404
class NotWriteLocked(BzrError):
343
414
    _fmt = "Error in command line options"
344
415
 
345
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
 
346
473
class BadOptionValue(BzrError):
347
474
 
348
475
    _fmt = """Bad value "%(value)s" for option "%(name)s"."""
350
477
    def __init__(self, name, value):
351
478
        BzrError.__init__(self, name=name, value=value)
352
479
 
353
 
    
 
480
 
354
481
class StrictCommitFailed(BzrError):
355
482
 
356
483
    _fmt = "Commit refused because there are unknown files in the tree"
359
486
# XXX: Should be unified with TransportError; they seem to represent the
360
487
# same thing
361
488
# RBC 20060929: I think that unifiying with TransportError would be a mistake
362
 
# - this is finer than a TransportError - and more useful as such. It 
 
489
# - this is finer than a TransportError - and more useful as such. It
363
490
# differentiates between 'transport has failed' and 'operation on a transport
364
491
# has failed.'
365
492
class PathError(BzrError):
366
 
    
 
493
 
367
494
    _fmt = "Generic path error: %(path)r%(extra)s)"
368
495
 
369
496
    def __init__(self, path, extra=None):
389
516
    """Used when renaming and both source and dest exist."""
390
517
 
391
518
    _fmt = ("Could not rename %(source)s => %(dest)s because both files exist."
392
 
            "%(extra)s")
 
519
            " (Use --after to tell bzr about a rename that has already"
 
520
            " happened)%(extra)s")
393
521
 
394
522
    def __init__(self, source, dest, extra=None):
395
523
        BzrError.__init__(self)
403
531
 
404
532
class NotADirectory(PathError):
405
533
 
406
 
    _fmt = "%(path)r is not a directory %(extra)s"
 
534
    _fmt = '"%(path)s" is not a directory %(extra)s'
407
535
 
408
536
 
409
537
class NotInWorkingDirectory(PathError):
410
538
 
411
 
    _fmt = "%(path)r is not in the working directory %(extra)s"
 
539
    _fmt = '"%(path)s" is not in the working directory %(extra)s'
412
540
 
413
541
 
414
542
class DirectoryNotEmpty(PathError):
415
543
 
416
 
    _fmt = "Directory not empty: %(path)r%(extra)s"
417
 
 
418
 
 
419
 
class ReadingCompleted(BzrError):
420
 
    
 
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
 
421
554
    _fmt = ("The MediumRequest '%(request)s' has already had finish_reading "
422
555
            "called upon it - the request has been completed and no more "
423
556
            "data may be read.")
424
557
 
425
 
    internal_error = True
426
 
 
427
558
    def __init__(self, request):
428
559
        self.request = request
429
560
 
430
561
 
431
562
class ResourceBusy(PathError):
432
563
 
433
 
    _fmt = "Device or resource busy: %(path)r%(extra)s"
 
564
    _fmt = 'Device or resource busy: "%(path)s"%(extra)s'
434
565
 
435
566
 
436
567
class PermissionDenied(PathError):
437
568
 
438
 
    _fmt = "Permission denied: %(path)r%(extra)s"
 
569
    _fmt = 'Permission denied: "%(path)s"%(extra)s'
439
570
 
440
571
 
441
572
class InvalidURL(PathError):
442
573
 
443
 
    _fmt = "Invalid url supplied to transport: %(path)r%(extra)s"
 
574
    _fmt = 'Invalid url supplied to transport: "%(path)s"%(extra)s'
444
575
 
445
576
 
446
577
class InvalidURLJoin(PathError):
447
578
 
448
 
    _fmt = "Invalid URL join request: %(args)s%(extra)s"
449
 
 
450
 
    def __init__(self, msg, base, args):
451
 
        PathError.__init__(self, base, msg)
452
 
        self.args = [base] + list(args)
 
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
453
608
 
454
609
 
455
610
class UnknownHook(BzrError):
470
625
        PathError.__init__(self, url, extra=extra)
471
626
 
472
627
 
 
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 UnstackableLocationError(BzrError):
 
640
 
 
641
    _fmt = "The branch '%(branch_url)s' cannot be stacked on '%(target_url)s'."
 
642
 
 
643
    def __init__(self, branch_url, target_url):
 
644
        BzrError.__init__(self)
 
645
        self.branch_url = branch_url
 
646
        self.target_url = target_url
 
647
 
 
648
 
 
649
class UnstackableRepositoryFormat(BzrError):
 
650
 
 
651
    _fmt = ("The repository '%(url)s'(%(format)s) is not a stackable format. "
 
652
        "You will need to upgrade the repository to permit branch stacking.")
 
653
 
 
654
    def __init__(self, format, url):
 
655
        BzrError.__init__(self)
 
656
        self.format = format
 
657
        self.url = url
 
658
 
 
659
 
473
660
class ReadError(PathError):
474
 
    
 
661
 
475
662
    _fmt = """Error reading from %(path)r."""
476
663
 
477
664
 
478
665
class ShortReadvError(PathError):
479
666
 
480
 
    _fmt = ("readv() read %(actual)s bytes rather than %(length)s bytes"
481
 
            " at %(offset)s for %(path)s%(extra)s")
 
667
    _fmt = ('readv() read %(actual)s bytes rather than %(length)s bytes'
 
668
            ' at %(offset)s for "%(path)s"%(extra)s')
482
669
 
483
670
    internal_error = True
484
671
 
489
676
        self.actual = actual
490
677
 
491
678
 
492
 
class PathNotChild(BzrError):
 
679
class PathNotChild(PathError):
493
680
 
494
 
    _fmt = "Path %(path)r is not a child of path %(base)r%(extra)s"
 
681
    _fmt = 'Path "%(path)s" is not a child of path "%(base)s"%(extra)s'
495
682
 
496
683
    internal_error = True
497
684
 
507
694
 
508
695
class InvalidNormalization(PathError):
509
696
 
510
 
    _fmt = "Path %(path)r is not unicode normalized"
 
697
    _fmt = 'Path "%(path)s" is not unicode normalized'
511
698
 
512
699
 
513
700
# TODO: This is given a URL; we try to unescape it but doing that from inside
514
701
# the exception object is a bit undesirable.
515
 
# TODO: Probably this behavior of should be a common superclass 
 
702
# TODO: Probably this behavior of should be a common superclass
516
703
class NotBranchError(PathError):
517
704
 
518
 
    _fmt = "Not a branch: %(path)s"
 
705
    _fmt = 'Not a branch: "%(path)s".'
519
706
 
520
707
    def __init__(self, path):
521
708
       import bzrlib.urlutils as urlutils
533
720
 
534
721
class AlreadyBranchError(PathError):
535
722
 
536
 
    _fmt = "Already a branch: %(path)s."
 
723
    _fmt = 'Already a branch: "%(path)s".'
537
724
 
538
725
 
539
726
class BranchExistsWithoutWorkingTree(PathError):
540
727
 
541
 
    _fmt = "Directory contains a branch, but no working tree \
542
 
(use bzr checkout if you wish to build a working tree): %(path)s"
 
728
    _fmt = 'Directory contains a branch, but no working tree \
 
729
(use bzr checkout if you wish to build a working tree): "%(path)s"'
543
730
 
544
731
 
545
732
class AtomicFileAlreadyClosed(PathError):
546
733
 
547
 
    _fmt = ("'%(function)s' called on an AtomicFile after it was closed:"
548
 
            " %(path)s")
 
734
    _fmt = ('"%(function)s" called on an AtomicFile after it was closed:'
 
735
            ' "%(path)s"')
549
736
 
550
737
    def __init__(self, path, function):
551
738
        PathError.__init__(self, path=path, extra=None)
554
741
 
555
742
class InaccessibleParent(PathError):
556
743
 
557
 
    _fmt = ("Parent not accessible given base %(base)s and"
558
 
            " relative path %(path)s")
 
744
    _fmt = ('Parent not accessible given base "%(base)s" and'
 
745
            ' relative path "%(path)s"')
559
746
 
560
747
    def __init__(self, path, base):
561
748
        PathError.__init__(self, path)
564
751
 
565
752
class NoRepositoryPresent(BzrError):
566
753
 
567
 
    _fmt = "No repository present: %(path)r"
 
754
    _fmt = 'No repository present: "%(path)s"'
568
755
    def __init__(self, bzrdir):
569
756
        BzrError.__init__(self)
570
757
        self.path = bzrdir.transport.clone('..').base
572
759
 
573
760
class FileInWrongBranch(BzrError):
574
761
 
575
 
    _fmt = "File %(path)s in not in branch %(branch_base)s."
 
762
    _fmt = 'File "%(path)s" is not in branch %(branch_base)s.'
576
763
 
577
764
    def __init__(self, branch, path):
578
765
        BzrError.__init__(self)
587
774
 
588
775
 
589
776
class UnknownFormatError(BzrError):
590
 
    
591
 
    _fmt = "Unknown branch format: %(format)r"
 
777
 
 
778
    _fmt = "Unknown %(kind)s format: %(format)r"
 
779
 
 
780
    def __init__(self, format, kind='branch'):
 
781
        self.kind = kind
 
782
        self.format = format
592
783
 
593
784
 
594
785
class IncompatibleFormat(BzrError):
595
 
    
 
786
 
596
787
    _fmt = "Format %(format)s is not compatible with .bzr version %(bzrdir)s."
597
788
 
598
789
    def __init__(self, format, bzrdir_format):
602
793
 
603
794
 
604
795
class IncompatibleRepositories(BzrError):
605
 
 
606
 
    _fmt = "Repository %(target)s is not compatible with repository"\
607
 
        " %(source)s"
608
 
 
609
 
    def __init__(self, source, target):
610
 
        BzrError.__init__(self, target=target, source=source)
 
796
    """Report an error that two repositories are not compatible.
 
797
 
 
798
    Note that the source and target repositories are permitted to be strings:
 
799
    this exception is thrown from the smart server and may refer to a
 
800
    repository the client hasn't opened.
 
801
    """
 
802
 
 
803
    _fmt = "%(target)s\n" \
 
804
            "is not compatible with\n" \
 
805
            "%(source)s\n" \
 
806
            "%(details)s"
 
807
 
 
808
    def __init__(self, source, target, details=None):
 
809
        if details is None:
 
810
            details = "(no details)"
 
811
        BzrError.__init__(self, target=target, source=source, details=details)
611
812
 
612
813
 
613
814
class IncompatibleRevision(BzrError):
614
 
    
 
815
 
615
816
    _fmt = "Revision is not compatible with %(repo_format)s"
616
817
 
617
818
    def __init__(self, repo_format):
622
823
class AlreadyVersionedError(BzrError):
623
824
    """Used when a path is expected not to be versioned, but it is."""
624
825
 
625
 
    _fmt = "%(context_info)s%(path)s is already versioned"
 
826
    _fmt = "%(context_info)s%(path)s is already versioned."
626
827
 
627
828
    def __init__(self, path, context_info=None):
628
829
        """Construct a new AlreadyVersionedError.
643
844
class NotVersionedError(BzrError):
644
845
    """Used when a path is expected to be versioned, but it is not."""
645
846
 
646
 
    _fmt = "%(context_info)s%(path)s is not versioned"
 
847
    _fmt = "%(context_info)s%(path)s is not versioned."
647
848
 
648
849
    def __init__(self, path, context_info=None):
649
850
        """Construct a new NotVersionedError.
700
901
        BzrError.__init__(self, filename=filename, kind=kind)
701
902
 
702
903
 
 
904
class BadFilenameEncoding(BzrError):
 
905
 
 
906
    _fmt = ('Filename %(filename)r is not valid in your current filesystem'
 
907
            ' encoding %(fs_encoding)s')
 
908
 
 
909
    def __init__(self, filename, fs_encoding):
 
910
        BzrError.__init__(self)
 
911
        self.filename = filename
 
912
        self.fs_encoding = fs_encoding
 
913
 
 
914
 
703
915
class ForbiddenControlFileError(BzrError):
704
916
 
705
 
    _fmt = "Cannot operate on %(filename)s because it is a control file"
706
 
 
707
 
 
708
 
class LockError(BzrError):
 
917
    _fmt = 'Cannot operate on "%(filename)s" because it is a control file'
 
918
 
 
919
 
 
920
class LockError(InternalBzrError):
709
921
 
710
922
    _fmt = "Lock error: %(msg)s"
711
923
 
712
 
    internal_error = True
713
 
 
714
924
    # All exceptions from the lock/unlock functions should be from
715
925
    # this exception class.  They will be translated as necessary. The
716
926
    # original exception is available as e.original_error
718
928
    # New code should prefer to raise specific subclasses
719
929
    def __init__(self, message):
720
930
        # Python 2.5 uses a slot for StandardError.message,
721
 
        # so use a different variable name
722
 
        # so it is exposed in self.__dict__
 
931
        # so use a different variable name.  We now work around this in
 
932
        # BzrError.__str__, but this member name is kept for compatability.
723
933
        self.msg = message
724
934
 
725
935
 
760
970
        self.obj = obj
761
971
 
762
972
 
763
 
class ReadOnlyLockError(LockError):
764
 
 
765
 
    _fmt = "Cannot acquire write lock on %(fname)s. %(msg)s"
766
 
 
767
 
    def __init__(self, fname, msg):
 
973
class LockFailed(LockError):
 
974
 
 
975
    internal_error = False
 
976
 
 
977
    _fmt = "Cannot lock %(lock)s: %(why)s"
 
978
 
 
979
    def __init__(self, lock, why):
768
980
        LockError.__init__(self, '')
769
 
        self.fname = fname
770
 
        self.msg = msg
 
981
        self.lock = lock
 
982
        self.why = why
771
983
 
772
984
 
773
985
class OutSideTransaction(BzrError):
797
1009
 
798
1010
class UnlockableTransport(LockError):
799
1011
 
 
1012
    internal_error = False
 
1013
 
800
1014
    _fmt = "Cannot lock: transport is read only: %(transport)s"
801
1015
 
802
1016
    def __init__(self, transport):
805
1019
 
806
1020
class LockContention(LockError):
807
1021
 
808
 
    _fmt = "Could not acquire lock %(lock)s"
 
1022
    _fmt = 'Could not acquire lock "%(lock)s": %(msg)s'
809
1023
    # TODO: show full url for lock, combining the transport and relative
810
1024
    # bits?
811
1025
 
812
1026
    internal_error = False
813
1027
 
814
 
    def __init__(self, lock):
 
1028
    def __init__(self, lock, msg=''):
815
1029
        self.lock = lock
 
1030
        self.msg = msg
816
1031
 
817
1032
 
818
1033
class LockBroken(LockError):
853
1068
 
854
1069
    _fmt = "The object %(obj)s does not support token specifying a token when locking."
855
1070
 
856
 
    internal_error = True
857
 
 
858
1071
    def __init__(self, obj):
859
1072
        self.obj = obj
860
1073
 
885
1098
        BzrError.__init__(self, files=files, files_str=files_str)
886
1099
 
887
1100
 
 
1101
class BadCommitMessageEncoding(BzrError):
 
1102
 
 
1103
    _fmt = 'The specified commit message contains characters unsupported by '\
 
1104
        'the current encoding.'
 
1105
 
 
1106
 
888
1107
class UpgradeReadonly(BzrError):
889
1108
 
890
1109
    _fmt = "Upgrade URL cannot work with readonly URLs."
904
1123
    _fmt = "Commit refused because there are unknowns in the tree."
905
1124
 
906
1125
 
907
 
class NoSuchRevision(BzrError):
908
 
 
909
 
    _fmt = "Branch %(branch)s has no revision %(revision)s"
910
 
 
911
 
    internal_error = True
 
1126
class NoSuchRevision(InternalBzrError):
 
1127
 
 
1128
    _fmt = "%(branch)s has no revision %(revision)s"
912
1129
 
913
1130
    def __init__(self, branch, revision):
 
1131
        # 'branch' may sometimes be an internal object like a KnitRevisionStore
914
1132
        BzrError.__init__(self, branch=branch, revision=revision)
915
1133
 
916
1134
 
917
 
class NotLeftParentDescendant(BzrError):
918
 
 
919
 
    _fmt = ("Revision %(old_revision)s is not the left parent of"
920
 
            " %(new_revision)s, but branch %(branch_location)s expects this")
921
 
 
922
 
    internal_error = True
923
 
 
924
 
    def __init__(self, branch, old_revision, new_revision):
925
 
        BzrError.__init__(self, branch_location=branch.base,
926
 
                          old_revision=old_revision,
927
 
                          new_revision=new_revision)
 
1135
class RangeInChangeOption(BzrError):
 
1136
 
 
1137
    _fmt = "Option --change does not accept revision ranges"
928
1138
 
929
1139
 
930
1140
class NoSuchRevisionSpec(BzrError):
937
1147
 
938
1148
class NoSuchRevisionInTree(NoSuchRevision):
939
1149
    """When using Tree.revision_tree, and the revision is not accessible."""
940
 
    
941
 
    _fmt = "The revision id %(revision_id)s is not present in the tree %(tree)s."
 
1150
 
 
1151
    _fmt = "The revision id {%(revision_id)s} is not present in the tree %(tree)s."
942
1152
 
943
1153
    def __init__(self, tree, revision_id):
944
1154
        BzrError.__init__(self)
979
1189
class DivergedBranches(BzrError):
980
1190
 
981
1191
    _fmt = ("These branches have diverged."
982
 
            " Use the merge command to reconcile them.")
983
 
 
984
 
    internal_error = False
 
1192
            " Use the missing command to see how.\n"
 
1193
            "Use the merge command to reconcile them.")
985
1194
 
986
1195
    def __init__(self, branch1, branch2):
987
1196
        self.branch1 = branch1
988
1197
        self.branch2 = branch2
989
1198
 
990
1199
 
991
 
class NotLefthandHistory(BzrError):
 
1200
class NotLefthandHistory(InternalBzrError):
992
1201
 
993
1202
    _fmt = "Supplied history does not follow left-hand parents"
994
1203
 
995
 
    internal_error = True
996
 
 
997
1204
    def __init__(self, history):
998
1205
        BzrError.__init__(self, history=history)
999
1206
 
1003
1210
    _fmt = ("Branches have no common ancestor, and"
1004
1211
            " no merge base revision was specified.")
1005
1212
 
1006
 
    internal_error = False
 
1213
 
 
1214
class CannotReverseCherrypick(BzrError):
 
1215
 
 
1216
    _fmt = ('Selected merge cannot perform reverse cherrypicks.  Try merge3'
 
1217
            ' or diff3.')
1007
1218
 
1008
1219
 
1009
1220
class NoCommonAncestor(BzrError):
1010
 
    
 
1221
 
1011
1222
    _fmt = "Revisions have no common ancestor: %(revision_a)s %(revision_b)s"
1012
1223
 
1013
1224
    def __init__(self, revision_a, revision_b):
1033
1244
            not_ancestor_id=not_ancestor_id)
1034
1245
 
1035
1246
 
1036
 
class InstallFailed(BzrError):
1037
 
 
1038
 
    def __init__(self, revisions):
1039
 
        revision_str = ", ".join(str(r) for r in revisions)
1040
 
        msg = "Could not install revisions:\n%s" % revision_str
1041
 
        BzrError.__init__(self, msg)
1042
 
        self.revisions = revisions
1043
 
 
1044
 
 
1045
1247
class AmbiguousBase(BzrError):
1046
1248
 
1047
1249
    def __init__(self, bases):
1053
1255
        self.bases = bases
1054
1256
 
1055
1257
 
1056
 
class NoCommits(BzrError):
 
1258
class NoCommits(BranchError):
1057
1259
 
1058
1260
    _fmt = "Branch %(branch)s has no commits."
1059
1261
 
1060
 
    def __init__(self, branch):
1061
 
        BzrError.__init__(self, branch=branch)
1062
 
 
1063
1262
 
1064
1263
class UnlistableStore(BzrError):
1065
1264
 
1076
1275
 
1077
1276
class BoundBranchOutOfDate(BzrError):
1078
1277
 
1079
 
    _fmt = ("Bound branch %(branch)s is out of date"
1080
 
            " with master branch %(master)s.")
 
1278
    _fmt = ("Bound branch %(branch)s is out of date with master branch"
 
1279
            " %(master)s.")
1081
1280
 
1082
1281
    def __init__(self, branch, master):
1083
1282
        BzrError.__init__(self)
1084
1283
        self.branch = branch
1085
1284
        self.master = master
1086
1285
 
1087
 
        
 
1286
 
1088
1287
class CommitToDoubleBoundBranch(BzrError):
1089
1288
 
1090
1289
    _fmt = ("Cannot commit to branch %(branch)s."
1120
1319
 
1121
1320
class WeaveError(BzrError):
1122
1321
 
1123
 
    _fmt = "Error in processing weave: %(message)s"
 
1322
    _fmt = "Error in processing weave: %(msg)s"
1124
1323
 
1125
 
    def __init__(self, message=None):
 
1324
    def __init__(self, msg=None):
1126
1325
        BzrError.__init__(self)
1127
 
        self.message = message
 
1326
        self.msg = msg
1128
1327
 
1129
1328
 
1130
1329
class WeaveRevisionAlreadyPresent(WeaveError):
1159
1358
 
1160
1359
class WeaveParentMismatch(WeaveError):
1161
1360
 
1162
 
    _fmt = "Parents are mismatched between two revisions."
1163
 
    
 
1361
    _fmt = "Parents are mismatched between two revisions. %(message)s"
 
1362
 
1164
1363
 
1165
1364
class WeaveInvalidChecksum(WeaveError):
1166
1365
 
1192
1391
 
1193
1392
 
1194
1393
class VersionedFileError(BzrError):
1195
 
    
 
1394
 
1196
1395
    _fmt = "Versioned file error"
1197
1396
 
1198
1397
 
1199
1398
class RevisionNotPresent(VersionedFileError):
1200
 
    
1201
 
    _fmt = "Revision {%(revision_id)s} not present in %(file_id)s."
 
1399
 
 
1400
    _fmt = 'Revision {%(revision_id)s} not present in "%(file_id)s".'
1202
1401
 
1203
1402
    def __init__(self, revision_id, file_id):
1204
1403
        VersionedFileError.__init__(self)
1207
1406
 
1208
1407
 
1209
1408
class RevisionAlreadyPresent(VersionedFileError):
1210
 
    
1211
 
    _fmt = "Revision {%(revision_id)s} already present in %(file_id)s."
 
1409
 
 
1410
    _fmt = 'Revision {%(revision_id)s} already present in "%(file_id)s".'
1212
1411
 
1213
1412
    def __init__(self, revision_id, file_id):
1214
1413
        VersionedFileError.__init__(self)
1216
1415
        self.file_id = file_id
1217
1416
 
1218
1417
 
1219
 
class KnitError(BzrError):
1220
 
    
 
1418
class VersionedFileInvalidChecksum(VersionedFileError):
 
1419
 
 
1420
    _fmt = "Text did not match its checksum: %(message)s"
 
1421
 
 
1422
 
 
1423
class KnitError(InternalBzrError):
 
1424
 
1221
1425
    _fmt = "Knit error"
1222
1426
 
1223
 
    internal_error = True
1224
 
 
1225
 
 
1226
 
class KnitHeaderError(KnitError):
1227
 
 
1228
 
    _fmt = "Knit header error: %(badline)r unexpected for file %(filename)s"
1229
 
 
1230
 
    def __init__(self, badline, filename):
1231
 
        KnitError.__init__(self)
1232
 
        self.badline = badline
1233
 
        self.filename = filename
1234
 
 
1235
1427
 
1236
1428
class KnitCorrupt(KnitError):
1237
1429
 
1243
1435
        self.how = how
1244
1436
 
1245
1437
 
 
1438
class SHA1KnitCorrupt(KnitCorrupt):
 
1439
 
 
1440
    _fmt = ("Knit %(filename)s corrupt: sha-1 of reconstructed text does not "
 
1441
        "match expected sha-1. key %(key)s expected sha %(expected)s actual "
 
1442
        "sha %(actual)s")
 
1443
 
 
1444
    def __init__(self, filename, actual, expected, key, content):
 
1445
        KnitError.__init__(self)
 
1446
        self.filename = filename
 
1447
        self.actual = actual
 
1448
        self.expected = expected
 
1449
        self.key = key
 
1450
        self.content = content
 
1451
 
 
1452
 
 
1453
class KnitDataStreamIncompatible(KnitError):
 
1454
    # Not raised anymore, as we can convert data streams.  In future we may
 
1455
    # need it again for more exotic cases, so we're keeping it around for now.
 
1456
 
 
1457
    _fmt = "Cannot insert knit data stream of format \"%(stream_format)s\" into knit of format \"%(target_format)s\"."
 
1458
 
 
1459
    def __init__(self, stream_format, target_format):
 
1460
        self.stream_format = stream_format
 
1461
        self.target_format = target_format
 
1462
 
 
1463
 
 
1464
class KnitDataStreamUnknown(KnitError):
 
1465
    # Indicates a data stream we don't know how to handle.
 
1466
 
 
1467
    _fmt = "Cannot parse knit data stream of format \"%(stream_format)s\"."
 
1468
 
 
1469
    def __init__(self, stream_format):
 
1470
        self.stream_format = stream_format
 
1471
 
 
1472
 
 
1473
class KnitHeaderError(KnitError):
 
1474
 
 
1475
    _fmt = 'Knit header error: %(badline)r unexpected for file "%(filename)s".'
 
1476
 
 
1477
    def __init__(self, badline, filename):
 
1478
        KnitError.__init__(self)
 
1479
        self.badline = badline
 
1480
        self.filename = filename
 
1481
 
1246
1482
class KnitIndexUnknownMethod(KnitError):
1247
1483
    """Raised when we don't understand the storage method.
1248
1484
 
1249
1485
    Currently only 'fulltext' and 'line-delta' are supported.
1250
1486
    """
1251
 
    
 
1487
 
1252
1488
    _fmt = ("Knit index %(filename)s does not have a known method"
1253
1489
            " in options: %(options)r")
1254
1490
 
1258
1494
        self.options = options
1259
1495
 
1260
1496
 
 
1497
class RetryWithNewPacks(BzrError):
 
1498
    """Raised when we realize that the packs on disk have changed.
 
1499
 
 
1500
    This is meant as more of a signaling exception, to trap between where a
 
1501
    local error occurred and the code that can actually handle the error and
 
1502
    code that can retry appropriately.
 
1503
    """
 
1504
 
 
1505
    internal_error = True
 
1506
 
 
1507
    _fmt = ("Pack files have changed, reload and retry. context: %(context)s"
 
1508
            " %(orig_error)s")
 
1509
 
 
1510
    def __init__(self, context, reload_occurred, exc_info):
 
1511
        """create a new RetryWithNewPacks error.
 
1512
 
 
1513
        :param reload_occurred: Set to True if we know that the packs have
 
1514
            already been reloaded, and we are failing because of an in-memory
 
1515
            cache miss. If set to True then we will ignore if a reload says
 
1516
            nothing has changed, because we assume it has already reloaded. If
 
1517
            False, then a reload with nothing changed will force an error.
 
1518
        :param exc_info: The original exception traceback, so if there is a
 
1519
            problem we can raise the original error (value from sys.exc_info())
 
1520
        """
 
1521
        BzrError.__init__(self)
 
1522
        self.reload_occurred = reload_occurred
 
1523
        self.exc_info = exc_info
 
1524
        self.orig_error = exc_info[1]
 
1525
        # TODO: The global error handler should probably treat this by
 
1526
        #       raising/printing the original exception with a bit about
 
1527
        #       RetryWithNewPacks also not being caught
 
1528
 
 
1529
 
 
1530
class RetryAutopack(RetryWithNewPacks):
 
1531
    """Raised when we are autopacking and we find a missing file.
 
1532
 
 
1533
    Meant as a signaling exception, to tell the autopack code it should try
 
1534
    again.
 
1535
    """
 
1536
 
 
1537
    internal_error = True
 
1538
 
 
1539
    _fmt = ("Pack files have changed, reload and try autopack again."
 
1540
            " context: %(context)s %(orig_error)s")
 
1541
 
 
1542
 
1261
1543
class NoSuchExportFormat(BzrError):
1262
 
    
 
1544
 
1263
1545
    _fmt = "Export format %(format)r not supported"
1264
1546
 
1265
1547
    def __init__(self, format):
1268
1550
 
1269
1551
 
1270
1552
class TransportError(BzrError):
1271
 
    
 
1553
 
1272
1554
    _fmt = "Transport error: %(msg)s %(orig_error)s"
1273
1555
 
1274
1556
    def __init__(self, msg=None, orig_error=None):
1283
1565
        BzrError.__init__(self)
1284
1566
 
1285
1567
 
1286
 
class TooManyConcurrentRequests(BzrError):
 
1568
class TooManyConcurrentRequests(InternalBzrError):
1287
1569
 
1288
1570
    _fmt = ("The medium '%(medium)s' has reached its concurrent request limit."
1289
1571
            " Be sure to finish_writing and finish_reading on the"
1290
1572
            " currently open request.")
1291
1573
 
1292
 
    internal_error = True
1293
 
 
1294
1574
    def __init__(self, medium):
1295
1575
        self.medium = medium
1296
1576
 
1303
1583
        self.details = details
1304
1584
 
1305
1585
 
 
1586
class UnexpectedProtocolVersionMarker(TransportError):
 
1587
 
 
1588
    _fmt = "Received bad protocol version marker: %(marker)r"
 
1589
 
 
1590
    def __init__(self, marker):
 
1591
        self.marker = marker
 
1592
 
 
1593
 
 
1594
class UnknownSmartMethod(InternalBzrError):
 
1595
 
 
1596
    _fmt = "The server does not recognise the '%(verb)s' request."
 
1597
 
 
1598
    def __init__(self, verb):
 
1599
        self.verb = verb
 
1600
 
 
1601
 
 
1602
class SmartMessageHandlerError(InternalBzrError):
 
1603
 
 
1604
    _fmt = ("The message handler raised an exception:\n"
 
1605
            "%(traceback_text)s")
 
1606
 
 
1607
    def __init__(self, exc_info):
 
1608
        import traceback
 
1609
        self.exc_type, self.exc_value, self.exc_tb = exc_info
 
1610
        self.exc_info = exc_info
 
1611
        traceback_strings = traceback.format_exception(
 
1612
                self.exc_type, self.exc_value, self.exc_tb)
 
1613
        self.traceback_text = ''.join(traceback_strings)
 
1614
 
 
1615
 
1306
1616
# A set of semi-meaningful errors which can be thrown
1307
1617
class TransportNotPossible(TransportError):
1308
1618
 
1333
1643
            self.port = ':%s' % port
1334
1644
 
1335
1645
 
 
1646
# XXX: This is also used for unexpected end of file, which is different at the
 
1647
# TCP level from "connection reset".
1336
1648
class ConnectionReset(TransportError):
1337
1649
 
1338
1650
    _fmt = "Connection closed: %(msg)s %(orig_error)s"
1340
1652
 
1341
1653
class InvalidRange(TransportError):
1342
1654
 
1343
 
    _fmt = "Invalid range access in %(path)s at %(offset)s."
1344
 
    
1345
 
    def __init__(self, path, offset):
1346
 
        TransportError.__init__(self, ("Invalid range access in %s at %d"
1347
 
                                       % (path, offset)))
 
1655
    _fmt = "Invalid range access in %(path)s at %(offset)s: %(msg)s"
 
1656
 
 
1657
    def __init__(self, path, offset, msg=None):
 
1658
        TransportError.__init__(self, msg)
1348
1659
        self.path = path
1349
1660
        self.offset = offset
1350
1661
 
1361
1672
class InvalidHttpRange(InvalidHttpResponse):
1362
1673
 
1363
1674
    _fmt = "Invalid http range %(range)r for %(path)s: %(msg)s"
1364
 
    
 
1675
 
1365
1676
    def __init__(self, path, range, msg):
1366
1677
        self.range = range
1367
1678
        InvalidHttpResponse.__init__(self, path, msg)
1370
1681
class InvalidHttpContentType(InvalidHttpResponse):
1371
1682
 
1372
1683
    _fmt = 'Invalid http Content-type "%(ctype)s" for %(path)s: %(msg)s'
1373
 
    
 
1684
 
1374
1685
    def __init__(self, path, ctype, msg):
1375
1686
        self.ctype = ctype
1376
1687
        InvalidHttpResponse.__init__(self, path, msg)
1380
1691
 
1381
1692
    _fmt = '%(source)s is%(permanently)s redirected to %(target)s'
1382
1693
 
1383
 
    def __init__(self, source, target, is_permament=False, qual_proto=None):
 
1694
    def __init__(self, source, target, is_permanent=False):
1384
1695
        self.source = source
1385
1696
        self.target = target
1386
 
        if is_permament:
 
1697
        if is_permanent:
1387
1698
            self.permanently = ' permanently'
1388
1699
        else:
1389
1700
            self.permanently = ''
1390
 
        self.is_permament = is_permament
1391
 
        self._qualified_proto = qual_proto
1392
1701
        TransportError.__init__(self)
1393
1702
 
1394
 
    def _requalify_url(self, url):
1395
 
        """Restore the qualified proto in front of the url"""
1396
 
        # When this exception is raised, source and target are in
1397
 
        # user readable format. But some transports may use a
1398
 
        # different proto (http+urllib:// will present http:// to
1399
 
        # the user. If a qualified proto is specified, the code
1400
 
        # trapping the exception can get the qualified urls to
1401
 
        # properly handle the redirection themself (creating a
1402
 
        # new transport object from the target url for example).
1403
 
        # But checking that the scheme of the original and
1404
 
        # redirected urls are the same can be tricky. (see the
1405
 
        # FIXME in BzrDir.open_from_transport for the unique use
1406
 
        # case so far).
1407
 
        if self._qualified_proto is None:
1408
 
            return url
1409
 
 
1410
 
        # The TODO related to NotBranchError mention that doing
1411
 
        # that kind of manipulation on the urls may not be the
1412
 
        # exception object job. On the other hand, this object is
1413
 
        # the interface between the code and the user so
1414
 
        # presenting the urls in different ways is indeed its
1415
 
        # job...
1416
 
        import urlparse
1417
 
        proto, netloc, path, query, fragment = urlparse.urlsplit(url)
1418
 
        return urlparse.urlunsplit((self._qualified_proto, netloc, path,
1419
 
                                   query, fragment))
1420
 
 
1421
 
    def get_source_url(self):
1422
 
        return self._requalify_url(self.source)
1423
 
 
1424
 
    def get_target_url(self):
1425
 
        return self._requalify_url(self.target)
1426
 
 
1427
1703
 
1428
1704
class TooManyRedirections(TransportError):
1429
1705
 
1430
1706
    _fmt = "Too many redirections"
1431
1707
 
 
1708
 
1432
1709
class ConflictsInTree(BzrError):
1433
1710
 
1434
1711
    _fmt = "Working tree has conflicts."
1440
1717
        if filename is None:
1441
1718
            filename = ""
1442
1719
        message = "Error(s) parsing config file %s:\n%s" % \
1443
 
            (filename, ('\n'.join(e.message for e in errors)))
 
1720
            (filename, ('\n'.join(e.msg for e in errors)))
1444
1721
        BzrError.__init__(self, message)
1445
1722
 
1446
1723
 
1455
1732
 
1456
1733
class SigningFailed(BzrError):
1457
1734
 
1458
 
    _fmt = "Failed to gpg sign data with command %(command_line)r"
 
1735
    _fmt = 'Failed to gpg sign data with command "%(command_line)s"'
1459
1736
 
1460
1737
    def __init__(self, command_line):
1461
1738
        BzrError.__init__(self, command_line=command_line)
1463
1740
 
1464
1741
class WorkingTreeNotRevision(BzrError):
1465
1742
 
1466
 
    _fmt = ("The working tree for %(basedir)s has changed since" 
 
1743
    _fmt = ("The working tree for %(basedir)s has changed since"
1467
1744
            " the last commit, but weave merge requires that it be"
1468
1745
            " unchanged")
1469
1746
 
1486
1763
        self.graph = graph
1487
1764
 
1488
1765
 
1489
 
class WritingCompleted(BzrError):
 
1766
class WritingCompleted(InternalBzrError):
1490
1767
 
1491
1768
    _fmt = ("The MediumRequest '%(request)s' has already had finish_writing "
1492
1769
            "called upon it - accept bytes may not be called anymore.")
1493
1770
 
1494
 
    internal_error = True
1495
 
 
1496
1771
    def __init__(self, request):
1497
1772
        self.request = request
1498
1773
 
1499
1774
 
1500
 
class WritingNotComplete(BzrError):
 
1775
class WritingNotComplete(InternalBzrError):
1501
1776
 
1502
1777
    _fmt = ("The MediumRequest '%(request)s' has not has finish_writing "
1503
1778
            "called upon it - until the write phase is complete no "
1504
1779
            "data may be read.")
1505
1780
 
1506
 
    internal_error = True
1507
 
 
1508
1781
    def __init__(self, request):
1509
1782
        self.request = request
1510
1783
 
1518
1791
        self.filename = filename
1519
1792
 
1520
1793
 
1521
 
class MediumNotConnected(BzrError):
 
1794
class MediumNotConnected(InternalBzrError):
1522
1795
 
1523
1796
    _fmt = """The medium '%(medium)s' is not connected."""
1524
1797
 
1525
 
    internal_error = True
1526
 
 
1527
1798
    def __init__(self, medium):
1528
1799
        self.medium = medium
1529
1800
 
1535
1806
 
1536
1807
class NoBundleFound(BzrError):
1537
1808
 
1538
 
    _fmt = "No bundle was found in %(filename)s"
 
1809
    _fmt = 'No bundle was found in "%(filename)s".'
1539
1810
 
1540
1811
    def __init__(self, filename):
1541
1812
        BzrError.__init__(self)
1605
1876
        self.root_trans_id = transform.root
1606
1877
 
1607
1878
 
1608
 
class BzrBadParameter(BzrError):
 
1879
class BzrBadParameter(InternalBzrError):
1609
1880
 
1610
1881
    _fmt = "Bad parameter: %(param)r"
1611
1882
 
1612
 
    internal_error = True
1613
 
 
1614
1883
    # This exception should never be thrown, but it is a base class for all
1615
1884
    # parameter-to-function errors.
1616
1885
 
1639
1908
    _fmt = "Could not move %(from_path)s%(operator)s %(to_path)s%(extra)s"
1640
1909
 
1641
1910
    def __init__(self, from_path='', to_path='', extra=None):
 
1911
        from bzrlib.osutils import splitpath
1642
1912
        BzrError.__init__(self)
1643
1913
        if extra:
1644
1914
            self.extra = ': ' + str(extra)
1648
1918
        has_from = len(from_path) > 0
1649
1919
        has_to = len(to_path) > 0
1650
1920
        if has_from:
1651
 
            self.from_path = osutils.splitpath(from_path)[-1]
 
1921
            self.from_path = splitpath(from_path)[-1]
1652
1922
        else:
1653
1923
            self.from_path = ''
1654
1924
 
1655
1925
        if has_to:
1656
 
            self.to_path = osutils.splitpath(to_path)[-1]
 
1926
            self.to_path = splitpath(to_path)[-1]
1657
1927
        else:
1658
1928
            self.to_path = ''
1659
1929
 
1678
1948
class BzrRemoveChangedFilesError(BzrError):
1679
1949
    """Used when user is trying to remove changed files."""
1680
1950
 
1681
 
    _fmt = ("Can't remove changed or unknown files:\n%(changes_as_text)s"
 
1951
    _fmt = ("Can't safely remove modified or unknown files:\n"
 
1952
        "%(changes_as_text)s"
1682
1953
        "Use --keep to not delete them, or --force to delete them regardless.")
1683
1954
 
1684
1955
    def __init__(self, tree_delta):
1741
2012
 
1742
2013
class BadConversionTarget(BzrError):
1743
2014
 
1744
 
    _fmt = "Cannot convert to format %(format)s.  %(problem)s"
 
2015
    _fmt = "Cannot convert from format %(from_format)s to format %(format)s." \
 
2016
            "    %(problem)s"
1745
2017
 
1746
 
    def __init__(self, problem, format):
 
2018
    def __init__(self, problem, format, from_format=None):
1747
2019
        BzrError.__init__(self)
1748
2020
        self.problem = problem
1749
2021
        self.format = format
 
2022
        self.from_format = from_format or '(unspecified)'
 
2023
 
 
2024
 
 
2025
class NoDiffFound(BzrError):
 
2026
 
 
2027
    _fmt = 'Could not find an appropriate Differ for file "%(path)s"'
 
2028
 
 
2029
    def __init__(self, path):
 
2030
        BzrError.__init__(self, path)
 
2031
 
 
2032
 
 
2033
class ExecutableMissing(BzrError):
 
2034
 
 
2035
    _fmt = "%(exe_name)s could not be found on this machine"
 
2036
 
 
2037
    def __init__(self, exe_name):
 
2038
        BzrError.__init__(self, exe_name=exe_name)
1750
2039
 
1751
2040
 
1752
2041
class NoDiff(BzrError):
1762
2051
    _fmt = "Diff3 is not installed on this machine."
1763
2052
 
1764
2053
 
 
2054
class ExistingContent(BzrError):
 
2055
    # Added in bzrlib 0.92, used by VersionedFile.add_lines.
 
2056
 
 
2057
    _fmt = "The content being inserted is already present."
 
2058
 
 
2059
 
1765
2060
class ExistingLimbo(BzrError):
1766
2061
 
1767
2062
    _fmt = """This tree contains left-over files from a failed operation.
1768
2063
    Please examine %(limbo_dir)s to see if it contains any files you wish to
1769
2064
    keep, and delete it when you are done."""
1770
 
    
 
2065
 
1771
2066
    def __init__(self, limbo_dir):
1772
2067
       BzrError.__init__(self)
1773
2068
       self.limbo_dir = limbo_dir
1774
2069
 
1775
2070
 
 
2071
class ExistingPendingDeletion(BzrError):
 
2072
 
 
2073
    _fmt = """This tree contains left-over files from a failed operation.
 
2074
    Please examine %(pending_deletion)s to see if it contains any files you
 
2075
    wish to keep, and delete it when you are done."""
 
2076
 
 
2077
    def __init__(self, pending_deletion):
 
2078
       BzrError.__init__(self, pending_deletion=pending_deletion)
 
2079
 
 
2080
 
1776
2081
class ImmortalLimbo(BzrError):
1777
2082
 
1778
 
    _fmt = """Unable to delete transform temporary directory $(limbo_dir)s.
 
2083
    _fmt = """Unable to delete transform temporary directory %(limbo_dir)s.
1779
2084
    Please examine %(limbo_dir)s to see if it contains any files you wish to
1780
2085
    keep, and delete it when you are done."""
1781
2086
 
1784
2089
       self.limbo_dir = limbo_dir
1785
2090
 
1786
2091
 
 
2092
class ImmortalPendingDeletion(BzrError):
 
2093
 
 
2094
    _fmt = ("Unable to delete transform temporary directory "
 
2095
    "%(pending_deletion)s.  Please examine %(pending_deletion)s to see if it "
 
2096
    "contains any files you wish to keep, and delete it when you are done.")
 
2097
 
 
2098
    def __init__(self, pending_deletion):
 
2099
       BzrError.__init__(self, pending_deletion=pending_deletion)
 
2100
 
 
2101
 
1787
2102
class OutOfDateTree(BzrError):
1788
2103
 
1789
 
    _fmt = "Working tree is out of date, please run 'bzr update'."
 
2104
    _fmt = "Working tree is out of date, please run 'bzr update'.%(more)s"
1790
2105
 
1791
 
    def __init__(self, tree):
 
2106
    def __init__(self, tree, more=None):
 
2107
        if more is None:
 
2108
            more = ''
 
2109
        else:
 
2110
            more = ' ' + more
1792
2111
        BzrError.__init__(self)
1793
2112
        self.tree = tree
 
2113
        self.more = more
1794
2114
 
1795
2115
 
1796
2116
class PublicBranchOutOfDate(BzrError):
1816
2136
    _fmt = "Format error in conflict listings"
1817
2137
 
1818
2138
 
 
2139
class CorruptDirstate(BzrError):
 
2140
 
 
2141
    _fmt = ("Inconsistency in dirstate file %(dirstate_path)s.\n"
 
2142
            "Error: %(description)s")
 
2143
 
 
2144
    def __init__(self, dirstate_path, description):
 
2145
        BzrError.__init__(self)
 
2146
        self.dirstate_path = dirstate_path
 
2147
        self.description = description
 
2148
 
 
2149
 
1819
2150
class CorruptRepository(BzrError):
1820
2151
 
1821
2152
    _fmt = ("An error has been detected in the repository %(repo_path)s.\n"
1826
2157
        self.repo_path = repo.bzrdir.root_transport.base
1827
2158
 
1828
2159
 
 
2160
class InconsistentDelta(BzrError):
 
2161
    """Used when we get a delta that is not valid."""
 
2162
 
 
2163
    _fmt = ("An inconsistent delta was supplied involving %(path)r,"
 
2164
            " %(file_id)r\nreason: %(reason)s")
 
2165
 
 
2166
    def __init__(self, path, file_id, reason):
 
2167
        BzrError.__init__(self)
 
2168
        self.path = path
 
2169
        self.file_id = file_id
 
2170
        self.reason = reason
 
2171
 
 
2172
 
 
2173
class InconsistentDeltaDelta(InconsistentDelta):
 
2174
    """Used when we get a delta that is not valid."""
 
2175
 
 
2176
    _fmt = ("An inconsistent delta was supplied: %(delta)r"
 
2177
            "\nreason: %(reason)s")
 
2178
 
 
2179
    def __init__(self, delta, reason):
 
2180
        BzrError.__init__(self)
 
2181
        self.delta = delta
 
2182
        self.reason = reason
 
2183
 
 
2184
 
1829
2185
class UpgradeRequired(BzrError):
1830
2186
 
1831
2187
    _fmt = "To use this feature you must upgrade your branch at %(path)s."
1835
2191
        self.path = path
1836
2192
 
1837
2193
 
 
2194
class RepositoryUpgradeRequired(UpgradeRequired):
 
2195
 
 
2196
    _fmt = "To use this feature you must upgrade your repository at %(path)s."
 
2197
 
 
2198
 
 
2199
class RichRootUpgradeRequired(UpgradeRequired):
 
2200
 
 
2201
    _fmt = ("To use this feature you must upgrade your branch at %(path)s to"
 
2202
           " a format which supports rich roots.")
 
2203
 
 
2204
 
1838
2205
class LocalRequiresBoundBranch(BzrError):
1839
2206
 
1840
2207
    _fmt = "Cannot perform local-only commits on unbound branches."
1841
2208
 
1842
2209
 
1843
 
class MissingProgressBarFinish(BzrError):
1844
 
 
1845
 
    _fmt = "A nested progress bar was not 'finished' correctly."
1846
 
 
1847
 
 
1848
 
class InvalidProgressBarType(BzrError):
1849
 
 
1850
 
    _fmt = ("Environment variable BZR_PROGRESS_BAR='%(bar_type)s"
1851
 
            " is not a supported type Select one of: %(valid_types)s")
1852
 
 
1853
 
    def __init__(self, bar_type, valid_types):
1854
 
        BzrError.__init__(self, bar_type=bar_type, valid_types=valid_types)
1855
 
 
1856
 
 
1857
2210
class UnsupportedOperation(BzrError):
1858
2211
 
1859
2212
    _fmt = ("The method %(mname)s is not supported on"
1876
2229
 
1877
2230
 
1878
2231
class BinaryFile(BzrError):
1879
 
    
 
2232
 
1880
2233
    _fmt = "File is binary but should be text."
1881
2234
 
1882
2235
 
1902
2255
 
1903
2256
 
1904
2257
class NotABundle(BzrError):
1905
 
    
 
2258
 
1906
2259
    _fmt = "Not a bzr revision-bundle: %(text)r"
1907
2260
 
1908
2261
    def __init__(self, text):
1910
2263
        self.text = text
1911
2264
 
1912
2265
 
1913
 
class BadBundle(BzrError): 
1914
 
    
 
2266
class BadBundle(BzrError):
 
2267
 
1915
2268
    _fmt = "Bad bzr revision-bundle: %(text)r"
1916
2269
 
1917
2270
    def __init__(self, text):
1919
2272
        self.text = text
1920
2273
 
1921
2274
 
1922
 
class MalformedHeader(BadBundle): 
1923
 
    
 
2275
class MalformedHeader(BadBundle):
 
2276
 
1924
2277
    _fmt = "Malformed bzr revision-bundle header: %(text)r"
1925
2278
 
1926
2279
 
1927
 
class MalformedPatches(BadBundle): 
1928
 
    
 
2280
class MalformedPatches(BadBundle):
 
2281
 
1929
2282
    _fmt = "Malformed patches in bzr revision-bundle: %(text)r"
1930
2283
 
1931
2284
 
1932
 
class MalformedFooter(BadBundle): 
1933
 
    
 
2285
class MalformedFooter(BadBundle):
 
2286
 
1934
2287
    _fmt = "Malformed footer in bzr revision-bundle: %(text)r"
1935
2288
 
1936
2289
 
1937
2290
class UnsupportedEOLMarker(BadBundle):
1938
 
    
1939
 
    _fmt = "End of line marker was not \\n in bzr revision-bundle"    
 
2291
 
 
2292
    _fmt = "End of line marker was not \\n in bzr revision-bundle"
1940
2293
 
1941
2294
    def __init__(self):
1942
 
        # XXX: BadBundle's constructor assumes there's explanatory text, 
 
2295
        # XXX: BadBundle's constructor assumes there's explanatory text,
1943
2296
        # but for this there is not
1944
2297
        BzrError.__init__(self)
1945
2298
 
1946
2299
 
1947
2300
class IncompatibleBundleFormat(BzrError):
1948
 
    
 
2301
 
1949
2302
    _fmt = "Bundle format %(bundle_format)s is incompatible with %(other)s"
1950
2303
 
1951
2304
    def __init__(self, bundle_format, other):
1955
2308
 
1956
2309
 
1957
2310
class BadInventoryFormat(BzrError):
1958
 
    
 
2311
 
1959
2312
    _fmt = "Root class for inventory serialization errors"
1960
2313
 
1961
2314
 
1972
2325
    _fmt = """This operation requires rich root data storage"""
1973
2326
 
1974
2327
 
1975
 
class NoSmartMedium(BzrError):
 
2328
class NoSmartMedium(InternalBzrError):
1976
2329
 
1977
2330
    _fmt = "The transport '%(transport)s' cannot tunnel the smart protocol."
1978
2331
 
1979
 
    internal_error = True
1980
 
 
1981
2332
    def __init__(self, transport):
1982
2333
        self.transport = transport
1983
2334
 
1984
2335
 
1985
 
class NoSmartServer(NotBranchError):
1986
 
 
1987
 
    _fmt = "No smart server available at %(url)s"
1988
 
 
1989
 
    def __init__(self, url):
1990
 
        self.url = url
1991
 
 
1992
 
 
1993
2336
class UnknownSSH(BzrError):
1994
2337
 
1995
2338
    _fmt = "Unrecognised value for BZR_SSH environment variable: %(vendor)s"
2005
2348
            " Please set BZR_SSH environment variable.")
2006
2349
 
2007
2350
 
 
2351
class GhostRevisionsHaveNoRevno(BzrError):
 
2352
    """When searching for revnos, if we encounter a ghost, we are stuck"""
 
2353
 
 
2354
    _fmt = ("Could not determine revno for {%(revision_id)s} because"
 
2355
            " its ancestry shows a ghost at {%(ghost_revision_id)s}")
 
2356
 
 
2357
    def __init__(self, revision_id, ghost_revision_id):
 
2358
        self.revision_id = revision_id
 
2359
        self.ghost_revision_id = ghost_revision_id
 
2360
 
 
2361
 
2008
2362
class GhostRevisionUnusableHere(BzrError):
2009
2363
 
2010
2364
    _fmt = "Ghost revision {%(revision_id)s} cannot be used here."
2014
2368
        self.revision_id = revision_id
2015
2369
 
2016
2370
 
2017
 
class IllegalUseOfScopeReplacer(BzrError):
 
2371
class IllegalUseOfScopeReplacer(InternalBzrError):
2018
2372
 
2019
2373
    _fmt = ("ScopeReplacer object %(name)r was used incorrectly:"
2020
2374
            " %(msg)s%(extra)s")
2021
2375
 
2022
 
    internal_error = True
2023
 
 
2024
2376
    def __init__(self, name, msg, extra=None):
2025
2377
        BzrError.__init__(self)
2026
2378
        self.name = name
2031
2383
            self.extra = ''
2032
2384
 
2033
2385
 
2034
 
class InvalidImportLine(BzrError):
 
2386
class InvalidImportLine(InternalBzrError):
2035
2387
 
2036
2388
    _fmt = "Not a valid import statement: %(msg)\n%(text)s"
2037
2389
 
2038
 
    internal_error = True
2039
 
 
2040
2390
    def __init__(self, text, msg):
2041
2391
        BzrError.__init__(self)
2042
2392
        self.text = text
2043
2393
        self.msg = msg
2044
2394
 
2045
2395
 
2046
 
class ImportNameCollision(BzrError):
 
2396
class ImportNameCollision(InternalBzrError):
2047
2397
 
2048
2398
    _fmt = ("Tried to import an object to the same name as"
2049
2399
            " an existing object. %(name)s")
2050
2400
 
2051
 
    internal_error = True
2052
 
 
2053
2401
    def __init__(self, name):
2054
2402
        BzrError.__init__(self)
2055
2403
        self.name = name
2068
2416
        " branch location."
2069
2417
 
2070
2418
 
 
2419
class IllegalMergeDirectivePayload(BzrError):
 
2420
    """A merge directive contained something other than a patch or bundle"""
 
2421
 
 
2422
    _fmt = "Bad merge directive payload %(start)r"
 
2423
 
 
2424
    def __init__(self, start):
 
2425
        BzrError(self)
 
2426
        self.start = start
 
2427
 
 
2428
 
 
2429
class PatchVerificationFailed(BzrError):
 
2430
    """A patch from a merge directive could not be verified"""
 
2431
 
 
2432
    _fmt = "Preview patch does not match requested changes."
 
2433
 
 
2434
 
2071
2435
class PatchMissing(BzrError):
2072
2436
    """Raise a patch type was specified but no patch supplied"""
2073
2437
 
2074
 
    _fmt = "patch_type was %(patch_type)s, but no patch was supplied."
 
2438
    _fmt = "Patch_type was %(patch_type)s, but no patch was supplied."
2075
2439
 
2076
2440
    def __init__(self, patch_type):
2077
2441
        BzrError.__init__(self)
2078
2442
        self.patch_type = patch_type
2079
2443
 
2080
2444
 
 
2445
class TargetNotBranch(BzrError):
 
2446
    """A merge directive's target branch is required, but isn't a branch"""
 
2447
 
 
2448
    _fmt = ("Your branch does not have all of the revisions required in "
 
2449
            "order to merge this merge directive and the target "
 
2450
            "location specified in the merge directive is not a branch: "
 
2451
            "%(location)s.")
 
2452
 
 
2453
    def __init__(self, location):
 
2454
        BzrError.__init__(self)
 
2455
        self.location = location
 
2456
 
 
2457
 
2081
2458
class UnsupportedInventoryKind(BzrError):
2082
 
    
 
2459
 
2083
2460
    _fmt = """Unsupported entry kind %(kind)s"""
2084
2461
 
2085
2462
    def __init__(self, kind):
2088
2465
 
2089
2466
class BadSubsumeSource(BzrError):
2090
2467
 
2091
 
    _fmt = """Can't subsume %(other_tree)s into %(tree)s.  %(reason)s"""
 
2468
    _fmt = "Can't subsume %(other_tree)s into %(tree)s. %(reason)s"
2092
2469
 
2093
2470
    def __init__(self, tree, other_tree, reason):
2094
2471
        self.tree = tree
2097
2474
 
2098
2475
 
2099
2476
class SubsumeTargetNeedsUpgrade(BzrError):
2100
 
    
 
2477
 
2101
2478
    _fmt = """Subsume target %(other_tree)s needs to be upgraded."""
2102
2479
 
2103
2480
    def __init__(self, other_tree):
2104
2481
        self.other_tree = other_tree
2105
2482
 
2106
2483
 
2107
 
class BadReferenceTarget(BzrError):
2108
 
 
2109
 
    _fmt = "Can't add reference to %(other_tree)s into %(tree)s.  %(reason)s"
2110
 
 
2111
 
    internal_error = True
 
2484
class BadReferenceTarget(InternalBzrError):
 
2485
 
 
2486
    _fmt = "Can't add reference to %(other_tree)s into %(tree)s." \
 
2487
           "%(reason)s"
2112
2488
 
2113
2489
    def __init__(self, tree, other_tree, reason):
2114
2490
        self.tree = tree
2127
2503
class TagsNotSupported(BzrError):
2128
2504
 
2129
2505
    _fmt = ("Tags not supported by %(branch)s;"
2130
 
            " you may be able to use bzr upgrade --dirstate-tags.")
 
2506
            " you may be able to use bzr upgrade.")
2131
2507
 
2132
2508
    def __init__(self, branch):
2133
2509
        self.branch = branch
2134
2510
 
2135
 
        
 
2511
 
2136
2512
class TagAlreadyExists(BzrError):
2137
2513
 
2138
2514
    _fmt = "Tag %(tag_name)s already exists."
2143
2519
 
2144
2520
class MalformedBugIdentifier(BzrError):
2145
2521
 
2146
 
    _fmt = "Did not understand bug identifier %(bug_id)s: %(reason)s"
 
2522
    _fmt = ('Did not understand bug identifier %(bug_id)s: %(reason)s. '
 
2523
            'See "bzr help bugs" for more information on this feature.')
2147
2524
 
2148
2525
    def __init__(self, bug_id, reason):
2149
2526
        self.bug_id = bug_id
2150
2527
        self.reason = reason
2151
2528
 
2152
2529
 
 
2530
class InvalidBugTrackerURL(BzrError):
 
2531
 
 
2532
    _fmt = ("The URL for bug tracker \"%(abbreviation)s\" doesn't "
 
2533
            "contain {id}: %(url)s")
 
2534
 
 
2535
    def __init__(self, abbreviation, url):
 
2536
        self.abbreviation = abbreviation
 
2537
        self.url = url
 
2538
 
 
2539
 
2153
2540
class UnknownBugTrackerAbbreviation(BzrError):
2154
2541
 
2155
2542
    _fmt = ("Cannot find registered bug tracker called %(abbreviation)s "
2160
2547
        self.branch = branch
2161
2548
 
2162
2549
 
 
2550
class InvalidLineInBugsProperty(BzrError):
 
2551
 
 
2552
    _fmt = ("Invalid line in bugs property: '%(line)s'")
 
2553
 
 
2554
    def __init__(self, line):
 
2555
        self.line = line
 
2556
 
 
2557
 
 
2558
class InvalidBugStatus(BzrError):
 
2559
 
 
2560
    _fmt = ("Invalid bug status: '%(status)s'")
 
2561
 
 
2562
    def __init__(self, status):
 
2563
        self.status = status
 
2564
 
 
2565
 
2163
2566
class UnexpectedSmartServerResponse(BzrError):
2164
2567
 
2165
2568
    _fmt = "Could not understand response from smart server: %(response_tuple)r"
2168
2571
        self.response_tuple = response_tuple
2169
2572
 
2170
2573
 
 
2574
class ErrorFromSmartServer(BzrError):
 
2575
    """An error was received from a smart server.
 
2576
 
 
2577
    :seealso: UnknownErrorFromSmartServer
 
2578
    """
 
2579
 
 
2580
    _fmt = "Error received from smart server: %(error_tuple)r"
 
2581
 
 
2582
    internal_error = True
 
2583
 
 
2584
    def __init__(self, error_tuple):
 
2585
        self.error_tuple = error_tuple
 
2586
        try:
 
2587
            self.error_verb = error_tuple[0]
 
2588
        except IndexError:
 
2589
            self.error_verb = None
 
2590
        self.error_args = error_tuple[1:]
 
2591
 
 
2592
 
 
2593
class UnknownErrorFromSmartServer(BzrError):
 
2594
    """An ErrorFromSmartServer could not be translated into a typical bzrlib
 
2595
    error.
 
2596
 
 
2597
    This is distinct from ErrorFromSmartServer so that it is possible to
 
2598
    distinguish between the following two cases:
 
2599
      - ErrorFromSmartServer was uncaught.  This is logic error in the client
 
2600
        and so should provoke a traceback to the user.
 
2601
      - ErrorFromSmartServer was caught but its error_tuple could not be
 
2602
        translated.  This is probably because the server sent us garbage, and
 
2603
        should not provoke a traceback.
 
2604
    """
 
2605
 
 
2606
    _fmt = "Server sent an unexpected error: %(error_tuple)r"
 
2607
 
 
2608
    internal_error = False
 
2609
 
 
2610
    def __init__(self, error_from_smart_server):
 
2611
        """Constructor.
 
2612
 
 
2613
        :param error_from_smart_server: An ErrorFromSmartServer instance.
 
2614
        """
 
2615
        self.error_from_smart_server = error_from_smart_server
 
2616
        self.error_tuple = error_from_smart_server.error_tuple
 
2617
 
 
2618
 
2171
2619
class ContainerError(BzrError):
2172
2620
    """Base class of container errors."""
2173
2621
 
2175
2623
class UnknownContainerFormatError(ContainerError):
2176
2624
 
2177
2625
    _fmt = "Unrecognised container format: %(container_format)r"
2178
 
    
 
2626
 
2179
2627
    def __init__(self, container_format):
2180
2628
        self.container_format = container_format
2181
2629
 
2184
2632
 
2185
2633
    _fmt = "Unexpected end of container stream"
2186
2634
 
2187
 
    internal_error = False
2188
 
 
2189
2635
 
2190
2636
class UnknownRecordTypeError(ContainerError):
2191
2637
 
2213
2659
 
2214
2660
class DuplicateRecordNameError(ContainerError):
2215
2661
 
2216
 
    _fmt = "Container has multiple records with the same name: \"%(name)s\""
 
2662
    _fmt = "Container has multiple records with the same name: %(name)s"
2217
2663
 
2218
2664
    def __init__(self, name):
2219
2665
        self.name = name
2220
2666
 
2221
2667
 
2222
 
class NoDestinationAddress(BzrError):
 
2668
class NoDestinationAddress(InternalBzrError):
2223
2669
 
2224
2670
    _fmt = "Message does not have a destination address."
2225
2671
 
2226
 
    internal_error = True
 
2672
 
 
2673
class RepositoryDataStreamError(BzrError):
 
2674
 
 
2675
    _fmt = "Corrupt or incompatible data stream: %(reason)s"
 
2676
 
 
2677
    def __init__(self, reason):
 
2678
        self.reason = reason
2227
2679
 
2228
2680
 
2229
2681
class SMTPError(BzrError):
2232
2684
 
2233
2685
    def __init__(self, error):
2234
2686
        self.error = error
 
2687
 
 
2688
 
 
2689
class NoMessageSupplied(BzrError):
 
2690
 
 
2691
    _fmt = "No message supplied."
 
2692
 
 
2693
 
 
2694
class NoMailAddressSpecified(BzrError):
 
2695
 
 
2696
    _fmt = "No mail-to address (--mail-to) or output (-o) specified."
 
2697
 
 
2698
 
 
2699
class UnknownMailClient(BzrError):
 
2700
 
 
2701
    _fmt = "Unknown mail client: %(mail_client)s"
 
2702
 
 
2703
    def __init__(self, mail_client):
 
2704
        BzrError.__init__(self, mail_client=mail_client)
 
2705
 
 
2706
 
 
2707
class MailClientNotFound(BzrError):
 
2708
 
 
2709
    _fmt = "Unable to find mail client with the following names:"\
 
2710
        " %(mail_command_list_string)s"
 
2711
 
 
2712
    def __init__(self, mail_command_list):
 
2713
        mail_command_list_string = ', '.join(mail_command_list)
 
2714
        BzrError.__init__(self, mail_command_list=mail_command_list,
 
2715
                          mail_command_list_string=mail_command_list_string)
 
2716
 
 
2717
class SMTPConnectionRefused(SMTPError):
 
2718
 
 
2719
    _fmt = "SMTP connection to %(host)s refused"
 
2720
 
 
2721
    def __init__(self, error, host):
 
2722
        self.error = error
 
2723
        self.host = host
 
2724
 
 
2725
 
 
2726
class DefaultSMTPConnectionRefused(SMTPConnectionRefused):
 
2727
 
 
2728
    _fmt = "Please specify smtp_server.  No server at default %(host)s."
 
2729
 
 
2730
 
 
2731
class BzrDirError(BzrError):
 
2732
 
 
2733
    def __init__(self, bzrdir):
 
2734
        import bzrlib.urlutils as urlutils
 
2735
        display_url = urlutils.unescape_for_display(bzrdir.root_transport.base,
 
2736
                                                    'ascii')
 
2737
        BzrError.__init__(self, bzrdir=bzrdir, display_url=display_url)
 
2738
 
 
2739
 
 
2740
class UnsyncedBranches(BzrDirError):
 
2741
 
 
2742
    _fmt = ("'%(display_url)s' is not in sync with %(target_url)s.  See"
 
2743
            " bzr help sync-for-reconfigure.")
 
2744
 
 
2745
    def __init__(self, bzrdir, target_branch):
 
2746
        BzrDirError.__init__(self, bzrdir)
 
2747
        import bzrlib.urlutils as urlutils
 
2748
        self.target_url = urlutils.unescape_for_display(target_branch.base,
 
2749
                                                        'ascii')
 
2750
 
 
2751
 
 
2752
class AlreadyBranch(BzrDirError):
 
2753
 
 
2754
    _fmt = "'%(display_url)s' is already a branch."
 
2755
 
 
2756
 
 
2757
class AlreadyTree(BzrDirError):
 
2758
 
 
2759
    _fmt = "'%(display_url)s' is already a tree."
 
2760
 
 
2761
 
 
2762
class AlreadyCheckout(BzrDirError):
 
2763
 
 
2764
    _fmt = "'%(display_url)s' is already a checkout."
 
2765
 
 
2766
 
 
2767
class AlreadyLightweightCheckout(BzrDirError):
 
2768
 
 
2769
    _fmt = "'%(display_url)s' is already a lightweight checkout."
 
2770
 
 
2771
 
 
2772
class AlreadyUsingShared(BzrDirError):
 
2773
 
 
2774
    _fmt = "'%(display_url)s' is already using a shared repository."
 
2775
 
 
2776
 
 
2777
class AlreadyStandalone(BzrDirError):
 
2778
 
 
2779
    _fmt = "'%(display_url)s' is already standalone."
 
2780
 
 
2781
 
 
2782
class AlreadyWithTrees(BzrDirError):
 
2783
 
 
2784
    _fmt = ("Shared repository '%(display_url)s' already creates "
 
2785
            "working trees.")
 
2786
 
 
2787
 
 
2788
class AlreadyWithNoTrees(BzrDirError):
 
2789
 
 
2790
    _fmt = ("Shared repository '%(display_url)s' already doesn't create "
 
2791
            "working trees.")
 
2792
 
 
2793
 
 
2794
class ReconfigurationNotSupported(BzrDirError):
 
2795
 
 
2796
    _fmt = "Requested reconfiguration of '%(display_url)s' is not supported."
 
2797
 
 
2798
 
 
2799
class NoBindLocation(BzrDirError):
 
2800
 
 
2801
    _fmt = "No location could be found to bind to at %(display_url)s."
 
2802
 
 
2803
 
 
2804
class UncommittedChanges(BzrError):
 
2805
 
 
2806
    _fmt = ('Working tree "%(display_url)s" has uncommitted changes'
 
2807
            ' (See bzr status).%(more)s')
 
2808
 
 
2809
    def __init__(self, tree, more=None):
 
2810
        if more is None:
 
2811
            more = ''
 
2812
        else:
 
2813
            more = ' ' + more
 
2814
        import bzrlib.urlutils as urlutils
 
2815
        display_url = urlutils.unescape_for_display(
 
2816
            tree.bzrdir.root_transport.base, 'ascii')
 
2817
        BzrError.__init__(self, tree=tree, display_url=display_url, more=more)
 
2818
 
 
2819
 
 
2820
class MissingTemplateVariable(BzrError):
 
2821
 
 
2822
    _fmt = 'Variable {%(name)s} is not available.'
 
2823
 
 
2824
    def __init__(self, name):
 
2825
        self.name = name
 
2826
 
 
2827
 
 
2828
class NoTemplate(BzrError):
 
2829
 
 
2830
    _fmt = 'No template specified.'
 
2831
 
 
2832
 
 
2833
class UnableCreateSymlink(BzrError):
 
2834
 
 
2835
    _fmt = 'Unable to create symlink %(path_str)son this platform'
 
2836
 
 
2837
    def __init__(self, path=None):
 
2838
        path_str = ''
 
2839
        if path:
 
2840
            try:
 
2841
                path_str = repr(str(path))
 
2842
            except UnicodeEncodeError:
 
2843
                path_str = repr(path)
 
2844
            path_str += ' '
 
2845
        self.path_str = path_str
 
2846
 
 
2847
 
 
2848
class UnsupportedTimezoneFormat(BzrError):
 
2849
 
 
2850
    _fmt = ('Unsupported timezone format "%(timezone)s", '
 
2851
            'options are "utc", "original", "local".')
 
2852
 
 
2853
    def __init__(self, timezone):
 
2854
        self.timezone = timezone
 
2855
 
 
2856
 
 
2857
class CommandAvailableInPlugin(StandardError):
 
2858
 
 
2859
    internal_error = False
 
2860
 
 
2861
    def __init__(self, cmd_name, plugin_metadata, provider):
 
2862
 
 
2863
        self.plugin_metadata = plugin_metadata
 
2864
        self.cmd_name = cmd_name
 
2865
        self.provider = provider
 
2866
 
 
2867
    def __str__(self):
 
2868
 
 
2869
        _fmt = ('"%s" is not a standard bzr command. \n'
 
2870
                'However, the following official plugin provides this command: %s\n'
 
2871
                'You can install it by going to: %s'
 
2872
                % (self.cmd_name, self.plugin_metadata['name'],
 
2873
                    self.plugin_metadata['url']))
 
2874
 
 
2875
        return _fmt
 
2876
 
 
2877
 
 
2878
class NoPluginAvailable(BzrError):
 
2879
    pass
 
2880
 
 
2881
 
 
2882
class UnableEncodePath(BzrError):
 
2883
 
 
2884
    _fmt = ('Unable to encode %(kind)s path %(path)r in '
 
2885
            'user encoding %(user_encoding)s')
 
2886
 
 
2887
    def __init__(self, path, kind):
 
2888
        from bzrlib.osutils import get_user_encoding
 
2889
        self.path = path
 
2890
        self.kind = kind
 
2891
        self.user_encoding = osutils.get_user_encoding()
 
2892
 
 
2893
 
 
2894
class NoSuchAlias(BzrError):
 
2895
 
 
2896
    _fmt = ('The alias "%(alias_name)s" does not exist.')
 
2897
 
 
2898
    def __init__(self, alias_name):
 
2899
        BzrError.__init__(self, alias_name=alias_name)
 
2900
 
 
2901
 
 
2902
class DirectoryLookupFailure(BzrError):
 
2903
    """Base type for lookup errors."""
 
2904
 
 
2905
    pass
 
2906
 
 
2907
 
 
2908
class InvalidLocationAlias(DirectoryLookupFailure):
 
2909
 
 
2910
    _fmt = '"%(alias_name)s" is not a valid location alias.'
 
2911
 
 
2912
    def __init__(self, alias_name):
 
2913
        DirectoryLookupFailure.__init__(self, alias_name=alias_name)
 
2914
 
 
2915
 
 
2916
class UnsetLocationAlias(DirectoryLookupFailure):
 
2917
 
 
2918
    _fmt = 'No %(alias_name)s location assigned.'
 
2919
 
 
2920
    def __init__(self, alias_name):
 
2921
        DirectoryLookupFailure.__init__(self, alias_name=alias_name[1:])
 
2922
 
 
2923
 
 
2924
class CannotBindAddress(BzrError):
 
2925
 
 
2926
    _fmt = 'Cannot bind address "%(host)s:%(port)i": %(orig_error)s.'
 
2927
 
 
2928
    def __init__(self, host, port, orig_error):
 
2929
        # nb: in python2.4 socket.error doesn't have a useful repr
 
2930
        BzrError.__init__(self, host=host, port=port,
 
2931
            orig_error=repr(orig_error.args))
 
2932
 
 
2933
 
 
2934
class UnknownRules(BzrError):
 
2935
 
 
2936
    _fmt = ('Unknown rules detected: %(unknowns_str)s.')
 
2937
 
 
2938
    def __init__(self, unknowns):
 
2939
        BzrError.__init__(self, unknowns_str=", ".join(unknowns))
 
2940
 
 
2941
 
 
2942
class HookFailed(BzrError):
 
2943
    """Raised when a pre_change_branch_tip hook function fails anything other
 
2944
    than TipChangeRejected.
 
2945
    """
 
2946
 
 
2947
    _fmt = ("Hook '%(hook_name)s' during %(hook_stage)s failed:\n"
 
2948
            "%(traceback_text)s%(exc_value)s")
 
2949
 
 
2950
    def __init__(self, hook_stage, hook_name, exc_info):
 
2951
        import traceback
 
2952
        self.hook_stage = hook_stage
 
2953
        self.hook_name = hook_name
 
2954
        self.exc_info = exc_info
 
2955
        self.exc_type = exc_info[0]
 
2956
        self.exc_value = exc_info[1]
 
2957
        self.exc_tb = exc_info[2]
 
2958
        self.traceback_text = ''.join(traceback.format_tb(self.exc_tb))
 
2959
 
 
2960
 
 
2961
class TipChangeRejected(BzrError):
 
2962
    """A pre_change_branch_tip hook function may raise this to cleanly and
 
2963
    explicitly abort a change to a branch tip.
 
2964
    """
 
2965
 
 
2966
    _fmt = u"Tip change rejected: %(msg)s"
 
2967
 
 
2968
    def __init__(self, msg):
 
2969
        self.msg = msg
 
2970
 
 
2971
 
 
2972
class ShelfCorrupt(BzrError):
 
2973
 
 
2974
    _fmt = "Shelf corrupt."
 
2975
 
 
2976
 
 
2977
class NoSuchShelfId(BzrError):
 
2978
 
 
2979
    _fmt = 'No changes are shelved with id "%(shelf_id)d".'
 
2980
 
 
2981
    def __init__(self, shelf_id):
 
2982
        BzrError.__init__(self, shelf_id=shelf_id)
 
2983
 
 
2984
 
 
2985
class InvalidShelfId(BzrError):
 
2986
 
 
2987
    _fmt = '"%(invalid_id)s" is not a valid shelf id, try a number instead.'
 
2988
 
 
2989
    def __init__(self, invalid_id):
 
2990
        BzrError.__init__(self, invalid_id=invalid_id)
 
2991
 
 
2992
 
 
2993
class JailBreak(BzrError):
 
2994
 
 
2995
    _fmt = "An attempt to access a url outside the server jail was made: '%(url)s'."
 
2996
 
 
2997
    def __init__(self, url):
 
2998
        BzrError.__init__(self, url=url)
 
2999
 
 
3000
 
 
3001
class UserAbort(BzrError):
 
3002
 
 
3003
    _fmt = 'The user aborted the operation.'
 
3004
 
 
3005
 
 
3006
class MustHaveWorkingTree(BzrError):
 
3007
 
 
3008
    _fmt = ("Branching '%(url)s'(%(format)s) must create a working tree.")
 
3009
 
 
3010
    def __init__(self, format, url):
 
3011
        BzrError.__init__(self, format=format, url=url)
 
3012
 
 
3013
 
 
3014
class NoSuchView(BzrError):
 
3015
    """A view does not exist.
 
3016
    """
 
3017
 
 
3018
    _fmt = u"No such view: %(view_name)s."
 
3019
 
 
3020
    def __init__(self, view_name):
 
3021
        self.view_name = view_name
 
3022
 
 
3023
 
 
3024
class ViewsNotSupported(BzrError):
 
3025
    """Views are not supported by a tree format.
 
3026
    """
 
3027
 
 
3028
    _fmt = ("Views are not supported by %(tree)s;"
 
3029
            " use 'bzr upgrade' to change your tree to a later format.")
 
3030
 
 
3031
    def __init__(self, tree):
 
3032
        self.tree = tree
 
3033
 
 
3034
 
 
3035
class FileOutsideView(BzrError):
 
3036
 
 
3037
    _fmt = ('Specified file "%(file_name)s" is outside the current view: '
 
3038
            '%(view_str)s')
 
3039
 
 
3040
    def __init__(self, file_name, view_files):
 
3041
        self.file_name = file_name
 
3042
        self.view_str = ", ".join(view_files)
 
3043
 
 
3044
 
 
3045
class UnresumableWriteGroup(BzrError):
 
3046
 
 
3047
    _fmt = ("Repository %(repository)s cannot resume write group "
 
3048
            "%(write_groups)r: %(reason)s")
 
3049
 
 
3050
    internal_error = True
 
3051
 
 
3052
    def __init__(self, repository, write_groups, reason):
 
3053
        self.repository = repository
 
3054
        self.write_groups = write_groups
 
3055
        self.reason = reason
 
3056
 
 
3057
 
 
3058
class UnsuspendableWriteGroup(BzrError):
 
3059
 
 
3060
    _fmt = ("Repository %(repository)s cannot suspend a write group.")
 
3061
 
 
3062
    internal_error = True
 
3063
 
 
3064
    def __init__(self, repository):
 
3065
        self.repository = repository
 
3066
 
 
3067
 
 
3068
class LossyPushToSameVCS(BzrError):
 
3069
 
 
3070
    _fmt = ("Lossy push not possible between %(source_branch)r and "
 
3071
            "%(target_branch)r that are in the same VCS.")
 
3072
 
 
3073
    internal_error = True
 
3074
 
 
3075
    def __init__(self, source_branch, target_branch):
 
3076
        self.source_branch = source_branch
 
3077
        self.target_branch = target_branch