/brz/remove-bazaar

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

« back to all changes in this revision

Viewing changes to brzlib/errors.py

  • Committer: Jelmer Vernooij
  • Date: 2017-05-21 12:41:27 UTC
  • mto: This revision was merged to the branch mainline in revision 6623.
  • Revision ID: jelmer@jelmer.uk-20170521124127-iv8etg0vwymyai6y
s/bzr/brz/ in apport config.

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
"""Exceptions for bzr, and reporting of them.
18
18
"""
19
19
 
 
20
from __future__ import absolute_import
20
21
 
21
22
# TODO: is there any value in providing the .args field used by standard
22
23
# python exceptions?   A list of values with no names seems less useful
31
32
# 'unprintable'.
32
33
 
33
34
 
34
 
# return codes from the brz program
 
35
# return codes from the bzr program
35
36
EXIT_OK = 0
36
37
EXIT_ERROR = 3
37
38
EXIT_INTERNAL_ERROR = 4
38
39
 
39
40
 
40
 
class BzrError(Exception):
 
41
class BzrError(StandardError):
41
42
    """
42
 
    Base class for errors raised by breezy.
 
43
    Base class for errors raised by brzlib.
43
44
 
44
 
    :cvar internal_error: if True this was probably caused by a brz bug and
 
45
    :cvar internal_error: if True this was probably caused by a bzr bug and
45
46
        should be displayed with a traceback; if False (or absent) this was
46
47
        probably a user or environment error and they don't need the gory
47
48
        details.  (That can be overridden by -Derror on the command line.)
71
72
           not subject to expansion. 'msg' is used instead of 'message' because
72
73
           python evolved and, in 2.6, forbids the use of 'message'.
73
74
        """
74
 
        Exception.__init__(self)
 
75
        StandardError.__init__(self)
75
76
        if msg is not None:
76
77
            # I was going to deprecate this, but it actually turns out to be
77
78
            # quite handy - mbp 20061103.
86
87
        if s is not None:
87
88
            # contains a preformatted message
88
89
            return s
89
 
        err = None
90
90
        try:
91
91
            fmt = self._get_format_string()
92
92
            if fmt:
95
95
                # __str__() should always return a 'str' object
96
96
                # never a 'unicode' object.
97
97
                return s
98
 
        except Exception as e:
99
 
            err = e
 
98
        except Exception, e:
 
99
            pass # just bind to 'e' for formatting below
 
100
        else:
 
101
            e = None
100
102
        return 'Unprintable exception %s: dict=%r, fmt=%r, error=%r' \
101
103
            % (self.__class__.__name__,
102
104
               self.__dict__,
103
105
               getattr(self, '_fmt', None),
104
 
               err)
105
 
 
106
 
    __str__ = _format
 
106
               e)
 
107
 
 
108
    def __unicode__(self):
 
109
        u = self._format()
 
110
        if isinstance(u, str):
 
111
            # Try decoding the str using the default encoding.
 
112
            u = unicode(u)
 
113
        elif not isinstance(u, unicode):
 
114
            # Try to make a unicode object from it, because __unicode__ must
 
115
            # return a unicode object.
 
116
            u = unicode(u)
 
117
        return u
 
118
 
 
119
    def __str__(self):
 
120
        s = self._format()
 
121
        if isinstance(s, unicode):
 
122
            s = s.encode('utf8')
 
123
        else:
 
124
            # __str__ must return a str.
 
125
            s = str(s)
 
126
        return s
107
127
 
108
128
    def __repr__(self):
109
129
        return '%s(%s)' % (self.__class__.__name__, str(self))
112
132
        """Return format string for this exception or None"""
113
133
        fmt = getattr(self, '_fmt', None)
114
134
        if fmt is not None:
115
 
            from breezy.i18n import gettext
116
 
            return gettext(fmt)  # _fmt strings should be ascii
 
135
            from brzlib.i18n import gettext
 
136
            return gettext(unicode(fmt)) # _fmt strings should be ascii
117
137
 
118
138
    def __eq__(self, other):
119
139
        if self.__class__ is not other.__class__:
120
140
            return NotImplemented
121
141
        return self.__dict__ == other.__dict__
122
142
 
123
 
    def __hash__(self):
124
 
        return id(self)
125
 
 
126
143
 
127
144
class InternalBzrError(BzrError):
128
145
    """Base class for errors that are internal in nature.
135
152
    internal_error = True
136
153
 
137
154
 
 
155
class AlreadyBuilding(BzrError):
 
156
 
 
157
    _fmt = "The tree builder is already building a tree."
 
158
 
 
159
 
138
160
class BranchError(BzrError):
139
161
    """Base class for concrete 'errors about a branch'."""
140
162
 
151
173
        self.msg = msg
152
174
 
153
175
 
154
 
class IncompatibleVersion(BzrError):
155
 
 
156
 
    _fmt = 'API %(api)s is not compatible; one of versions %(wanted)r '\
157
 
           'is required, but current version is %(current)r.'
158
 
 
159
 
    def __init__(self, api, wanted, current):
 
176
class DirstateCorrupt(BzrError):
 
177
 
 
178
    _fmt = "The dirstate file (%(state)s) appears to be corrupt: %(msg)s"
 
179
 
 
180
    def __init__(self, state, msg):
 
181
        BzrError.__init__(self)
 
182
        self.state = state
 
183
        self.msg = msg
 
184
 
 
185
 
 
186
class DisabledMethod(InternalBzrError):
 
187
 
 
188
    _fmt = "The smart server method '%(class_name)s' is disabled."
 
189
 
 
190
    def __init__(self, class_name):
 
191
        BzrError.__init__(self)
 
192
        self.class_name = class_name
 
193
 
 
194
 
 
195
class IncompatibleAPI(BzrError):
 
196
 
 
197
    _fmt = 'The API for "%(api)s" is not compatible with "%(wanted)s". '\
 
198
        'It supports versions "%(minimum)s" to "%(current)s".'
 
199
 
 
200
    def __init__(self, api, wanted, minimum, current):
160
201
        self.api = api
161
202
        self.wanted = wanted
 
203
        self.minimum = minimum
162
204
        self.current = current
163
205
 
164
206
 
171
213
        self.transport = transport
172
214
 
173
215
 
 
216
class InvalidEntryName(InternalBzrError):
 
217
 
 
218
    _fmt = "Invalid entry name: %(name)s"
 
219
 
 
220
    def __init__(self, name):
 
221
        BzrError.__init__(self)
 
222
        self.name = name
 
223
 
 
224
 
174
225
class InvalidRevisionNumber(BzrError):
175
226
 
176
227
    _fmt = "Invalid revision number %(revno)s"
202
253
class RootMissing(InternalBzrError):
203
254
 
204
255
    _fmt = ("The root entry of a tree must be the first entry supplied to "
205
 
            "the commit builder.")
 
256
        "the commit builder.")
206
257
 
207
258
 
208
259
class NoPublicBranch(BzrError):
210
261
    _fmt = 'There is no public branch set for "%(branch_url)s".'
211
262
 
212
263
    def __init__(self, branch):
213
 
        from . import urlutils
 
264
        import brzlib.urlutils as urlutils
214
265
        public_location = urlutils.unescape_for_display(branch.base, 'ascii')
215
266
        BzrError.__init__(self, branch_url=public_location)
216
267
 
217
268
 
 
269
class NoHelpTopic(BzrError):
 
270
 
 
271
    _fmt = ("No help could be found for '%(topic)s'. "
 
272
        "Please use 'bzr help topics' to obtain a list of topics.")
 
273
 
 
274
    def __init__(self, topic):
 
275
        self.topic = topic
 
276
 
 
277
 
218
278
class NoSuchId(BzrError):
219
279
 
220
280
    _fmt = 'The file id "%(file_id)s" is not present in the tree %(tree)s.'
225
285
        self.tree = tree
226
286
 
227
287
 
 
288
class NoSuchIdInRepository(NoSuchId):
 
289
 
 
290
    _fmt = ('The file id "%(file_id)s" is not present in the repository'
 
291
            ' %(repository)r')
 
292
 
 
293
    def __init__(self, repository, file_id):
 
294
        BzrError.__init__(self, repository=repository, file_id=file_id)
 
295
 
 
296
 
228
297
class NotStacked(BranchError):
229
298
 
230
299
    _fmt = "The branch '%(branch)s' is not stacked."
248
317
        self.base = base
249
318
 
250
319
 
 
320
class NotBuilding(BzrError):
 
321
 
 
322
    _fmt = "Not currently building a tree."
 
323
 
 
324
 
251
325
class NotLocalUrl(BzrError):
252
326
 
253
327
    _fmt = "%(url)s is not a local path."
264
338
        self.base = base
265
339
 
266
340
 
267
 
class NoWhoami(BzrError):
268
 
 
269
 
    _fmt = ('Unable to determine your name.\n'
270
 
            "Please, set your name with the 'whoami' command.\n"
271
 
            'E.g. brz whoami "Your Name <name@example.com>"')
272
 
 
273
 
 
274
341
class BzrCommandError(BzrError):
275
342
    """Error from user command"""
276
343
 
291
358
        self.not_locked = not_locked
292
359
 
293
360
 
 
361
class BzrOptionError(BzrCommandError):
 
362
 
 
363
    _fmt = "Error in command line options"
 
364
 
 
365
 
 
366
class BadIndexFormatSignature(BzrError):
 
367
 
 
368
    _fmt = "%(value)s is not an index of type %(_type)s."
 
369
 
 
370
    def __init__(self, value, _type):
 
371
        BzrError.__init__(self)
 
372
        self.value = value
 
373
        self._type = _type
 
374
 
 
375
 
 
376
class BadIndexData(BzrError):
 
377
 
 
378
    _fmt = "Error in data for index %(value)s."
 
379
 
 
380
    def __init__(self, value):
 
381
        BzrError.__init__(self)
 
382
        self.value = value
 
383
 
 
384
 
 
385
class BadIndexDuplicateKey(BzrError):
 
386
 
 
387
    _fmt = "The key '%(key)s' is already in index '%(index)s'."
 
388
 
 
389
    def __init__(self, key, index):
 
390
        BzrError.__init__(self)
 
391
        self.key = key
 
392
        self.index = index
 
393
 
 
394
 
 
395
class BadIndexKey(BzrError):
 
396
 
 
397
    _fmt = "The key '%(key)s' is not a valid key."
 
398
 
 
399
    def __init__(self, key):
 
400
        BzrError.__init__(self)
 
401
        self.key = key
 
402
 
 
403
 
 
404
class BadIndexOptions(BzrError):
 
405
 
 
406
    _fmt = "Could not parse options for index %(value)s."
 
407
 
 
408
    def __init__(self, value):
 
409
        BzrError.__init__(self)
 
410
        self.value = value
 
411
 
 
412
 
 
413
class BadIndexValue(BzrError):
 
414
 
 
415
    _fmt = "The value '%(value)s' is not a valid value."
 
416
 
 
417
    def __init__(self, value):
 
418
        BzrError.__init__(self)
 
419
        self.value = value
 
420
 
 
421
 
 
422
class BadOptionValue(BzrError):
 
423
 
 
424
    _fmt = """Bad value "%(value)s" for option "%(name)s"."""
 
425
 
 
426
    def __init__(self, name, value):
 
427
        BzrError.__init__(self, name=name, value=value)
 
428
 
 
429
 
294
430
class StrictCommitFailed(BzrError):
295
431
 
296
432
    _fmt = "Commit refused because there are unknown files in the tree"
329
465
    """Used when renaming and both source and dest exist."""
330
466
 
331
467
    _fmt = ("Could not rename %(source)s => %(dest)s because both files exist."
332
 
            " (Use --after to tell brz about a rename that has already"
 
468
            " (Use --after to tell bzr about a rename that has already"
333
469
            " happened)%(extra)s")
334
470
 
335
471
    def __init__(self, source, dest, extra=None):
382
518
    _fmt = 'Permission denied: "%(path)s"%(extra)s'
383
519
 
384
520
 
 
521
class InvalidURL(PathError):
 
522
 
 
523
    _fmt = 'Invalid url supplied to transport: "%(path)s"%(extra)s'
 
524
 
 
525
 
 
526
class InvalidURLJoin(PathError):
 
527
 
 
528
    _fmt = "Invalid URL join request: %(reason)s: %(base)r + %(join_args)r"
 
529
 
 
530
    def __init__(self, reason, base, join_args):
 
531
        self.reason = reason
 
532
        self.base = base
 
533
        self.join_args = join_args
 
534
        PathError.__init__(self, base, reason)
 
535
 
 
536
 
 
537
class InvalidRebaseURLs(PathError):
 
538
 
 
539
    _fmt = "URLs differ by more than path: %(from_)r and %(to)r"
 
540
 
 
541
    def __init__(self, from_, to):
 
542
        self.from_ = from_
 
543
        self.to = to
 
544
        PathError.__init__(self, from_, 'URLs differ by more than path.')
 
545
 
 
546
 
385
547
class UnavailableRepresentation(InternalBzrError):
386
548
 
387
549
    _fmt = ("The encoding '%(wanted)s' is not available for key %(key)s which "
388
 
            "is encoded as '%(native)s'.")
 
550
        "is encoded as '%(native)s'.")
389
551
 
390
552
    def __init__(self, key, wanted, native):
391
553
        InternalBzrError.__init__(self)
394
556
        self.key = key
395
557
 
396
558
 
 
559
class UnknownHook(BzrError):
 
560
 
 
561
    _fmt = "The %(type)s hook '%(hook)s' is unknown in this version of brzlib."
 
562
 
 
563
    def __init__(self, hook_type, hook_name):
 
564
        BzrError.__init__(self)
 
565
        self.type = hook_type
 
566
        self.hook = hook_name
 
567
 
 
568
 
397
569
class UnsupportedProtocol(PathError):
398
570
 
399
571
    _fmt = 'Unsupported protocol for url "%(path)s"%(extra)s'
402
574
        PathError.__init__(self, url, extra=extra)
403
575
 
404
576
 
 
577
class UnstackableBranchFormat(BzrError):
 
578
 
 
579
    _fmt = ("The branch '%(url)s'(%(format)s) is not a stackable format. "
 
580
        "You will need to upgrade the branch to permit branch stacking.")
 
581
 
 
582
    def __init__(self, format, url):
 
583
        BzrError.__init__(self)
 
584
        self.format = format
 
585
        self.url = url
 
586
 
 
587
 
405
588
class UnstackableLocationError(BzrError):
406
589
 
407
590
    _fmt = "The branch '%(branch_url)s' cannot be stacked on '%(target_url)s'."
415
598
class UnstackableRepositoryFormat(BzrError):
416
599
 
417
600
    _fmt = ("The repository '%(url)s'(%(format)s) is not a stackable format. "
418
 
            "You will need to upgrade the repository to permit branch stacking.")
 
601
        "You will need to upgrade the repository to permit branch stacking.")
419
602
 
420
603
    def __init__(self, format, url):
421
604
        BzrError.__init__(self)
470
653
 
471
654
    _fmt = 'Not a branch: "%(path)s"%(detail)s.'
472
655
 
473
 
    def __init__(self, path, detail=None, controldir=None):
474
 
        from . import urlutils
475
 
        path = urlutils.unescape_for_display(path, 'ascii')
476
 
        if detail is not None:
477
 
            detail = ': ' + detail
478
 
        self.detail = detail
479
 
        self.controldir = controldir
480
 
        PathError.__init__(self, path=path)
 
656
    def __init__(self, path, detail=None, bzrdir=None):
 
657
       import brzlib.urlutils as urlutils
 
658
       path = urlutils.unescape_for_display(path, 'ascii')
 
659
       if detail is not None:
 
660
           detail = ': ' + detail
 
661
       self.detail = detail
 
662
       self.bzrdir = bzrdir
 
663
       PathError.__init__(self, path=path)
481
664
 
482
665
    def __repr__(self):
483
666
        return '<%s %r>' % (self.__class__.__name__, self.__dict__)
484
667
 
485
 
    def _get_format_string(self):
486
 
        # GZ 2017-06-08: Not the best place to lazy fill detail in.
 
668
    def _format(self):
 
669
        # XXX: Ideally self.detail would be a property, but Exceptions in
 
670
        # Python 2.4 have to be old-style classes so properties don't work.
 
671
        # Instead we override _format.
487
672
        if self.detail is None:
488
 
            self.detail = self._get_detail()
489
 
        return super(NotBranchError, self)._get_format_string()
490
 
 
491
 
    def _get_detail(self):
492
 
        if self.controldir is not None:
493
 
            try:
494
 
                self.controldir.open_repository()
495
 
            except NoRepositoryPresent:
496
 
                return ''
497
 
            except Exception as e:
498
 
                # Just ignore unexpected errors.  Raising arbitrary errors
499
 
                # during str(err) can provoke strange bugs.  Concretely
500
 
                # Launchpad's codehosting managed to raise NotBranchError
501
 
                # here, and then get stuck in an infinite loop/recursion
502
 
                # trying to str() that error.  All this error really cares
503
 
                # about that there's no working repository there, and if
504
 
                # open_repository() fails, there probably isn't.
505
 
                return ': ' + e.__class__.__name__
 
673
            if self.bzrdir is not None:
 
674
                try:
 
675
                    self.bzrdir.open_repository()
 
676
                except NoRepositoryPresent:
 
677
                    self.detail = ''
 
678
                except Exception:
 
679
                    # Just ignore unexpected errors.  Raising arbitrary errors
 
680
                    # during str(err) can provoke strange bugs.  Concretely
 
681
                    # Launchpad's codehosting managed to raise NotBranchError
 
682
                    # here, and then get stuck in an infinite loop/recursion
 
683
                    # trying to str() that error.  All this error really cares
 
684
                    # about that there's no working repository there, and if
 
685
                    # open_repository() fails, there probably isn't.
 
686
                    self.detail = ''
 
687
                else:
 
688
                    self.detail = ': location is a repository'
506
689
            else:
507
 
                return ': location is a repository'
508
 
        return ''
 
690
                self.detail = ''
 
691
        return PathError._format(self)
509
692
 
510
693
 
511
694
class NoSubmitBranch(PathError):
513
696
    _fmt = 'No submit branch available for branch "%(path)s"'
514
697
 
515
698
    def __init__(self, branch):
516
 
        from . import urlutils
517
 
        self.path = urlutils.unescape_for_display(branch.base, 'ascii')
 
699
       import brzlib.urlutils as urlutils
 
700
       self.path = urlutils.unescape_for_display(branch.base, 'ascii')
518
701
 
519
702
 
520
703
class AlreadyControlDirError(PathError):
544
727
class BranchExistsWithoutWorkingTree(PathError):
545
728
 
546
729
    _fmt = 'Directory contains a branch, but no working tree \
547
 
(use brz checkout if you wish to build a working tree): "%(path)s"'
 
730
(use bzr checkout if you wish to build a working tree): "%(path)s"'
 
731
 
 
732
 
 
733
class AtomicFileAlreadyClosed(PathError):
 
734
 
 
735
    _fmt = ('"%(function)s" called on an AtomicFile after it was closed:'
 
736
            ' "%(path)s"')
 
737
 
 
738
    def __init__(self, path, function):
 
739
        PathError.__init__(self, path=path, extra=None)
 
740
        self.function = function
548
741
 
549
742
 
550
743
class InaccessibleParent(PathError):
560
753
class NoRepositoryPresent(BzrError):
561
754
 
562
755
    _fmt = 'No repository present: "%(path)s"'
563
 
 
564
 
    def __init__(self, controldir):
 
756
    def __init__(self, bzrdir):
565
757
        BzrError.__init__(self)
566
 
        self.path = controldir.transport.clone('..').base
 
758
        self.path = bzrdir.transport.clone('..').base
567
759
 
568
760
 
569
761
class UnsupportedFormatError(BzrError):
570
762
 
571
 
    _fmt = "Unsupported branch format: %(format)s\nPlease run 'brz upgrade'"
 
763
    _fmt = "Unsupported branch format: %(format)s\nPlease run 'bzr upgrade'"
572
764
 
573
765
 
574
766
class UnknownFormatError(BzrError):
580
772
        self.format = format
581
773
 
582
774
 
583
 
class LineEndingError(BzrError):
584
 
 
585
 
    _fmt = ("Line ending corrupted for file: %(file)s; "
586
 
            "Maybe your files got corrupted in transport?")
587
 
 
588
 
    def __init__(self, file):
589
 
        self.file = file
590
 
 
591
 
 
592
775
class IncompatibleFormat(BzrError):
593
776
 
594
 
    _fmt = "Format %(format)s is not compatible with .bzr version %(controldir)s."
 
777
    _fmt = "Format %(format)s is not compatible with .bzr version %(bzrdir)s."
595
778
 
596
 
    def __init__(self, format, controldir_format):
 
779
    def __init__(self, format, bzrdir_format):
597
780
        BzrError.__init__(self)
598
781
        self.format = format
599
 
        self.controldir = controldir_format
 
782
        self.bzrdir = bzrdir_format
600
783
 
601
784
 
602
785
class ParseFormatError(BzrError):
620
803
    """
621
804
 
622
805
    _fmt = "%(target)s\n" \
623
 
        "is not compatible with\n" \
624
 
        "%(source)s\n" \
625
 
        "%(details)s"
 
806
            "is not compatible with\n" \
 
807
            "%(source)s\n" \
 
808
            "%(details)s"
626
809
 
627
810
    def __init__(self, source, target, details=None):
628
811
        if details is None:
687
870
    _fmt = "Path(s) are not versioned: %(paths_as_string)s"
688
871
 
689
872
    def __init__(self, paths):
690
 
        from breezy.osutils import quotefn
 
873
        from brzlib.osutils import quotefn
691
874
        BzrError.__init__(self)
692
875
        self.paths = paths
693
876
        self.paths_as_string = ' '.join([quotefn(p) for p in paths])
702
885
 
703
886
    def __init__(self, paths, extra=None):
704
887
        # circular import
705
 
        from breezy.osutils import quotefn
 
888
        from brzlib.osutils import quotefn
706
889
        BzrError.__init__(self)
707
890
        self.paths = paths
708
891
        self.paths_as_string = ' '.join([quotefn(p) for p in paths])
871
1054
class LockCorrupt(LockError):
872
1055
 
873
1056
    _fmt = ("Lock is apparently held, but corrupted: %(corruption_info)s\n"
874
 
            "Use 'brz break-lock' to clear it")
 
1057
            "Use 'bzr break-lock' to clear it")
875
1058
 
876
1059
    internal_error = False
877
1060
 
909
1092
        self.lock_token = lock_token
910
1093
 
911
1094
 
 
1095
class PointlessCommit(BzrError):
 
1096
 
 
1097
    _fmt = "No changes to commit"
 
1098
 
 
1099
 
 
1100
class CannotCommitSelectedFileMerge(BzrError):
 
1101
 
 
1102
    _fmt = 'Selected-file commit of merges is not supported yet:'\
 
1103
        ' files %(files_str)s'
 
1104
 
 
1105
    def __init__(self, files):
 
1106
        files_str = ', '.join(files)
 
1107
        BzrError.__init__(self, files=files, files_str=files_str)
 
1108
 
 
1109
 
 
1110
class ExcludesUnsupported(BzrError):
 
1111
 
 
1112
    _fmt = ('Excluding paths during commit is not supported by '
 
1113
            'repository at %(repository)r.')
 
1114
 
 
1115
    def __init__(self, repository):
 
1116
        BzrError.__init__(self, repository=repository)
 
1117
 
 
1118
 
 
1119
class BadCommitMessageEncoding(BzrError):
 
1120
 
 
1121
    _fmt = 'The specified commit message contains characters unsupported by '\
 
1122
        'the current encoding.'
 
1123
 
 
1124
 
912
1125
class UpgradeReadonly(BzrError):
913
1126
 
914
1127
    _fmt = "Upgrade URL cannot work with readonly URLs."
923
1136
        self.format = format
924
1137
 
925
1138
 
 
1139
class StrictCommitFailed(Exception):
 
1140
 
 
1141
    _fmt = "Commit refused because there are unknowns in the tree."
 
1142
 
 
1143
 
926
1144
class NoSuchRevision(InternalBzrError):
927
1145
 
928
1146
    _fmt = "%(branch)s has no revision %(revision)s"
973
1191
class AppendRevisionsOnlyViolation(BzrError):
974
1192
 
975
1193
    _fmt = ('Operation denied because it would change the main history,'
976
 
            ' which is not permitted by the append_revisions_only setting on'
977
 
            ' branch "%(location)s".')
 
1194
           ' which is not permitted by the append_revisions_only setting on'
 
1195
           ' branch "%(location)s".')
978
1196
 
979
1197
    def __init__(self, location):
980
 
        import breezy.urlutils as urlutils
981
 
        location = urlutils.unescape_for_display(location, 'ascii')
982
 
        BzrError.__init__(self, location=location)
 
1198
       import brzlib.urlutils as urlutils
 
1199
       location = urlutils.unescape_for_display(location, 'ascii')
 
1200
       BzrError.__init__(self, location=location)
983
1201
 
984
1202
 
985
1203
class DivergedBranches(BzrError):
1025
1243
class NoCommonRoot(BzrError):
1026
1244
 
1027
1245
    _fmt = ("Revisions are not derived from the same root: "
1028
 
            "%(revision_a)s %(revision_b)s.")
 
1246
           "%(revision_a)s %(revision_b)s.")
1029
1247
 
1030
1248
    def __init__(self, revision_a, revision_b):
1031
1249
        BzrError.__init__(self, revision_a=revision_a, revision_b=revision_b)
1037
1255
 
1038
1256
    def __init__(self, rev_id, not_ancestor_id):
1039
1257
        BzrError.__init__(self, rev_id=rev_id,
1040
 
                          not_ancestor_id=not_ancestor_id)
 
1258
            not_ancestor_id=not_ancestor_id)
1041
1259
 
1042
1260
 
1043
1261
class NoCommits(BranchError):
1051
1269
        BzrError.__init__(self, "Store %s is not listable" % store)
1052
1270
 
1053
1271
 
 
1272
 
1054
1273
class UnlistableBranch(BzrError):
1055
1274
 
1056
1275
    def __init__(self, br):
1102
1321
        self.error = error
1103
1322
 
1104
1323
 
 
1324
class WeaveError(BzrError):
 
1325
 
 
1326
    _fmt = "Error in processing weave: %(msg)s"
 
1327
 
 
1328
    def __init__(self, msg=None):
 
1329
        BzrError.__init__(self)
 
1330
        self.msg = msg
 
1331
 
 
1332
 
 
1333
class WeaveRevisionAlreadyPresent(WeaveError):
 
1334
 
 
1335
    _fmt = "Revision {%(revision_id)s} already present in %(weave)s"
 
1336
 
 
1337
    def __init__(self, revision_id, weave):
 
1338
 
 
1339
        WeaveError.__init__(self)
 
1340
        self.revision_id = revision_id
 
1341
        self.weave = weave
 
1342
 
 
1343
 
 
1344
class WeaveRevisionNotPresent(WeaveError):
 
1345
 
 
1346
    _fmt = "Revision {%(revision_id)s} not present in %(weave)s"
 
1347
 
 
1348
    def __init__(self, revision_id, weave):
 
1349
        WeaveError.__init__(self)
 
1350
        self.revision_id = revision_id
 
1351
        self.weave = weave
 
1352
 
 
1353
 
 
1354
class WeaveFormatError(WeaveError):
 
1355
 
 
1356
    _fmt = "Weave invariant violated: %(what)s"
 
1357
 
 
1358
    def __init__(self, what):
 
1359
        WeaveError.__init__(self)
 
1360
        self.what = what
 
1361
 
 
1362
 
 
1363
class WeaveParentMismatch(WeaveError):
 
1364
 
 
1365
    _fmt = "Parents are mismatched between two revisions. %(msg)s"
 
1366
 
 
1367
 
 
1368
class WeaveInvalidChecksum(WeaveError):
 
1369
 
 
1370
    _fmt = "Text did not match its checksum: %(msg)s"
 
1371
 
 
1372
 
 
1373
class WeaveTextDiffers(WeaveError):
 
1374
 
 
1375
    _fmt = ("Weaves differ on text content. Revision:"
 
1376
            " {%(revision_id)s}, %(weave_a)s, %(weave_b)s")
 
1377
 
 
1378
    def __init__(self, revision_id, weave_a, weave_b):
 
1379
        WeaveError.__init__(self)
 
1380
        self.revision_id = revision_id
 
1381
        self.weave_a = weave_a
 
1382
        self.weave_b = weave_b
 
1383
 
 
1384
 
 
1385
class WeaveTextDiffers(WeaveError):
 
1386
 
 
1387
    _fmt = ("Weaves differ on text content. Revision:"
 
1388
            " {%(revision_id)s}, %(weave_a)s, %(weave_b)s")
 
1389
 
 
1390
    def __init__(self, revision_id, weave_a, weave_b):
 
1391
        WeaveError.__init__(self)
 
1392
        self.revision_id = revision_id
 
1393
        self.weave_a = weave_a
 
1394
        self.weave_b = weave_b
 
1395
 
 
1396
 
1105
1397
class VersionedFileError(BzrError):
1106
1398
 
1107
1399
    _fmt = "Versioned file error"
1132
1424
    _fmt = "Text did not match its checksum: %(msg)s"
1133
1425
 
1134
1426
 
 
1427
class KnitError(InternalBzrError):
 
1428
 
 
1429
    _fmt = "Knit error"
 
1430
 
 
1431
 
 
1432
class KnitCorrupt(KnitError):
 
1433
 
 
1434
    _fmt = "Knit %(filename)s corrupt: %(how)s"
 
1435
 
 
1436
    def __init__(self, filename, how):
 
1437
        KnitError.__init__(self)
 
1438
        self.filename = filename
 
1439
        self.how = how
 
1440
 
 
1441
 
 
1442
class SHA1KnitCorrupt(KnitCorrupt):
 
1443
 
 
1444
    _fmt = ("Knit %(filename)s corrupt: sha-1 of reconstructed text does not "
 
1445
        "match expected sha-1. key %(key)s expected sha %(expected)s actual "
 
1446
        "sha %(actual)s")
 
1447
 
 
1448
    def __init__(self, filename, actual, expected, key, content):
 
1449
        KnitError.__init__(self)
 
1450
        self.filename = filename
 
1451
        self.actual = actual
 
1452
        self.expected = expected
 
1453
        self.key = key
 
1454
        self.content = content
 
1455
 
 
1456
 
 
1457
class KnitDataStreamIncompatible(KnitError):
 
1458
    # Not raised anymore, as we can convert data streams.  In future we may
 
1459
    # need it again for more exotic cases, so we're keeping it around for now.
 
1460
 
 
1461
    _fmt = "Cannot insert knit data stream of format \"%(stream_format)s\" into knit of format \"%(target_format)s\"."
 
1462
 
 
1463
    def __init__(self, stream_format, target_format):
 
1464
        self.stream_format = stream_format
 
1465
        self.target_format = target_format
 
1466
 
 
1467
 
 
1468
class KnitDataStreamUnknown(KnitError):
 
1469
    # Indicates a data stream we don't know how to handle.
 
1470
 
 
1471
    _fmt = "Cannot parse knit data stream of format \"%(stream_format)s\"."
 
1472
 
 
1473
    def __init__(self, stream_format):
 
1474
        self.stream_format = stream_format
 
1475
 
 
1476
 
 
1477
class KnitHeaderError(KnitError):
 
1478
 
 
1479
    _fmt = 'Knit header error: %(badline)r unexpected for file "%(filename)s".'
 
1480
 
 
1481
    def __init__(self, badline, filename):
 
1482
        KnitError.__init__(self)
 
1483
        self.badline = badline
 
1484
        self.filename = filename
 
1485
 
 
1486
class KnitIndexUnknownMethod(KnitError):
 
1487
    """Raised when we don't understand the storage method.
 
1488
 
 
1489
    Currently only 'fulltext' and 'line-delta' are supported.
 
1490
    """
 
1491
 
 
1492
    _fmt = ("Knit index %(filename)s does not have a known method"
 
1493
            " in options: %(options)r")
 
1494
 
 
1495
    def __init__(self, filename, options):
 
1496
        KnitError.__init__(self)
 
1497
        self.filename = filename
 
1498
        self.options = options
 
1499
 
 
1500
 
1135
1501
class RetryWithNewPacks(BzrError):
1136
1502
    """Raised when we realize that the packs on disk have changed.
1137
1503
 
1198
1564
        if orig_error is None:
1199
1565
            orig_error = ''
1200
1566
        if msg is None:
1201
 
            msg = ''
 
1567
            msg =  ''
1202
1568
        self.msg = msg
1203
1569
        self.orig_error = orig_error
1204
1570
        BzrError.__init__(self)
1249
1615
        self.exc_type, self.exc_value, self.exc_tb = exc_info
1250
1616
        self.exc_info = exc_info
1251
1617
        traceback_strings = traceback.format_exception(
1252
 
            self.exc_type, self.exc_value, self.exc_tb)
 
1618
                self.exc_type, self.exc_value, self.exc_tb)
1253
1619
        self.traceback_text = ''.join(traceback_strings)
1254
1620
 
1255
1621
 
1375
1741
    _fmt = "Working tree has conflicts."
1376
1742
 
1377
1743
 
 
1744
class ConfigContentError(BzrError):
 
1745
 
 
1746
    _fmt = "Config file %(filename)s is not UTF-8 encoded\n"
 
1747
 
 
1748
    def __init__(self, filename):
 
1749
        BzrError.__init__(self)
 
1750
        self.filename = filename
 
1751
 
 
1752
 
 
1753
class ParseConfigError(BzrError):
 
1754
 
 
1755
    _fmt = "Error(s) parsing config file %(filename)s:\n%(errors)s"
 
1756
 
 
1757
    def __init__(self, errors, filename):
 
1758
        BzrError.__init__(self)
 
1759
        self.filename = filename
 
1760
        self.errors = '\n'.join(e.msg for e in errors)
 
1761
 
 
1762
 
 
1763
class ConfigOptionValueError(BzrError):
 
1764
 
 
1765
    _fmt = ('Bad value "%(value)s" for option "%(name)s".\n'
 
1766
            'See ``bzr help %(name)s``')
 
1767
 
 
1768
    def __init__(self, name, value):
 
1769
        BzrError.__init__(self, name=name, value=value)
 
1770
 
 
1771
 
 
1772
class NoEmailInUsername(BzrError):
 
1773
 
 
1774
    _fmt = "%(username)r does not seem to contain a reasonable email address"
 
1775
 
 
1776
    def __init__(self, username):
 
1777
        BzrError.__init__(self)
 
1778
        self.username = username
 
1779
 
 
1780
 
 
1781
class SigningFailed(BzrError):
 
1782
 
 
1783
    _fmt = 'Failed to GPG sign data with command "%(command_line)s"'
 
1784
 
 
1785
    def __init__(self, command_line):
 
1786
        BzrError.__init__(self, command_line=command_line)
 
1787
 
 
1788
 
 
1789
class SignatureVerificationFailed(BzrError):
 
1790
 
 
1791
    _fmt = 'Failed to verify GPG signature data with error "%(error)s"'
 
1792
 
 
1793
    def __init__(self, error):
 
1794
        BzrError.__init__(self, error=error)
 
1795
 
 
1796
 
1378
1797
class DependencyNotPresent(BzrError):
1379
1798
 
1380
1799
    _fmt = 'Unable to import library "%(library)s": %(error)s'
1383
1802
        BzrError.__init__(self, library=library, error=error)
1384
1803
 
1385
1804
 
 
1805
class GpgmeNotInstalled(DependencyNotPresent):
 
1806
 
 
1807
    _fmt = 'python-gpgme is not installed, it is needed to verify signatures'
 
1808
 
 
1809
    def __init__(self, error):
 
1810
        DependencyNotPresent.__init__(self, 'gpgme', error)
 
1811
 
 
1812
 
1386
1813
class WorkingTreeNotRevision(BzrError):
1387
1814
 
1388
1815
    _fmt = ("The working tree for %(basedir)s has changed since"
1393
1820
        BzrError.__init__(self, basedir=tree.basedir)
1394
1821
 
1395
1822
 
 
1823
class CantReprocessAndShowBase(BzrError):
 
1824
 
 
1825
    _fmt = ("Can't reprocess and show base, because reprocessing obscures "
 
1826
           "the relationship of conflicting lines to the base")
 
1827
 
 
1828
 
1396
1829
class GraphCycleError(BzrError):
1397
1830
 
1398
1831
    _fmt = "Cycle in graph %(graph)r"
1556
1989
class BzrMoveFailedError(BzrError):
1557
1990
 
1558
1991
    _fmt = ("Could not move %(from_path)s%(operator)s %(to_path)s"
1559
 
            "%(_has_extra)s%(extra)s")
 
1992
        "%(_has_extra)s%(extra)s")
1560
1993
 
1561
1994
    def __init__(self, from_path='', to_path='', extra=None):
1562
 
        from breezy.osutils import splitpath
 
1995
        from brzlib.osutils import splitpath
1563
1996
        BzrError.__init__(self)
1564
1997
        if extra:
1565
1998
            self.extra, self._has_extra = extra, ': '
1592
2025
class BzrRenameFailedError(BzrMoveFailedError):
1593
2026
 
1594
2027
    _fmt = ("Could not rename %(from_path)s%(operator)s %(to_path)s"
1595
 
            "%(_has_extra)s%(extra)s")
 
2028
        "%(_has_extra)s%(extra)s")
1596
2029
 
1597
2030
    def __init__(self, from_path, to_path, extra=None):
1598
2031
        BzrMoveFailedError.__init__(self, from_path, to_path, extra)
1634
2067
 
1635
2068
class UninitializableFormat(BzrError):
1636
2069
 
1637
 
    _fmt = "Format %(format)s cannot be initialised by this version of brz."
 
2070
    _fmt = "Format %(format)s cannot be initialised by this version of bzr."
1638
2071
 
1639
2072
    def __init__(self, format):
1640
2073
        BzrError.__init__(self)
1644
2077
class BadConversionTarget(BzrError):
1645
2078
 
1646
2079
    _fmt = "Cannot convert from format %(from_format)s to format %(format)s." \
1647
 
        "    %(problem)s"
 
2080
            "    %(problem)s"
1648
2081
 
1649
2082
    def __init__(self, problem, format, from_format=None):
1650
2083
        BzrError.__init__(self)
1683
2116
 
1684
2117
 
1685
2118
class ExistingContent(BzrError):
1686
 
    # Added in breezy 0.92, used by VersionedFile.add_lines.
 
2119
    # Added in brzlib 0.92, used by VersionedFile.add_lines.
1687
2120
 
1688
2121
    _fmt = "The content being inserted is already present."
1689
2122
 
1695
2128
    keep, and delete it when you are done."""
1696
2129
 
1697
2130
    def __init__(self, limbo_dir):
1698
 
        BzrError.__init__(self)
1699
 
        self.limbo_dir = limbo_dir
 
2131
       BzrError.__init__(self)
 
2132
       self.limbo_dir = limbo_dir
1700
2133
 
1701
2134
 
1702
2135
class ExistingPendingDeletion(BzrError):
1706
2139
    wish to keep, and delete it when you are done."""
1707
2140
 
1708
2141
    def __init__(self, pending_deletion):
1709
 
        BzrError.__init__(self, pending_deletion=pending_deletion)
 
2142
       BzrError.__init__(self, pending_deletion=pending_deletion)
1710
2143
 
1711
2144
 
1712
2145
class ImmortalLimbo(BzrError):
1716
2149
    keep, and delete it when you are done."""
1717
2150
 
1718
2151
    def __init__(self, limbo_dir):
1719
 
        BzrError.__init__(self)
1720
 
        self.limbo_dir = limbo_dir
 
2152
       BzrError.__init__(self)
 
2153
       self.limbo_dir = limbo_dir
1721
2154
 
1722
2155
 
1723
2156
class ImmortalPendingDeletion(BzrError):
1724
2157
 
1725
2158
    _fmt = ("Unable to delete transform temporary directory "
1726
 
            "%(pending_deletion)s.  Please examine %(pending_deletion)s to see if it "
1727
 
            "contains any files you wish to keep, and delete it when you are done.")
 
2159
    "%(pending_deletion)s.  Please examine %(pending_deletion)s to see if it "
 
2160
    "contains any files you wish to keep, and delete it when you are done.")
1728
2161
 
1729
2162
    def __init__(self, pending_deletion):
1730
 
        BzrError.__init__(self, pending_deletion=pending_deletion)
 
2163
       BzrError.__init__(self, pending_deletion=pending_deletion)
1731
2164
 
1732
2165
 
1733
2166
class OutOfDateTree(BzrError):
1734
2167
 
1735
 
    _fmt = "Working tree is out of date, please run 'brz update'.%(more)s"
 
2168
    _fmt = "Working tree is out of date, please run 'bzr update'.%(more)s"
1736
2169
 
1737
2170
    def __init__(self, tree, more=None):
1738
2171
        if more is None:
1750
2183
        '"%(revstring)s".'
1751
2184
 
1752
2185
    def __init__(self, public_location, revstring):
1753
 
        import breezy.urlutils as urlutils
 
2186
        import brzlib.urlutils as urlutils
1754
2187
        public_location = urlutils.unescape_for_display(public_location,
1755
2188
                                                        'ascii')
1756
2189
        BzrError.__init__(self, public_location=public_location,
1767
2200
    _fmt = "Format error in conflict listings"
1768
2201
 
1769
2202
 
 
2203
class CorruptDirstate(BzrError):
 
2204
 
 
2205
    _fmt = ("Inconsistency in dirstate file %(dirstate_path)s.\n"
 
2206
            "Error: %(description)s")
 
2207
 
 
2208
    def __init__(self, dirstate_path, description):
 
2209
        BzrError.__init__(self)
 
2210
        self.dirstate_path = dirstate_path
 
2211
        self.description = description
 
2212
 
 
2213
 
1770
2214
class CorruptRepository(BzrError):
1771
2215
 
1772
2216
    _fmt = ("An error has been detected in the repository %(repo_path)s.\n"
1773
 
            "Please run brz reconcile on this repository.")
 
2217
            "Please run bzr reconcile on this repository.")
1774
2218
 
1775
2219
    def __init__(self, repo):
1776
2220
        BzrError.__init__(self)
1819
2263
class RichRootUpgradeRequired(UpgradeRequired):
1820
2264
 
1821
2265
    _fmt = ("To use this feature you must upgrade your branch at %(path)s to"
1822
 
            " a format which supports rich roots.")
 
2266
           " a format which supports rich roots.")
1823
2267
 
1824
2268
 
1825
2269
class LocalRequiresBoundBranch(BzrError):
1838
2282
        self.tname = type(method_self).__name__
1839
2283
 
1840
2284
 
1841
 
class FetchLimitUnsupported(UnsupportedOperation):
1842
 
 
1843
 
    fmt = ("InterBranch %(interbranch)r does not support fetching limits.")
1844
 
 
1845
 
    def __init__(self, interbranch):
1846
 
        BzrError.__init__(self, interbranch=interbranch)
 
2285
class CannotSetRevisionId(UnsupportedOperation):
 
2286
    """Raised when a commit is attempting to set a revision id but cant."""
1847
2287
 
1848
2288
 
1849
2289
class NonAsciiRevisionId(UnsupportedOperation):
1852
2292
    """
1853
2293
 
1854
2294
 
1855
 
class SharedRepositoriesUnsupported(UnsupportedOperation):
1856
 
    _fmt = "Shared repositories are not supported by %(format)r."
1857
 
 
1858
 
    def __init__(self, format):
1859
 
        BzrError.__init__(self, format=format)
1860
 
 
1861
 
 
1862
2295
class GhostTagsNotSupported(BzrError):
1863
2296
 
1864
2297
    _fmt = "Ghost tags not supported by format %(format)r."
1974
2407
 
1975
2408
class UnknownSSH(BzrError):
1976
2409
 
1977
 
    _fmt = "Unrecognised value for BRZ_SSH environment variable: %(vendor)s"
 
2410
    _fmt = "Unrecognised value for BZR_SSH environment variable: %(vendor)s"
1978
2411
 
1979
2412
    def __init__(self, vendor):
1980
2413
        BzrError.__init__(self)
1984
2417
class SSHVendorNotFound(BzrError):
1985
2418
 
1986
2419
    _fmt = ("Don't know how to handle SSH connections."
1987
 
            " Please set BRZ_SSH environment variable.")
 
2420
            " Please set BZR_SSH environment variable.")
1988
2421
 
1989
2422
 
1990
2423
class GhostRevisionsHaveNoRevno(BzrError):
2007
2440
        self.revision_id = revision_id
2008
2441
 
2009
2442
 
 
2443
class IllegalUseOfScopeReplacer(InternalBzrError):
 
2444
 
 
2445
    _fmt = ("ScopeReplacer object %(name)r was used incorrectly:"
 
2446
            " %(msg)s%(extra)s")
 
2447
 
 
2448
    def __init__(self, name, msg, extra=None):
 
2449
        BzrError.__init__(self)
 
2450
        self.name = name
 
2451
        self.msg = msg
 
2452
        if extra:
 
2453
            self.extra = ': ' + str(extra)
 
2454
        else:
 
2455
            self.extra = ''
 
2456
 
 
2457
 
 
2458
class InvalidImportLine(InternalBzrError):
 
2459
 
 
2460
    _fmt = "Not a valid import statement: %(msg)\n%(text)s"
 
2461
 
 
2462
    def __init__(self, text, msg):
 
2463
        BzrError.__init__(self)
 
2464
        self.text = text
 
2465
        self.msg = msg
 
2466
 
 
2467
 
 
2468
class ImportNameCollision(InternalBzrError):
 
2469
 
 
2470
    _fmt = ("Tried to import an object to the same name as"
 
2471
            " an existing object. %(name)s")
 
2472
 
 
2473
    def __init__(self, name):
 
2474
        BzrError.__init__(self)
 
2475
        self.name = name
 
2476
 
 
2477
 
2010
2478
class NotAMergeDirective(BzrError):
2011
2479
    """File starting with %(firstline)r is not a merge directive"""
2012
 
 
2013
2480
    def __init__(self, firstline):
2014
2481
        BzrError.__init__(self, firstline=firstline)
2015
2482
 
2086
2553
        self.other_tree = other_tree
2087
2554
 
2088
2555
 
 
2556
class BadReferenceTarget(InternalBzrError):
 
2557
 
 
2558
    _fmt = "Can't add reference to %(other_tree)s into %(tree)s." \
 
2559
           "%(reason)s"
 
2560
 
 
2561
    def __init__(self, tree, other_tree, reason):
 
2562
        self.tree = tree
 
2563
        self.other_tree = other_tree
 
2564
        self.reason = reason
 
2565
 
 
2566
 
2089
2567
class NoSuchTag(BzrError):
2090
2568
 
2091
2569
    _fmt = "No such tag: %(tag_name)s"
2097
2575
class TagsNotSupported(BzrError):
2098
2576
 
2099
2577
    _fmt = ("Tags not supported by %(branch)s;"
2100
 
            " you may be able to use 'brz upgrade %(branch_url)s'.")
 
2578
            " you may be able to use bzr upgrade.")
2101
2579
 
2102
2580
    def __init__(self, branch):
2103
2581
        self.branch = branch
2104
 
        self.branch_url = branch.user_url
2105
2582
 
2106
2583
 
2107
2584
class TagAlreadyExists(BzrError):
2112
2589
        self.tag_name = tag_name
2113
2590
 
2114
2591
 
 
2592
class MalformedBugIdentifier(BzrError):
 
2593
 
 
2594
    _fmt = ('Did not understand bug identifier %(bug_id)s: %(reason)s. '
 
2595
            'See "bzr help bugs" for more information on this feature.')
 
2596
 
 
2597
    def __init__(self, bug_id, reason):
 
2598
        self.bug_id = bug_id
 
2599
        self.reason = reason
 
2600
 
 
2601
 
 
2602
class InvalidBugTrackerURL(BzrError):
 
2603
 
 
2604
    _fmt = ("The URL for bug tracker \"%(abbreviation)s\" doesn't "
 
2605
            "contain {id}: %(url)s")
 
2606
 
 
2607
    def __init__(self, abbreviation, url):
 
2608
        self.abbreviation = abbreviation
 
2609
        self.url = url
 
2610
 
 
2611
 
 
2612
class UnknownBugTrackerAbbreviation(BzrError):
 
2613
 
 
2614
    _fmt = ("Cannot find registered bug tracker called %(abbreviation)s "
 
2615
            "on %(branch)s")
 
2616
 
 
2617
    def __init__(self, abbreviation, branch):
 
2618
        self.abbreviation = abbreviation
 
2619
        self.branch = branch
 
2620
 
 
2621
 
 
2622
class InvalidLineInBugsProperty(BzrError):
 
2623
 
 
2624
    _fmt = ("Invalid line in bugs property: '%(line)s'")
 
2625
 
 
2626
    def __init__(self, line):
 
2627
        self.line = line
 
2628
 
 
2629
 
 
2630
class InvalidBugStatus(BzrError):
 
2631
 
 
2632
    _fmt = ("Invalid bug status: '%(status)s'")
 
2633
 
 
2634
    def __init__(self, status):
 
2635
        self.status = status
 
2636
 
 
2637
 
2115
2638
class UnexpectedSmartServerResponse(BzrError):
2116
2639
 
2117
2640
    _fmt = "Could not understand response from smart server: %(response_tuple)r"
2140
2663
 
2141
2664
 
2142
2665
class UnknownErrorFromSmartServer(BzrError):
2143
 
    """An ErrorFromSmartServer could not be translated into a typical breezy
 
2666
    """An ErrorFromSmartServer could not be translated into a typical brzlib
2144
2667
    error.
2145
2668
 
2146
2669
    This is distinct from ErrorFromSmartServer so that it is possible to
2215
2738
        self.name = name.decode("utf-8")
2216
2739
 
2217
2740
 
 
2741
class NoDestinationAddress(InternalBzrError):
 
2742
 
 
2743
    _fmt = "Message does not have a destination address."
 
2744
 
 
2745
 
2218
2746
class RepositoryDataStreamError(BzrError):
2219
2747
 
2220
2748
    _fmt = "Corrupt or incompatible data stream: %(reason)s"
2223
2751
        self.reason = reason
2224
2752
 
2225
2753
 
 
2754
class SMTPError(BzrError):
 
2755
 
 
2756
    _fmt = "SMTP error: %(error)s"
 
2757
 
 
2758
    def __init__(self, error):
 
2759
        self.error = error
 
2760
 
 
2761
 
 
2762
class NoMessageSupplied(BzrError):
 
2763
 
 
2764
    _fmt = "No message supplied."
 
2765
 
 
2766
 
 
2767
class NoMailAddressSpecified(BzrError):
 
2768
 
 
2769
    _fmt = "No mail-to address (--mail-to) or output (-o) specified."
 
2770
 
 
2771
 
 
2772
class MailClientNotFound(BzrError):
 
2773
 
 
2774
    _fmt = "Unable to find mail client with the following names:"\
 
2775
        " %(mail_command_list_string)s"
 
2776
 
 
2777
    def __init__(self, mail_command_list):
 
2778
        mail_command_list_string = ', '.join(mail_command_list)
 
2779
        BzrError.__init__(self, mail_command_list=mail_command_list,
 
2780
                          mail_command_list_string=mail_command_list_string)
 
2781
 
 
2782
class SMTPConnectionRefused(SMTPError):
 
2783
 
 
2784
    _fmt = "SMTP connection to %(host)s refused"
 
2785
 
 
2786
    def __init__(self, error, host):
 
2787
        self.error = error
 
2788
        self.host = host
 
2789
 
 
2790
 
 
2791
class DefaultSMTPConnectionRefused(SMTPConnectionRefused):
 
2792
 
 
2793
    _fmt = "Please specify smtp_server.  No server at default %(host)s."
 
2794
 
 
2795
 
 
2796
class BzrDirError(BzrError):
 
2797
 
 
2798
    def __init__(self, bzrdir):
 
2799
        import brzlib.urlutils as urlutils
 
2800
        display_url = urlutils.unescape_for_display(bzrdir.user_url,
 
2801
                                                    'ascii')
 
2802
        BzrError.__init__(self, bzrdir=bzrdir, display_url=display_url)
 
2803
 
 
2804
 
 
2805
class UnsyncedBranches(BzrDirError):
 
2806
 
 
2807
    _fmt = ("'%(display_url)s' is not in sync with %(target_url)s.  See"
 
2808
            " bzr help sync-for-reconfigure.")
 
2809
 
 
2810
    def __init__(self, bzrdir, target_branch):
 
2811
        BzrDirError.__init__(self, bzrdir)
 
2812
        import brzlib.urlutils as urlutils
 
2813
        self.target_url = urlutils.unescape_for_display(target_branch.base,
 
2814
                                                        'ascii')
 
2815
 
 
2816
 
 
2817
class AlreadyBranch(BzrDirError):
 
2818
 
 
2819
    _fmt = "'%(display_url)s' is already a branch."
 
2820
 
 
2821
 
 
2822
class AlreadyTree(BzrDirError):
 
2823
 
 
2824
    _fmt = "'%(display_url)s' is already a tree."
 
2825
 
 
2826
 
 
2827
class AlreadyCheckout(BzrDirError):
 
2828
 
 
2829
    _fmt = "'%(display_url)s' is already a checkout."
 
2830
 
 
2831
 
 
2832
class AlreadyLightweightCheckout(BzrDirError):
 
2833
 
 
2834
    _fmt = "'%(display_url)s' is already a lightweight checkout."
 
2835
 
 
2836
 
 
2837
class AlreadyUsingShared(BzrDirError):
 
2838
 
 
2839
    _fmt = "'%(display_url)s' is already using a shared repository."
 
2840
 
 
2841
 
 
2842
class AlreadyStandalone(BzrDirError):
 
2843
 
 
2844
    _fmt = "'%(display_url)s' is already standalone."
 
2845
 
 
2846
 
 
2847
class AlreadyWithTrees(BzrDirError):
 
2848
 
 
2849
    _fmt = ("Shared repository '%(display_url)s' already creates "
 
2850
            "working trees.")
 
2851
 
 
2852
 
 
2853
class AlreadyWithNoTrees(BzrDirError):
 
2854
 
 
2855
    _fmt = ("Shared repository '%(display_url)s' already doesn't create "
 
2856
            "working trees.")
 
2857
 
 
2858
 
 
2859
class ReconfigurationNotSupported(BzrDirError):
 
2860
 
 
2861
    _fmt = "Requested reconfiguration of '%(display_url)s' is not supported."
 
2862
 
 
2863
 
 
2864
class NoBindLocation(BzrDirError):
 
2865
 
 
2866
    _fmt = "No location could be found to bind to at %(display_url)s."
 
2867
 
 
2868
 
2226
2869
class UncommittedChanges(BzrError):
2227
2870
 
2228
2871
    _fmt = ('Working tree "%(display_url)s" has uncommitted changes'
2229
 
            ' (See brz status).%(more)s')
 
2872
            ' (See bzr status).%(more)s')
2230
2873
 
2231
2874
    def __init__(self, tree, more=None):
2232
2875
        if more is None:
2233
2876
            more = ''
2234
2877
        else:
2235
2878
            more = ' ' + more
2236
 
        import breezy.urlutils as urlutils
 
2879
        import brzlib.urlutils as urlutils
2237
2880
        user_url = getattr(tree, "user_url", None)
2238
2881
        if user_url is None:
2239
2882
            display_url = str(tree)
2248
2891
            ' changes.')
2249
2892
 
2250
2893
    def __init__(self, branch):
2251
 
        import breezy.urlutils as urlutils
 
2894
        import brzlib.urlutils as urlutils
2252
2895
        user_url = getattr(branch, "user_url", None)
2253
2896
        if user_url is None:
2254
2897
            display_url = str(branch)
2260
2903
class ShelvedChanges(UncommittedChanges):
2261
2904
 
2262
2905
    _fmt = ('Working tree "%(display_url)s" has shelved changes'
2263
 
            ' (See brz shelve --list).%(more)s')
 
2906
            ' (See bzr shelve --list).%(more)s')
 
2907
 
 
2908
 
 
2909
class MissingTemplateVariable(BzrError):
 
2910
 
 
2911
    _fmt = 'Variable {%(name)s} is not available.'
 
2912
 
 
2913
    def __init__(self, name):
 
2914
        self.name = name
 
2915
 
 
2916
 
 
2917
class NoTemplate(BzrError):
 
2918
 
 
2919
    _fmt = 'No template specified.'
 
2920
 
 
2921
 
 
2922
class UnableCreateSymlink(BzrError):
 
2923
 
 
2924
    _fmt = 'Unable to create symlink %(path_str)son this platform'
 
2925
 
 
2926
    def __init__(self, path=None):
 
2927
        path_str = ''
 
2928
        if path:
 
2929
            try:
 
2930
                path_str = repr(str(path))
 
2931
            except UnicodeEncodeError:
 
2932
                path_str = repr(path)
 
2933
            path_str += ' '
 
2934
        self.path_str = path_str
 
2935
 
 
2936
 
 
2937
class UnsupportedTimezoneFormat(BzrError):
 
2938
 
 
2939
    _fmt = ('Unsupported timezone format "%(timezone)s", '
 
2940
            'options are "utc", "original", "local".')
 
2941
 
 
2942
    def __init__(self, timezone):
 
2943
        self.timezone = timezone
 
2944
 
 
2945
 
 
2946
class CommandAvailableInPlugin(StandardError):
 
2947
 
 
2948
    internal_error = False
 
2949
 
 
2950
    def __init__(self, cmd_name, plugin_metadata, provider):
 
2951
 
 
2952
        self.plugin_metadata = plugin_metadata
 
2953
        self.cmd_name = cmd_name
 
2954
        self.provider = provider
 
2955
 
 
2956
    def __str__(self):
 
2957
 
 
2958
        _fmt = ('"%s" is not a standard bzr command. \n'
 
2959
                'However, the following official plugin provides this command: %s\n'
 
2960
                'You can install it by going to: %s'
 
2961
                % (self.cmd_name, self.plugin_metadata['name'],
 
2962
                    self.plugin_metadata['url']))
 
2963
 
 
2964
        return _fmt
 
2965
 
 
2966
 
 
2967
class NoPluginAvailable(BzrError):
 
2968
    pass
2264
2969
 
2265
2970
 
2266
2971
class UnableEncodePath(BzrError):
2269
2974
            'user encoding %(user_encoding)s')
2270
2975
 
2271
2976
    def __init__(self, path, kind):
2272
 
        from breezy.osutils import get_user_encoding
 
2977
        from brzlib.osutils import get_user_encoding
2273
2978
        self.path = path
2274
2979
        self.kind = kind
2275
2980
        self.user_encoding = get_user_encoding()
2276
2981
 
2277
2982
 
 
2983
class NoSuchConfig(BzrError):
 
2984
 
 
2985
    _fmt = ('The "%(config_id)s" configuration does not exist.')
 
2986
 
 
2987
    def __init__(self, config_id):
 
2988
        BzrError.__init__(self, config_id=config_id)
 
2989
 
 
2990
 
 
2991
class NoSuchConfigOption(BzrError):
 
2992
 
 
2993
    _fmt = ('The "%(option_name)s" configuration option does not exist.')
 
2994
 
 
2995
    def __init__(self, option_name):
 
2996
        BzrError.__init__(self, option_name=option_name)
 
2997
 
 
2998
 
2278
2999
class NoSuchAlias(BzrError):
2279
3000
 
2280
3001
    _fmt = ('The alias "%(alias_name)s" does not exist.')
2283
3004
        BzrError.__init__(self, alias_name=alias_name)
2284
3005
 
2285
3006
 
 
3007
class DirectoryLookupFailure(BzrError):
 
3008
    """Base type for lookup errors."""
 
3009
 
 
3010
    pass
 
3011
 
 
3012
 
 
3013
class InvalidLocationAlias(DirectoryLookupFailure):
 
3014
 
 
3015
    _fmt = '"%(alias_name)s" is not a valid location alias.'
 
3016
 
 
3017
    def __init__(self, alias_name):
 
3018
        DirectoryLookupFailure.__init__(self, alias_name=alias_name)
 
3019
 
 
3020
 
 
3021
class UnsetLocationAlias(DirectoryLookupFailure):
 
3022
 
 
3023
    _fmt = 'No %(alias_name)s location assigned.'
 
3024
 
 
3025
    def __init__(self, alias_name):
 
3026
        DirectoryLookupFailure.__init__(self, alias_name=alias_name[1:])
 
3027
 
 
3028
 
2286
3029
class CannotBindAddress(BzrError):
2287
3030
 
2288
3031
    _fmt = 'Cannot bind address "%(host)s:%(port)i": %(orig_error)s.'
2290
3033
    def __init__(self, host, port, orig_error):
2291
3034
        # nb: in python2.4 socket.error doesn't have a useful repr
2292
3035
        BzrError.__init__(self, host=host, port=port,
2293
 
                          orig_error=repr(orig_error.args))
 
3036
            orig_error=repr(orig_error.args))
 
3037
 
 
3038
 
 
3039
class UnknownRules(BzrError):
 
3040
 
 
3041
    _fmt = ('Unknown rules detected: %(unknowns_str)s.')
 
3042
 
 
3043
    def __init__(self, unknowns):
 
3044
        BzrError.__init__(self, unknowns_str=", ".join(unknowns))
2294
3045
 
2295
3046
 
2296
3047
class TipChangeRejected(BzrError):
2304
3055
        self.msg = msg
2305
3056
 
2306
3057
 
 
3058
class ShelfCorrupt(BzrError):
 
3059
 
 
3060
    _fmt = "Shelf corrupt."
 
3061
 
 
3062
 
 
3063
class DecompressCorruption(BzrError):
 
3064
 
 
3065
    _fmt = "Corruption while decompressing repository file%(orig_error)s"
 
3066
 
 
3067
    def __init__(self, orig_error=None):
 
3068
        if orig_error is not None:
 
3069
            self.orig_error = ", %s" % (orig_error,)
 
3070
        else:
 
3071
            self.orig_error = ""
 
3072
        BzrError.__init__(self)
 
3073
 
 
3074
 
 
3075
class NoSuchShelfId(BzrError):
 
3076
 
 
3077
    _fmt = 'No changes are shelved with id "%(shelf_id)d".'
 
3078
 
 
3079
    def __init__(self, shelf_id):
 
3080
        BzrError.__init__(self, shelf_id=shelf_id)
 
3081
 
 
3082
 
 
3083
class InvalidShelfId(BzrError):
 
3084
 
 
3085
    _fmt = '"%(invalid_id)s" is not a valid shelf id, try a number instead.'
 
3086
 
 
3087
    def __init__(self, invalid_id):
 
3088
        BzrError.__init__(self, invalid_id=invalid_id)
 
3089
 
 
3090
 
2307
3091
class JailBreak(BzrError):
2308
3092
 
2309
3093
    _fmt = "An attempt to access a url outside the server jail was made: '%(url)s'."
2317
3101
    _fmt = 'The user aborted the operation.'
2318
3102
 
2319
3103
 
 
3104
class MustHaveWorkingTree(BzrError):
 
3105
 
 
3106
    _fmt = ("Branching '%(url)s'(%(format)s) must create a working tree.")
 
3107
 
 
3108
    def __init__(self, format, url):
 
3109
        BzrError.__init__(self, format=format, url=url)
 
3110
 
 
3111
 
 
3112
class NoSuchView(BzrError):
 
3113
    """A view does not exist.
 
3114
    """
 
3115
 
 
3116
    _fmt = u"No such view: %(view_name)s."
 
3117
 
 
3118
    def __init__(self, view_name):
 
3119
        self.view_name = view_name
 
3120
 
 
3121
 
 
3122
class ViewsNotSupported(BzrError):
 
3123
    """Views are not supported by a tree format.
 
3124
    """
 
3125
 
 
3126
    _fmt = ("Views are not supported by %(tree)s;"
 
3127
            " use 'bzr upgrade' to change your tree to a later format.")
 
3128
 
 
3129
    def __init__(self, tree):
 
3130
        self.tree = tree
 
3131
 
 
3132
 
 
3133
class FileOutsideView(BzrError):
 
3134
 
 
3135
    _fmt = ('Specified file "%(file_name)s" is outside the current view: '
 
3136
            '%(view_str)s')
 
3137
 
 
3138
    def __init__(self, file_name, view_files):
 
3139
        self.file_name = file_name
 
3140
        self.view_str = ", ".join(view_files)
 
3141
 
 
3142
 
2320
3143
class UnresumableWriteGroup(BzrError):
2321
3144
 
2322
3145
    _fmt = ("Repository %(repository)s cannot resume write group "
2364
3187
        self.target_branch = target_branch
2365
3188
 
2366
3189
 
 
3190
class FileTimestampUnavailable(BzrError):
 
3191
 
 
3192
    _fmt = "The filestamp for %(path)s is not available."
 
3193
 
 
3194
    internal_error = True
 
3195
 
 
3196
    def __init__(self, path):
 
3197
        self.path = path
 
3198
 
 
3199
 
2367
3200
class NoColocatedBranchSupport(BzrError):
2368
3201
 
2369
 
    _fmt = ("%(controldir)r does not support co-located branches.")
2370
 
 
2371
 
    def __init__(self, controldir):
2372
 
        self.controldir = controldir
 
3202
    _fmt = ("%(bzrdir)r does not support co-located branches.")
 
3203
 
 
3204
    def __init__(self, bzrdir):
 
3205
        self.bzrdir = bzrdir
 
3206
 
 
3207
 
 
3208
class NoWhoami(BzrError):
 
3209
 
 
3210
    _fmt = ('Unable to determine your name.\n'
 
3211
        "Please, set your name with the 'whoami' command.\n"
 
3212
        'E.g. bzr whoami "Your Name <name@example.com>"')
 
3213
 
 
3214
 
 
3215
class InvalidPattern(BzrError):
 
3216
 
 
3217
    _fmt = ('Invalid pattern(s) found. %(msg)s')
 
3218
 
 
3219
    def __init__(self, msg):
 
3220
        self.msg = msg
2373
3221
 
2374
3222
 
2375
3223
class RecursiveBind(BzrError):
2376
3224
 
2377
3225
    _fmt = ('Branch "%(branch_url)s" appears to be bound to itself. '
2378
 
            'Please use `brz unbind` to fix.')
 
3226
        'Please use `bzr unbind` to fix.')
2379
3227
 
2380
3228
    def __init__(self, branch_url):
2381
3229
        self.branch_url = branch_url
2382
3230
 
2383
3231
 
 
3232
# FIXME: I would prefer to define the config related exception classes in
 
3233
# config.py but the lazy import mechanism proscribes this -- vila 20101222
 
3234
class OptionExpansionLoop(BzrError):
 
3235
 
 
3236
    _fmt = 'Loop involving %(refs)r while expanding "%(string)s".'
 
3237
 
 
3238
    def __init__(self, string, refs):
 
3239
        self.string = string
 
3240
        self.refs = '->'.join(refs)
 
3241
 
 
3242
 
 
3243
class ExpandingUnknownOption(BzrError):
 
3244
 
 
3245
    _fmt = 'Option "%(name)s" is not defined while expanding "%(string)s".'
 
3246
 
 
3247
    def __init__(self, name, string):
 
3248
        self.name = name
 
3249
        self.string = string
 
3250
 
 
3251
 
 
3252
class IllegalOptionName(BzrError):
 
3253
 
 
3254
    _fmt = 'Option "%(name)s" is not allowed.'
 
3255
 
 
3256
    def __init__(self, name):
 
3257
        self.name = name
 
3258
 
 
3259
 
 
3260
class NoCompatibleInter(BzrError):
 
3261
 
 
3262
    _fmt = ('No compatible object available for operations from %(source)r '
 
3263
            'to %(target)r.')
 
3264
 
 
3265
    def __init__(self, source, target):
 
3266
        self.source = source
 
3267
        self.target = target
 
3268
 
 
3269
 
 
3270
class HpssVfsRequestNotAllowed(BzrError):
 
3271
 
 
3272
    _fmt = ("VFS requests over the smart server are not allowed. Encountered: "
 
3273
            "%(method)s, %(arguments)s.")
 
3274
 
 
3275
    def __init__(self, method, arguments):
 
3276
        self.method = method
 
3277
        self.arguments = arguments
 
3278
 
 
3279
 
2384
3280
class UnsupportedKindChange(BzrError):
2385
3281
 
2386
3282
    _fmt = ("Kind change from %(from_kind)s to %(to_kind)s for "
2393
3289
        self.format = format
2394
3290
 
2395
3291
 
 
3292
class MissingFeature(BzrError):
 
3293
 
 
3294
    _fmt = ("Missing feature %(feature)s not provided by this "
 
3295
            "version of Bazaar or any plugin.")
 
3296
 
 
3297
    def __init__(self, feature):
 
3298
        self.feature = feature
 
3299
 
 
3300
 
 
3301
class PatchSyntax(BzrError):
 
3302
    """Base class for patch syntax errors."""
 
3303
 
 
3304
 
 
3305
class BinaryFiles(BzrError):
 
3306
 
 
3307
    _fmt = 'Binary files section encountered.'
 
3308
 
 
3309
    def __init__(self, orig_name, mod_name):
 
3310
        self.orig_name = orig_name
 
3311
        self.mod_name = mod_name
 
3312
 
 
3313
 
 
3314
class MalformedPatchHeader(PatchSyntax):
 
3315
 
 
3316
    _fmt = "Malformed patch header.  %(desc)s\n%(line)r"
 
3317
 
 
3318
    def __init__(self, desc, line):
 
3319
        self.desc = desc
 
3320
        self.line = line
 
3321
 
 
3322
 
 
3323
class MalformedHunkHeader(PatchSyntax):
 
3324
 
 
3325
    _fmt = "Malformed hunk header.  %(desc)s\n%(line)r"
 
3326
 
 
3327
    def __init__(self, desc, line):
 
3328
        self.desc = desc
 
3329
        self.line = line
 
3330
 
 
3331
 
 
3332
class MalformedLine(PatchSyntax):
 
3333
 
 
3334
    _fmt = "Malformed line.  %(desc)s\n%(line)r"
 
3335
 
 
3336
    def __init__(self, desc, line):
 
3337
        self.desc = desc
 
3338
        self.line = line
 
3339
 
 
3340
 
 
3341
class PatchConflict(BzrError):
 
3342
 
 
3343
    _fmt = ('Text contents mismatch at line %(line_no)d.  Original has '
 
3344
            '"%(orig_line)s", but patch says it should be "%(patch_line)s"')
 
3345
 
 
3346
    def __init__(self, line_no, orig_line, patch_line):
 
3347
        self.line_no = line_no
 
3348
        self.orig_line = orig_line.rstrip('\n')
 
3349
        self.patch_line = patch_line.rstrip('\n')
 
3350
 
 
3351
 
 
3352
class FeatureAlreadyRegistered(BzrError):
 
3353
 
 
3354
    _fmt = 'The feature %(feature)s has already been registered.'
 
3355
 
 
3356
    def __init__(self, feature):
 
3357
        self.feature = feature
 
3358
 
 
3359
 
2396
3360
class ChangesAlreadyStored(BzrCommandError):
2397
3361
 
2398
3362
    _fmt = ('Cannot store uncommitted changes because this branch already'
2399
3363
            ' stores uncommitted changes.')
2400
 
 
2401
 
 
2402
 
class RevnoOutOfBounds(InternalBzrError):
2403
 
 
2404
 
    _fmt = ("The requested revision number %(revno)d is outside of the "
2405
 
            "expected boundaries (%(minimum)d <= %(maximum)d).")
2406
 
 
2407
 
    def __init__(self, revno, bounds):
2408
 
        InternalBzrError.__init__(
2409
 
            self, revno=revno, minimum=bounds[0], maximum=bounds[1])