/brz/remove-bazaar

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

« back to all changes in this revision

Viewing changes to bzrlib/errors.py

  • Committer: Vincent Ladeuil
  • Date: 2011-11-24 10:47:43 UTC
  • mto: (6321.1.1 trunk)
  • mto: This revision was merged to the branch mainline in revision 6322.
  • Revision ID: v.ladeuil+lp@free.fr-20111124104743-rxqwhmzqu5k17f24
First cut at a working plugin to avoid conflicts in .po files by shelling out to msgmerge.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005-2013, 2016 Canonical Ltd
 
1
# Copyright (C) 2005-2011 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
17
17
"""Exceptions for bzr, and reporting of them.
18
18
"""
19
19
 
 
20
from bzrlib import (
 
21
    osutils,
 
22
    symbol_versioning,
 
23
    i18n,
 
24
    trace,
 
25
    )
 
26
from bzrlib.i18n import gettext
 
27
from bzrlib.patches import (
 
28
    MalformedHunkHeader,
 
29
    MalformedLine,
 
30
    MalformedPatchHeader,
 
31
    PatchConflict,
 
32
    PatchSyntax,
 
33
    )
 
34
 
20
35
 
21
36
# TODO: is there any value in providing the .args field used by standard
22
37
# python exceptions?   A list of values with no names seems less useful
31
46
# 'unprintable'.
32
47
 
33
48
 
34
 
# return codes from the brz program
 
49
# return codes from the bzr program
35
50
EXIT_OK = 0
36
51
EXIT_ERROR = 3
37
52
EXIT_INTERNAL_ERROR = 4
38
53
 
39
54
 
40
 
class BzrError(Exception):
 
55
class BzrError(StandardError):
41
56
    """
42
 
    Base class for errors raised by breezy.
 
57
    Base class for errors raised by bzrlib.
43
58
 
44
 
    :cvar internal_error: if True this was probably caused by a brz bug and
 
59
    :cvar internal_error: if True this was probably caused by a bzr bug and
45
60
        should be displayed with a traceback; if False (or absent) this was
46
61
        probably a user or environment error and they don't need the gory
47
62
        details.  (That can be overridden by -Derror on the command line.)
71
86
           not subject to expansion. 'msg' is used instead of 'message' because
72
87
           python evolved and, in 2.6, forbids the use of 'message'.
73
88
        """
74
 
        Exception.__init__(self)
 
89
        StandardError.__init__(self)
75
90
        if msg is not None:
76
91
            # I was going to deprecate this, but it actually turns out to be
77
92
            # quite handy - mbp 20061103.
86
101
        if s is not None:
87
102
            # contains a preformatted message
88
103
            return s
89
 
        err = None
90
104
        try:
91
105
            fmt = self._get_format_string()
92
106
            if fmt:
95
109
                # __str__() should always return a 'str' object
96
110
                # never a 'unicode' object.
97
111
                return s
98
 
        except Exception as e:
99
 
            err = e
100
 
        return 'Unprintable exception %s: dict=%r, fmt=%r, error=%r' \
 
112
        except (AttributeError, TypeError, NameError, ValueError, KeyError), e:
 
113
            return 'Unprintable exception %s: dict=%r, fmt=%r, error=%r' \
 
114
                % (self.__class__.__name__,
 
115
                   self.__dict__,
 
116
                   getattr(self, '_fmt', None),
 
117
                   e)
 
118
 
 
119
    def __unicode__(self):
 
120
        u = self._format()
 
121
        if isinstance(u, str):
 
122
            # Try decoding the str using the default encoding.
 
123
            u = unicode(u)
 
124
        elif not isinstance(u, unicode):
 
125
            # Try to make a unicode object from it, because __unicode__ must
 
126
            # return a unicode object.
 
127
            u = unicode(u)
 
128
        return u
 
129
 
 
130
    def __str__(self):
 
131
        s = self._format()
 
132
        if isinstance(s, unicode):
 
133
            s = s.encode('utf8')
 
134
        else:
 
135
            # __str__ must return a str.
 
136
            s = str(s)
 
137
        return s
 
138
 
 
139
    def __repr__(self):
 
140
        return '%s(%s)' % (self.__class__.__name__, str(self))
 
141
 
 
142
    def _get_format_string(self):
 
143
        """Return format string for this exception or None"""
 
144
        fmt = getattr(self, '_fmt', None)
 
145
        if fmt is not None:
 
146
            i18n.install()
 
147
            unicode_fmt = unicode(fmt) #_fmt strings should be ascii
 
148
            if type(fmt) == unicode:
 
149
                trace.mutter("Unicode strings in error.fmt are deprecated")
 
150
            return gettext(unicode_fmt)
 
151
        fmt = getattr(self, '__doc__', None)
 
152
        if fmt is not None:
 
153
            symbol_versioning.warn("%s uses its docstring as a format, "
 
154
                    "it should use _fmt instead" % self.__class__.__name__,
 
155
                    DeprecationWarning)
 
156
            return fmt
 
157
        return 'Unprintable exception %s: dict=%r, fmt=%r' \
101
158
            % (self.__class__.__name__,
102
159
               self.__dict__,
103
160
               getattr(self, '_fmt', None),
104
 
               err)
105
 
 
106
 
    __str__ = _format
107
 
 
108
 
    def __repr__(self):
109
 
        return '%s(%s)' % (self.__class__.__name__, str(self))
110
 
 
111
 
    def _get_format_string(self):
112
 
        """Return format string for this exception or None"""
113
 
        fmt = getattr(self, '_fmt', None)
114
 
        if fmt is not None:
115
 
            from breezy.i18n import gettext
116
 
            return gettext(fmt)  # _fmt strings should be ascii
 
161
               )
117
162
 
118
163
    def __eq__(self, other):
119
164
        if self.__class__ is not other.__class__:
120
165
            return NotImplemented
121
166
        return self.__dict__ == other.__dict__
122
167
 
123
 
    def __hash__(self):
124
 
        return id(self)
125
 
 
126
168
 
127
169
class InternalBzrError(BzrError):
128
170
    """Base class for errors that are internal in nature.
135
177
    internal_error = True
136
178
 
137
179
 
 
180
class BzrNewError(BzrError):
 
181
    """Deprecated error base class."""
 
182
    # base classes should override the docstring with their human-
 
183
    # readable explanation
 
184
 
 
185
    def __init__(self, *args, **kwds):
 
186
        # XXX: Use the underlying BzrError to always generate the args
 
187
        # attribute if it doesn't exist.  We can't use super here, because
 
188
        # exceptions are old-style classes in python2.4 (but new in 2.5).
 
189
        # --bmc, 20060426
 
190
        symbol_versioning.warn('BzrNewError was deprecated in bzr 0.13; '
 
191
             'please convert %s to use BzrError instead'
 
192
             % self.__class__.__name__,
 
193
             DeprecationWarning,
 
194
             stacklevel=2)
 
195
        BzrError.__init__(self, *args)
 
196
        for key, value in kwds.items():
 
197
            setattr(self, key, value)
 
198
 
 
199
    def __str__(self):
 
200
        try:
 
201
            # __str__() should always return a 'str' object
 
202
            # never a 'unicode' object.
 
203
            s = self.__doc__ % self.__dict__
 
204
            if isinstance(s, unicode):
 
205
                return s.encode('utf8')
 
206
            return s
 
207
        except (TypeError, NameError, ValueError, KeyError), e:
 
208
            return 'Unprintable exception %s(%r): %r' \
 
209
                % (self.__class__.__name__,
 
210
                   self.__dict__, e)
 
211
 
 
212
 
 
213
class AlreadyBuilding(BzrError):
 
214
 
 
215
    _fmt = "The tree builder is already building a tree."
 
216
 
 
217
 
138
218
class BranchError(BzrError):
139
219
    """Base class for concrete 'errors about a branch'."""
140
220
 
151
231
        self.msg = msg
152
232
 
153
233
 
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):
 
234
class DirstateCorrupt(BzrError):
 
235
 
 
236
    _fmt = "The dirstate file (%(state)s) appears to be corrupt: %(msg)s"
 
237
 
 
238
    def __init__(self, state, msg):
 
239
        BzrError.__init__(self)
 
240
        self.state = state
 
241
        self.msg = msg
 
242
 
 
243
 
 
244
class DisabledMethod(InternalBzrError):
 
245
 
 
246
    _fmt = "The smart server method '%(class_name)s' is disabled."
 
247
 
 
248
    def __init__(self, class_name):
 
249
        BzrError.__init__(self)
 
250
        self.class_name = class_name
 
251
 
 
252
 
 
253
class IncompatibleAPI(BzrError):
 
254
 
 
255
    _fmt = 'The API for "%(api)s" is not compatible with "%(wanted)s". '\
 
256
        'It supports versions "%(minimum)s" to "%(current)s".'
 
257
 
 
258
    def __init__(self, api, wanted, minimum, current):
160
259
        self.api = api
161
260
        self.wanted = wanted
 
261
        self.minimum = minimum
162
262
        self.current = current
163
263
 
164
264
 
171
271
        self.transport = transport
172
272
 
173
273
 
 
274
class InvalidEntryName(InternalBzrError):
 
275
 
 
276
    _fmt = "Invalid entry name: %(name)s"
 
277
 
 
278
    def __init__(self, name):
 
279
        BzrError.__init__(self)
 
280
        self.name = name
 
281
 
 
282
 
174
283
class InvalidRevisionNumber(BzrError):
175
284
 
176
285
    _fmt = "Invalid revision number %(revno)s"
202
311
class RootMissing(InternalBzrError):
203
312
 
204
313
    _fmt = ("The root entry of a tree must be the first entry supplied to "
205
 
            "the commit builder.")
 
314
        "the commit builder.")
206
315
 
207
316
 
208
317
class NoPublicBranch(BzrError):
210
319
    _fmt = 'There is no public branch set for "%(branch_url)s".'
211
320
 
212
321
    def __init__(self, branch):
213
 
        from . import urlutils
 
322
        import bzrlib.urlutils as urlutils
214
323
        public_location = urlutils.unescape_for_display(branch.base, 'ascii')
215
324
        BzrError.__init__(self, branch_url=public_location)
216
325
 
217
326
 
 
327
class NoHelpTopic(BzrError):
 
328
 
 
329
    _fmt = ("No help could be found for '%(topic)s'. "
 
330
        "Please use 'bzr help topics' to obtain a list of topics.")
 
331
 
 
332
    def __init__(self, topic):
 
333
        self.topic = topic
 
334
 
 
335
 
218
336
class NoSuchId(BzrError):
219
337
 
220
338
    _fmt = 'The file id "%(file_id)s" is not present in the tree %(tree)s.'
225
343
        self.tree = tree
226
344
 
227
345
 
 
346
class NoSuchIdInRepository(NoSuchId):
 
347
 
 
348
    _fmt = ('The file id "%(file_id)s" is not present in the repository'
 
349
            ' %(repository)r')
 
350
 
 
351
    def __init__(self, repository, file_id):
 
352
        BzrError.__init__(self, repository=repository, file_id=file_id)
 
353
 
 
354
 
228
355
class NotStacked(BranchError):
229
356
 
230
357
    _fmt = "The branch '%(branch)s' is not stacked."
231
358
 
232
359
 
 
360
class InventoryModified(InternalBzrError):
 
361
 
 
362
    _fmt = ("The current inventory for the tree %(tree)r has been modified,"
 
363
            " so a clean inventory cannot be read without data loss.")
 
364
 
 
365
    def __init__(self, tree):
 
366
        self.tree = tree
 
367
 
 
368
 
233
369
class NoWorkingTree(BzrError):
234
370
 
235
371
    _fmt = 'No WorkingTree exists for "%(base)s".'
239
375
        self.base = base
240
376
 
241
377
 
 
378
class NotBuilding(BzrError):
 
379
 
 
380
    _fmt = "Not currently building a tree."
 
381
 
 
382
 
242
383
class NotLocalUrl(BzrError):
243
384
 
244
385
    _fmt = "%(url)s is not a local path."
255
396
        self.base = base
256
397
 
257
398
 
258
 
class NoWhoami(BzrError):
259
 
 
260
 
    _fmt = ('Unable to determine your name.\n'
261
 
            "Please, set your name with the 'whoami' command.\n"
262
 
            'E.g. brz whoami "Your Name <name@example.com>"')
263
 
 
264
 
 
265
 
class CommandError(BzrError):
 
399
class BzrCommandError(BzrError):
266
400
    """Error from user command"""
267
401
 
268
402
    # Error from malformed user command; please avoid raising this as a
270
404
    #
271
405
    # I think it's a waste of effort to differentiate between errors that
272
406
    # are not intended to be caught anyway.  UI code need not subclass
273
 
    # CommandError, and non-UI code should not throw a subclass of
274
 
    # CommandError.  ADHB 20051211
275
 
 
276
 
 
277
 
# Provide the old name as backup, for the moment.
278
 
BzrCommandError = CommandError
 
407
    # BzrCommandError, and non-UI code should not throw a subclass of
 
408
    # BzrCommandError.  ADHB 20051211
279
409
 
280
410
 
281
411
class NotWriteLocked(BzrError):
286
416
        self.not_locked = not_locked
287
417
 
288
418
 
 
419
class BzrOptionError(BzrCommandError):
 
420
 
 
421
    _fmt = "Error in command line options"
 
422
 
 
423
 
 
424
class BadIndexFormatSignature(BzrError):
 
425
 
 
426
    _fmt = "%(value)s is not an index of type %(_type)s."
 
427
 
 
428
    def __init__(self, value, _type):
 
429
        BzrError.__init__(self)
 
430
        self.value = value
 
431
        self._type = _type
 
432
 
 
433
 
 
434
class BadIndexData(BzrError):
 
435
 
 
436
    _fmt = "Error in data for index %(value)s."
 
437
 
 
438
    def __init__(self, value):
 
439
        BzrError.__init__(self)
 
440
        self.value = value
 
441
 
 
442
 
 
443
class BadIndexDuplicateKey(BzrError):
 
444
 
 
445
    _fmt = "The key '%(key)s' is already in index '%(index)s'."
 
446
 
 
447
    def __init__(self, key, index):
 
448
        BzrError.__init__(self)
 
449
        self.key = key
 
450
        self.index = index
 
451
 
 
452
 
 
453
class BadIndexKey(BzrError):
 
454
 
 
455
    _fmt = "The key '%(key)s' is not a valid key."
 
456
 
 
457
    def __init__(self, key):
 
458
        BzrError.__init__(self)
 
459
        self.key = key
 
460
 
 
461
 
 
462
class BadIndexOptions(BzrError):
 
463
 
 
464
    _fmt = "Could not parse options for index %(value)s."
 
465
 
 
466
    def __init__(self, value):
 
467
        BzrError.__init__(self)
 
468
        self.value = value
 
469
 
 
470
 
 
471
class BadIndexValue(BzrError):
 
472
 
 
473
    _fmt = "The value '%(value)s' is not a valid value."
 
474
 
 
475
    def __init__(self, value):
 
476
        BzrError.__init__(self)
 
477
        self.value = value
 
478
 
 
479
 
 
480
class BadOptionValue(BzrError):
 
481
 
 
482
    _fmt = """Bad value "%(value)s" for option "%(name)s"."""
 
483
 
 
484
    def __init__(self, name, value):
 
485
        BzrError.__init__(self, name=name, value=value)
 
486
 
 
487
 
289
488
class StrictCommitFailed(BzrError):
290
489
 
291
490
    _fmt = "Commit refused because there are unknown files in the tree"
324
523
    """Used when renaming and both source and dest exist."""
325
524
 
326
525
    _fmt = ("Could not rename %(source)s => %(dest)s because both files exist."
327
 
            " (Use --after to tell brz about a rename that has already"
 
526
            " (Use --after to tell bzr about a rename that has already"
328
527
            " happened)%(extra)s")
329
528
 
330
529
    def __init__(self, source, dest, extra=None):
377
576
    _fmt = 'Permission denied: "%(path)s"%(extra)s'
378
577
 
379
578
 
 
579
class InvalidURL(PathError):
 
580
 
 
581
    _fmt = 'Invalid url supplied to transport: "%(path)s"%(extra)s'
 
582
 
 
583
 
 
584
class InvalidURLJoin(PathError):
 
585
 
 
586
    _fmt = "Invalid URL join request: %(reason)s: %(base)r + %(join_args)r"
 
587
 
 
588
    def __init__(self, reason, base, join_args):
 
589
        self.reason = reason
 
590
        self.base = base
 
591
        self.join_args = join_args
 
592
        PathError.__init__(self, base, reason)
 
593
 
 
594
 
 
595
class InvalidRebaseURLs(PathError):
 
596
 
 
597
    _fmt = "URLs differ by more than path: %(from_)r and %(to)r"
 
598
 
 
599
    def __init__(self, from_, to):
 
600
        self.from_ = from_
 
601
        self.to = to
 
602
        PathError.__init__(self, from_, 'URLs differ by more than path.')
 
603
 
 
604
 
 
605
class UnavailableRepresentation(InternalBzrError):
 
606
 
 
607
    _fmt = ("The encoding '%(wanted)s' is not available for key %(key)s which "
 
608
        "is encoded as '%(native)s'.")
 
609
 
 
610
    def __init__(self, key, wanted, native):
 
611
        InternalBzrError.__init__(self)
 
612
        self.wanted = wanted
 
613
        self.native = native
 
614
        self.key = key
 
615
 
 
616
 
 
617
class UnknownHook(BzrError):
 
618
 
 
619
    _fmt = "The %(type)s hook '%(hook)s' is unknown in this version of bzrlib."
 
620
 
 
621
    def __init__(self, hook_type, hook_name):
 
622
        BzrError.__init__(self)
 
623
        self.type = hook_type
 
624
        self.hook = hook_name
 
625
 
 
626
 
380
627
class UnsupportedProtocol(PathError):
381
628
 
382
629
    _fmt = 'Unsupported protocol for url "%(path)s"%(extra)s'
385
632
        PathError.__init__(self, url, extra=extra)
386
633
 
387
634
 
 
635
class UnstackableBranchFormat(BzrError):
 
636
 
 
637
    _fmt = ("The branch '%(url)s'(%(format)s) is not a stackable format. "
 
638
        "You will need to upgrade the branch to permit branch stacking.")
 
639
 
 
640
    def __init__(self, format, url):
 
641
        BzrError.__init__(self)
 
642
        self.format = format
 
643
        self.url = url
 
644
 
 
645
 
388
646
class UnstackableLocationError(BzrError):
389
647
 
390
648
    _fmt = "The branch '%(branch_url)s' cannot be stacked on '%(target_url)s'."
398
656
class UnstackableRepositoryFormat(BzrError):
399
657
 
400
658
    _fmt = ("The repository '%(url)s'(%(format)s) is not a stackable format. "
401
 
            "You will need to upgrade the repository to permit branch stacking.")
 
659
        "You will need to upgrade the repository to permit branch stacking.")
402
660
 
403
661
    def __init__(self, format, url):
404
662
        BzrError.__init__(self)
453
711
 
454
712
    _fmt = 'Not a branch: "%(path)s"%(detail)s.'
455
713
 
456
 
    def __init__(self, path, detail=None, controldir=None):
457
 
        from . import urlutils
458
 
        path = urlutils.unescape_for_display(path, 'ascii')
459
 
        if detail is not None:
460
 
            detail = ': ' + detail
461
 
        self.detail = detail
462
 
        self.controldir = controldir
463
 
        PathError.__init__(self, path=path)
 
714
    def __init__(self, path, detail=None, bzrdir=None):
 
715
       import bzrlib.urlutils as urlutils
 
716
       path = urlutils.unescape_for_display(path, 'ascii')
 
717
       if detail is not None:
 
718
           detail = ': ' + detail
 
719
       self.detail = detail
 
720
       self.bzrdir = bzrdir
 
721
       PathError.__init__(self, path=path)
464
722
 
465
723
    def __repr__(self):
466
724
        return '<%s %r>' % (self.__class__.__name__, self.__dict__)
467
725
 
468
 
    def _get_format_string(self):
469
 
        # GZ 2017-06-08: Not the best place to lazy fill detail in.
 
726
    def _format(self):
 
727
        # XXX: Ideally self.detail would be a property, but Exceptions in
 
728
        # Python 2.4 have to be old-style classes so properties don't work.
 
729
        # Instead we override _format.
470
730
        if self.detail is None:
471
 
            self.detail = self._get_detail()
472
 
        return super(NotBranchError, self)._get_format_string()
473
 
 
474
 
    def _get_detail(self):
475
 
        if self.controldir is not None:
476
 
            try:
477
 
                self.controldir.open_repository()
478
 
            except NoRepositoryPresent:
479
 
                return ''
480
 
            except Exception as e:
481
 
                # Just ignore unexpected errors.  Raising arbitrary errors
482
 
                # during str(err) can provoke strange bugs.  Concretely
483
 
                # Launchpad's codehosting managed to raise NotBranchError
484
 
                # here, and then get stuck in an infinite loop/recursion
485
 
                # trying to str() that error.  All this error really cares
486
 
                # about that there's no working repository there, and if
487
 
                # open_repository() fails, there probably isn't.
488
 
                return ': ' + e.__class__.__name__
 
731
            if self.bzrdir is not None:
 
732
                try:
 
733
                    self.bzrdir.open_repository()
 
734
                except NoRepositoryPresent:
 
735
                    self.detail = ''
 
736
                except Exception:
 
737
                    # Just ignore unexpected errors.  Raising arbitrary errors
 
738
                    # during str(err) can provoke strange bugs.  Concretely
 
739
                    # Launchpad's codehosting managed to raise NotBranchError
 
740
                    # here, and then get stuck in an infinite loop/recursion
 
741
                    # trying to str() that error.  All this error really cares
 
742
                    # about that there's no working repository there, and if
 
743
                    # open_repository() fails, there probably isn't.
 
744
                    self.detail = ''
 
745
                else:
 
746
                    self.detail = ': location is a repository'
489
747
            else:
490
 
                return ': location is a repository'
491
 
        return ''
 
748
                self.detail = ''
 
749
        return PathError._format(self)
492
750
 
493
751
 
494
752
class NoSubmitBranch(PathError):
496
754
    _fmt = 'No submit branch available for branch "%(path)s"'
497
755
 
498
756
    def __init__(self, branch):
499
 
        from . import urlutils
500
 
        self.path = urlutils.unescape_for_display(branch.base, 'ascii')
501
 
 
502
 
 
503
 
class AlreadyControlDirError(PathError):
504
 
 
505
 
    _fmt = 'A control directory already exists: "%(path)s".'
 
757
       import bzrlib.urlutils as urlutils
 
758
       self.path = urlutils.unescape_for_display(branch.base, 'ascii')
506
759
 
507
760
 
508
761
class AlreadyBranchError(PathError):
510
763
    _fmt = 'Already a branch: "%(path)s".'
511
764
 
512
765
 
513
 
class InvalidBranchName(PathError):
514
 
 
515
 
    _fmt = "Invalid branch name: %(name)s"
516
 
 
517
 
    def __init__(self, name):
518
 
        BzrError.__init__(self)
519
 
        self.name = name
520
 
 
521
 
 
522
 
class ParentBranchExists(AlreadyBranchError):
523
 
 
524
 
    _fmt = 'Parent branch already exists: "%(path)s".'
525
 
 
526
 
 
527
766
class BranchExistsWithoutWorkingTree(PathError):
528
767
 
529
768
    _fmt = 'Directory contains a branch, but no working tree \
530
 
(use brz checkout if you wish to build a working tree): "%(path)s"'
 
769
(use bzr checkout if you wish to build a working tree): "%(path)s"'
 
770
 
 
771
 
 
772
class AtomicFileAlreadyClosed(PathError):
 
773
 
 
774
    _fmt = ('"%(function)s" called on an AtomicFile after it was closed:'
 
775
            ' "%(path)s"')
 
776
 
 
777
    def __init__(self, path, function):
 
778
        PathError.__init__(self, path=path, extra=None)
 
779
        self.function = function
531
780
 
532
781
 
533
782
class InaccessibleParent(PathError):
543
792
class NoRepositoryPresent(BzrError):
544
793
 
545
794
    _fmt = 'No repository present: "%(path)s"'
546
 
 
547
 
    def __init__(self, controldir):
548
 
        BzrError.__init__(self)
549
 
        self.path = controldir.transport.clone('..').base
 
795
    def __init__(self, bzrdir):
 
796
        BzrError.__init__(self)
 
797
        self.path = bzrdir.transport.clone('..').base
 
798
 
 
799
 
 
800
class FileInWrongBranch(BzrError):
 
801
 
 
802
    _fmt = 'File "%(path)s" is not in branch %(branch_base)s.'
 
803
 
 
804
    # use PathNotChild instead
 
805
    @symbol_versioning.deprecated_method(symbol_versioning.deprecated_in((2, 3, 0)))
 
806
    def __init__(self, branch, path):
 
807
        BzrError.__init__(self)
 
808
        self.branch = branch
 
809
        self.branch_base = branch.base
 
810
        self.path = path
550
811
 
551
812
 
552
813
class UnsupportedFormatError(BzrError):
553
814
 
554
 
    _fmt = "Unsupported branch format: %(format)s\nPlease run 'brz upgrade'"
 
815
    _fmt = "Unsupported branch format: %(format)s\nPlease run 'bzr upgrade'"
555
816
 
556
817
 
557
818
class UnknownFormatError(BzrError):
565
826
 
566
827
class IncompatibleFormat(BzrError):
567
828
 
568
 
    _fmt = "Format %(format)s is not compatible with .bzr version %(controldir)s."
569
 
 
570
 
    def __init__(self, format, controldir_format):
571
 
        BzrError.__init__(self)
572
 
        self.format = format
573
 
        self.controldir = controldir_format
574
 
 
575
 
 
576
 
class ParseFormatError(BzrError):
577
 
 
578
 
    _fmt = "Parse error on line %(lineno)d of %(format)s format: %(line)s"
579
 
 
580
 
    def __init__(self, format, lineno, line, text):
581
 
        BzrError.__init__(self)
582
 
        self.format = format
583
 
        self.lineno = lineno
584
 
        self.line = line
585
 
        self.text = text
 
829
    _fmt = "Format %(format)s is not compatible with .bzr version %(bzrdir)s."
 
830
 
 
831
    def __init__(self, format, bzrdir_format):
 
832
        BzrError.__init__(self)
 
833
        self.format = format
 
834
        self.bzrdir = bzrdir_format
586
835
 
587
836
 
588
837
class IncompatibleRepositories(BzrError):
594
843
    """
595
844
 
596
845
    _fmt = "%(target)s\n" \
597
 
        "is not compatible with\n" \
598
 
        "%(source)s\n" \
599
 
        "%(details)s"
 
846
            "is not compatible with\n" \
 
847
            "%(source)s\n" \
 
848
            "%(details)s"
600
849
 
601
850
    def __init__(self, source, target, details=None):
602
851
        if details is None:
661
910
    _fmt = "Path(s) are not versioned: %(paths_as_string)s"
662
911
 
663
912
    def __init__(self, paths):
664
 
        from breezy.osutils import quotefn
 
913
        from bzrlib.osutils import quotefn
665
914
        BzrError.__init__(self)
666
915
        self.paths = paths
667
916
        self.paths_as_string = ' '.join([quotefn(p) for p in paths])
676
925
 
677
926
    def __init__(self, paths, extra=None):
678
927
        # circular import
679
 
        from breezy.osutils import quotefn
 
928
        from bzrlib.osutils import quotefn
680
929
        BzrError.__init__(self)
681
930
        self.paths = paths
682
931
        self.paths_as_string = ' '.join([quotefn(p) for p in paths])
845
1094
class LockCorrupt(LockError):
846
1095
 
847
1096
    _fmt = ("Lock is apparently held, but corrupted: %(corruption_info)s\n"
848
 
            "Use 'brz break-lock' to clear it")
 
1097
            "Use 'bzr break-lock' to clear it")
849
1098
 
850
1099
    internal_error = False
851
1100
 
883
1132
        self.lock_token = lock_token
884
1133
 
885
1134
 
 
1135
class PointlessCommit(BzrError):
 
1136
 
 
1137
    _fmt = "No changes to commit"
 
1138
 
 
1139
 
 
1140
class CannotCommitSelectedFileMerge(BzrError):
 
1141
 
 
1142
    _fmt = 'Selected-file commit of merges is not supported yet:'\
 
1143
        ' files %(files_str)s'
 
1144
 
 
1145
    def __init__(self, files):
 
1146
        files_str = ', '.join(files)
 
1147
        BzrError.__init__(self, files=files, files_str=files_str)
 
1148
 
 
1149
 
 
1150
class ExcludesUnsupported(BzrError):
 
1151
 
 
1152
    _fmt = ('Excluding paths during commit is not supported by '
 
1153
            'repository at %(repository)r.')
 
1154
 
 
1155
    def __init__(self, repository):
 
1156
        BzrError.__init__(self, repository=repository)
 
1157
 
 
1158
 
 
1159
class BadCommitMessageEncoding(BzrError):
 
1160
 
 
1161
    _fmt = 'The specified commit message contains characters unsupported by '\
 
1162
        'the current encoding.'
 
1163
 
 
1164
 
886
1165
class UpgradeReadonly(BzrError):
887
1166
 
888
1167
    _fmt = "Upgrade URL cannot work with readonly URLs."
897
1176
        self.format = format
898
1177
 
899
1178
 
 
1179
class StrictCommitFailed(Exception):
 
1180
 
 
1181
    _fmt = "Commit refused because there are unknowns in the tree."
 
1182
 
 
1183
 
900
1184
class NoSuchRevision(InternalBzrError):
901
1185
 
902
1186
    _fmt = "%(branch)s has no revision %(revision)s"
930
1214
        self.revision_id = revision_id
931
1215
 
932
1216
 
 
1217
class InvalidRevisionSpec(BzrError):
 
1218
 
 
1219
    _fmt = ("Requested revision: '%(spec)s' does not exist in branch:"
 
1220
            " %(branch_url)s%(extra)s")
 
1221
 
 
1222
    def __init__(self, spec, branch, extra=None):
 
1223
        BzrError.__init__(self, branch=branch, spec=spec)
 
1224
        self.branch_url = getattr(branch, 'user_url', str(branch))
 
1225
        if extra:
 
1226
            self.extra = '\n' + str(extra)
 
1227
        else:
 
1228
            self.extra = ''
 
1229
 
 
1230
 
 
1231
class HistoryMissing(BzrError):
 
1232
 
 
1233
    _fmt = "%(branch)s is missing %(object_type)s {%(object_id)s}"
 
1234
 
 
1235
 
933
1236
class AppendRevisionsOnlyViolation(BzrError):
934
1237
 
935
1238
    _fmt = ('Operation denied because it would change the main history,'
936
 
            ' which is not permitted by the append_revisions_only setting on'
937
 
            ' branch "%(location)s".')
 
1239
           ' which is not permitted by the append_revisions_only setting on'
 
1240
           ' branch "%(location)s".')
938
1241
 
939
1242
    def __init__(self, location):
940
 
        import breezy.urlutils as urlutils
941
 
        location = urlutils.unescape_for_display(location, 'ascii')
942
 
        BzrError.__init__(self, location=location)
 
1243
       import bzrlib.urlutils as urlutils
 
1244
       location = urlutils.unescape_for_display(location, 'ascii')
 
1245
       BzrError.__init__(self, location=location)
943
1246
 
944
1247
 
945
1248
class DivergedBranches(BzrError):
985
1288
class NoCommonRoot(BzrError):
986
1289
 
987
1290
    _fmt = ("Revisions are not derived from the same root: "
988
 
            "%(revision_a)s %(revision_b)s.")
 
1291
           "%(revision_a)s %(revision_b)s.")
989
1292
 
990
1293
    def __init__(self, revision_a, revision_b):
991
1294
        BzrError.__init__(self, revision_a=revision_a, revision_b=revision_b)
997
1300
 
998
1301
    def __init__(self, rev_id, not_ancestor_id):
999
1302
        BzrError.__init__(self, rev_id=rev_id,
1000
 
                          not_ancestor_id=not_ancestor_id)
 
1303
            not_ancestor_id=not_ancestor_id)
 
1304
 
 
1305
 
 
1306
class AmbiguousBase(BzrError):
 
1307
 
 
1308
    def __init__(self, bases):
 
1309
        symbol_versioning.warn("BzrError AmbiguousBase has been deprecated "
 
1310
            "as of bzrlib 0.8.", DeprecationWarning, stacklevel=2)
 
1311
        msg = ("The correct base is unclear, because %s are all equally close"
 
1312
                % ", ".join(bases))
 
1313
        BzrError.__init__(self, msg)
 
1314
        self.bases = bases
1001
1315
 
1002
1316
 
1003
1317
class NoCommits(BranchError):
1011
1325
        BzrError.__init__(self, "Store %s is not listable" % store)
1012
1326
 
1013
1327
 
 
1328
 
1014
1329
class UnlistableBranch(BzrError):
1015
1330
 
1016
1331
    def __init__(self, br):
1062
1377
        self.error = error
1063
1378
 
1064
1379
 
 
1380
class WeaveError(BzrError):
 
1381
 
 
1382
    _fmt = "Error in processing weave: %(msg)s"
 
1383
 
 
1384
    def __init__(self, msg=None):
 
1385
        BzrError.__init__(self)
 
1386
        self.msg = msg
 
1387
 
 
1388
 
 
1389
class WeaveRevisionAlreadyPresent(WeaveError):
 
1390
 
 
1391
    _fmt = "Revision {%(revision_id)s} already present in %(weave)s"
 
1392
 
 
1393
    def __init__(self, revision_id, weave):
 
1394
 
 
1395
        WeaveError.__init__(self)
 
1396
        self.revision_id = revision_id
 
1397
        self.weave = weave
 
1398
 
 
1399
 
 
1400
class WeaveRevisionNotPresent(WeaveError):
 
1401
 
 
1402
    _fmt = "Revision {%(revision_id)s} not present in %(weave)s"
 
1403
 
 
1404
    def __init__(self, revision_id, weave):
 
1405
        WeaveError.__init__(self)
 
1406
        self.revision_id = revision_id
 
1407
        self.weave = weave
 
1408
 
 
1409
 
 
1410
class WeaveFormatError(WeaveError):
 
1411
 
 
1412
    _fmt = "Weave invariant violated: %(what)s"
 
1413
 
 
1414
    def __init__(self, what):
 
1415
        WeaveError.__init__(self)
 
1416
        self.what = what
 
1417
 
 
1418
 
 
1419
class WeaveParentMismatch(WeaveError):
 
1420
 
 
1421
    _fmt = "Parents are mismatched between two revisions. %(msg)s"
 
1422
 
 
1423
 
 
1424
class WeaveInvalidChecksum(WeaveError):
 
1425
 
 
1426
    _fmt = "Text did not match its checksum: %(msg)s"
 
1427
 
 
1428
 
 
1429
class WeaveTextDiffers(WeaveError):
 
1430
 
 
1431
    _fmt = ("Weaves differ on text content. Revision:"
 
1432
            " {%(revision_id)s}, %(weave_a)s, %(weave_b)s")
 
1433
 
 
1434
    def __init__(self, revision_id, weave_a, weave_b):
 
1435
        WeaveError.__init__(self)
 
1436
        self.revision_id = revision_id
 
1437
        self.weave_a = weave_a
 
1438
        self.weave_b = weave_b
 
1439
 
 
1440
 
 
1441
class WeaveTextDiffers(WeaveError):
 
1442
 
 
1443
    _fmt = ("Weaves differ on text content. Revision:"
 
1444
            " {%(revision_id)s}, %(weave_a)s, %(weave_b)s")
 
1445
 
 
1446
    def __init__(self, revision_id, weave_a, weave_b):
 
1447
        WeaveError.__init__(self)
 
1448
        self.revision_id = revision_id
 
1449
        self.weave_a = weave_a
 
1450
        self.weave_b = weave_b
 
1451
 
 
1452
 
1065
1453
class VersionedFileError(BzrError):
1066
1454
 
1067
1455
    _fmt = "Versioned file error"
1092
1480
    _fmt = "Text did not match its checksum: %(msg)s"
1093
1481
 
1094
1482
 
 
1483
class KnitError(InternalBzrError):
 
1484
 
 
1485
    _fmt = "Knit error"
 
1486
 
 
1487
 
 
1488
class KnitCorrupt(KnitError):
 
1489
 
 
1490
    _fmt = "Knit %(filename)s corrupt: %(how)s"
 
1491
 
 
1492
    def __init__(self, filename, how):
 
1493
        KnitError.__init__(self)
 
1494
        self.filename = filename
 
1495
        self.how = how
 
1496
 
 
1497
 
 
1498
class SHA1KnitCorrupt(KnitCorrupt):
 
1499
 
 
1500
    _fmt = ("Knit %(filename)s corrupt: sha-1 of reconstructed text does not "
 
1501
        "match expected sha-1. key %(key)s expected sha %(expected)s actual "
 
1502
        "sha %(actual)s")
 
1503
 
 
1504
    def __init__(self, filename, actual, expected, key, content):
 
1505
        KnitError.__init__(self)
 
1506
        self.filename = filename
 
1507
        self.actual = actual
 
1508
        self.expected = expected
 
1509
        self.key = key
 
1510
        self.content = content
 
1511
 
 
1512
 
 
1513
class KnitDataStreamIncompatible(KnitError):
 
1514
    # Not raised anymore, as we can convert data streams.  In future we may
 
1515
    # need it again for more exotic cases, so we're keeping it around for now.
 
1516
 
 
1517
    _fmt = "Cannot insert knit data stream of format \"%(stream_format)s\" into knit of format \"%(target_format)s\"."
 
1518
 
 
1519
    def __init__(self, stream_format, target_format):
 
1520
        self.stream_format = stream_format
 
1521
        self.target_format = target_format
 
1522
 
 
1523
 
 
1524
class KnitDataStreamUnknown(KnitError):
 
1525
    # Indicates a data stream we don't know how to handle.
 
1526
 
 
1527
    _fmt = "Cannot parse knit data stream of format \"%(stream_format)s\"."
 
1528
 
 
1529
    def __init__(self, stream_format):
 
1530
        self.stream_format = stream_format
 
1531
 
 
1532
 
 
1533
class KnitHeaderError(KnitError):
 
1534
 
 
1535
    _fmt = 'Knit header error: %(badline)r unexpected for file "%(filename)s".'
 
1536
 
 
1537
    def __init__(self, badline, filename):
 
1538
        KnitError.__init__(self)
 
1539
        self.badline = badline
 
1540
        self.filename = filename
 
1541
 
 
1542
class KnitIndexUnknownMethod(KnitError):
 
1543
    """Raised when we don't understand the storage method.
 
1544
 
 
1545
    Currently only 'fulltext' and 'line-delta' are supported.
 
1546
    """
 
1547
 
 
1548
    _fmt = ("Knit index %(filename)s does not have a known method"
 
1549
            " in options: %(options)r")
 
1550
 
 
1551
    def __init__(self, filename, options):
 
1552
        KnitError.__init__(self)
 
1553
        self.filename = filename
 
1554
        self.options = options
 
1555
 
 
1556
 
1095
1557
class RetryWithNewPacks(BzrError):
1096
1558
    """Raised when we realize that the packs on disk have changed.
1097
1559
 
1158
1620
        if orig_error is None:
1159
1621
            orig_error = ''
1160
1622
        if msg is None:
1161
 
            msg = ''
 
1623
            msg =  ''
1162
1624
        self.msg = msg
1163
1625
        self.orig_error = orig_error
1164
1626
        BzrError.__init__(self)
1209
1671
        self.exc_type, self.exc_value, self.exc_tb = exc_info
1210
1672
        self.exc_info = exc_info
1211
1673
        traceback_strings = traceback.format_exception(
1212
 
            self.exc_type, self.exc_value, self.exc_tb)
 
1674
                self.exc_type, self.exc_value, self.exc_tb)
1213
1675
        self.traceback_text = ''.join(traceback_strings)
1214
1676
 
1215
1677
 
1280
1742
        TransportError.__init__(self, msg, orig_error=orig_error)
1281
1743
 
1282
1744
 
1283
 
class UnexpectedHttpStatus(InvalidHttpResponse):
1284
 
 
1285
 
    _fmt = "Unexpected HTTP status %(code)d for %(path)s"
1286
 
 
1287
 
    def __init__(self, path, code, msg=None):
1288
 
        self.path = path
1289
 
        self.code = code
1290
 
        self.msg = msg
1291
 
        full_msg = 'status code %d unexpected' % code
1292
 
        if msg is not None:
1293
 
            full_msg += ': ' + msg
1294
 
        InvalidHttpResponse.__init__(
1295
 
            self, path, full_msg)
1296
 
 
1297
 
 
1298
 
class BadHttpRequest(UnexpectedHttpStatus):
1299
 
 
1300
 
    _fmt = "Bad http request for %(path)s: %(reason)s"
1301
 
 
1302
 
    def __init__(self, path, reason):
1303
 
        self.path = path
1304
 
        self.reason = reason
1305
 
        TransportError.__init__(self, reason)
1306
 
 
1307
 
 
1308
1745
class InvalidHttpRange(InvalidHttpResponse):
1309
1746
 
1310
1747
    _fmt = "Invalid http range %(range)r for %(path)s: %(msg)s"
1360
1797
    _fmt = "Working tree has conflicts."
1361
1798
 
1362
1799
 
 
1800
class ConfigContentError(BzrError):
 
1801
 
 
1802
    _fmt = "Config file %(filename)s is not UTF-8 encoded\n"
 
1803
 
 
1804
    def __init__(self, filename):
 
1805
        BzrError.__init__(self)
 
1806
        self.filename = filename
 
1807
 
 
1808
 
 
1809
class ParseConfigError(BzrError):
 
1810
 
 
1811
    _fmt = "Error(s) parsing config file %(filename)s:\n%(errors)s"
 
1812
 
 
1813
    def __init__(self, errors, filename):
 
1814
        BzrError.__init__(self)
 
1815
        self.filename = filename
 
1816
        self.errors = '\n'.join(e.msg for e in errors)
 
1817
 
 
1818
 
 
1819
class ConfigOptionValueError(BzrError):
 
1820
 
 
1821
    _fmt = """Bad value "%(value)s" for option "%(name)s"."""
 
1822
 
 
1823
    def __init__(self, name, value):
 
1824
        BzrError.__init__(self, name=name, value=value)
 
1825
 
 
1826
 
 
1827
class NoEmailInUsername(BzrError):
 
1828
 
 
1829
    _fmt = "%(username)r does not seem to contain a reasonable email address"
 
1830
 
 
1831
    def __init__(self, username):
 
1832
        BzrError.__init__(self)
 
1833
        self.username = username
 
1834
 
 
1835
 
 
1836
class SigningFailed(BzrError):
 
1837
 
 
1838
    _fmt = 'Failed to GPG sign data with command "%(command_line)s"'
 
1839
 
 
1840
    def __init__(self, command_line):
 
1841
        BzrError.__init__(self, command_line=command_line)
 
1842
 
 
1843
 
 
1844
class SignatureVerificationFailed(BzrError):
 
1845
 
 
1846
    _fmt = 'Failed to verify GPG signature data with error "%(error)s"'
 
1847
 
 
1848
    def __init__(self, error):
 
1849
        BzrError.__init__(self, error=error)
 
1850
 
 
1851
 
1363
1852
class DependencyNotPresent(BzrError):
1364
1853
 
1365
1854
    _fmt = 'Unable to import library "%(library)s": %(error)s'
1368
1857
        BzrError.__init__(self, library=library, error=error)
1369
1858
 
1370
1859
 
 
1860
class GpgmeNotInstalled(DependencyNotPresent):
 
1861
 
 
1862
    _fmt = 'python-gpgme is not installed, it is needed to verify signatures'
 
1863
 
 
1864
    def __init__(self, error):
 
1865
        DependencyNotPresent.__init__(self, 'gpgme', error)
 
1866
 
 
1867
 
1371
1868
class WorkingTreeNotRevision(BzrError):
1372
1869
 
1373
1870
    _fmt = ("The working tree for %(basedir)s has changed since"
1378
1875
        BzrError.__init__(self, basedir=tree.basedir)
1379
1876
 
1380
1877
 
 
1878
class CantReprocessAndShowBase(BzrError):
 
1879
 
 
1880
    _fmt = ("Can't reprocess and show base, because reprocessing obscures "
 
1881
           "the relationship of conflicting lines to the base")
 
1882
 
 
1883
 
1381
1884
class GraphCycleError(BzrError):
1382
1885
 
1383
1886
    _fmt = "Cycle in graph %(graph)r"
1460
1963
        self.file_id = file_id
1461
1964
 
1462
1965
 
 
1966
class DuplicateFileId(BzrError):
 
1967
 
 
1968
    _fmt = "File id {%(file_id)s} already exists in inventory as %(entry)s"
 
1969
 
 
1970
    def __init__(self, file_id, entry):
 
1971
        BzrError.__init__(self)
 
1972
        self.file_id = file_id
 
1973
        self.entry = entry
 
1974
 
 
1975
 
1463
1976
class DuplicateKey(BzrError):
1464
1977
 
1465
1978
    _fmt = "Key %(key)s is already present in map"
1473
1986
        self.prefix = prefix
1474
1987
 
1475
1988
 
 
1989
class MalformedTransform(InternalBzrError):
 
1990
 
 
1991
    _fmt = "Tree transform is malformed %(conflicts)r"
 
1992
 
 
1993
 
 
1994
class NoFinalPath(BzrError):
 
1995
 
 
1996
    _fmt = ("No final name for trans_id %(trans_id)r\n"
 
1997
            "file-id: %(file_id)r\n"
 
1998
            "root trans-id: %(root_trans_id)r\n")
 
1999
 
 
2000
    def __init__(self, trans_id, transform):
 
2001
        self.trans_id = trans_id
 
2002
        self.file_id = transform.final_file_id(trans_id)
 
2003
        self.root_trans_id = transform.root
 
2004
 
 
2005
 
1476
2006
class BzrBadParameter(InternalBzrError):
1477
2007
 
1478
2008
    _fmt = "Bad parameter: %(param)r"
1490
2020
    _fmt = "Parameter %(param)s is neither unicode nor utf8."
1491
2021
 
1492
2022
 
 
2023
class ReusingTransform(BzrError):
 
2024
 
 
2025
    _fmt = "Attempt to reuse a transform that has already been applied."
 
2026
 
 
2027
 
 
2028
class CantMoveRoot(BzrError):
 
2029
 
 
2030
    _fmt = "Moving the root directory is not supported at this time"
 
2031
 
 
2032
 
 
2033
class TransformRenameFailed(BzrError):
 
2034
 
 
2035
    _fmt = "Failed to rename %(from_path)s to %(to_path)s: %(why)s"
 
2036
 
 
2037
    def __init__(self, from_path, to_path, why, errno):
 
2038
        self.from_path = from_path
 
2039
        self.to_path = to_path
 
2040
        self.why = why
 
2041
        self.errno = errno
 
2042
 
 
2043
 
1493
2044
class BzrMoveFailedError(BzrError):
1494
2045
 
1495
2046
    _fmt = ("Could not move %(from_path)s%(operator)s %(to_path)s"
1496
 
            "%(_has_extra)s%(extra)s")
 
2047
        "%(_has_extra)s%(extra)s")
1497
2048
 
1498
2049
    def __init__(self, from_path='', to_path='', extra=None):
1499
 
        from breezy.osutils import splitpath
 
2050
        from bzrlib.osutils import splitpath
1500
2051
        BzrError.__init__(self)
1501
2052
        if extra:
1502
2053
            self.extra, self._has_extra = extra, ': '
1529
2080
class BzrRenameFailedError(BzrMoveFailedError):
1530
2081
 
1531
2082
    _fmt = ("Could not rename %(from_path)s%(operator)s %(to_path)s"
1532
 
            "%(_has_extra)s%(extra)s")
 
2083
        "%(_has_extra)s%(extra)s")
1533
2084
 
1534
2085
    def __init__(self, from_path, to_path, extra=None):
1535
2086
        BzrMoveFailedError.__init__(self, from_path, to_path, extra)
1536
2087
 
1537
2088
 
 
2089
class BzrRemoveChangedFilesError(BzrError):
 
2090
    """Used when user is trying to remove changed files."""
 
2091
 
 
2092
    _fmt = ("Can't safely remove modified or unknown files:\n"
 
2093
        "%(changes_as_text)s"
 
2094
        "Use --keep to not delete them, or --force to delete them regardless.")
 
2095
 
 
2096
    def __init__(self, tree_delta):
 
2097
        symbol_versioning.warn(symbol_versioning.deprecated_in((2, 3, 0)) %
 
2098
            "BzrRemoveChangedFilesError", DeprecationWarning, stacklevel=2)
 
2099
        BzrError.__init__(self)
 
2100
        self.changes_as_text = tree_delta.get_changes_as_text()
 
2101
        #self.paths_as_string = '\n'.join(changed_files)
 
2102
        #self.paths_as_string = '\n'.join([quotefn(p) for p in changed_files])
 
2103
 
 
2104
 
1538
2105
class BzrBadParameterNotString(BzrBadParameter):
1539
2106
 
1540
2107
    _fmt = "Parameter %(param)s is not a string or unicode string."
1571
2138
 
1572
2139
class UninitializableFormat(BzrError):
1573
2140
 
1574
 
    _fmt = "Format %(format)s cannot be initialised by this version of brz."
 
2141
    _fmt = "Format %(format)s cannot be initialised by this version of bzr."
1575
2142
 
1576
2143
    def __init__(self, format):
1577
2144
        BzrError.__init__(self)
1581
2148
class BadConversionTarget(BzrError):
1582
2149
 
1583
2150
    _fmt = "Cannot convert from format %(from_format)s to format %(format)s." \
1584
 
        "    %(problem)s"
 
2151
            "    %(problem)s"
1585
2152
 
1586
2153
    def __init__(self, problem, format, from_format=None):
1587
2154
        BzrError.__init__(self)
1619
2186
    _fmt = "Diff3 is not installed on this machine."
1620
2187
 
1621
2188
 
 
2189
class ExistingContent(BzrError):
 
2190
    # Added in bzrlib 0.92, used by VersionedFile.add_lines.
 
2191
 
 
2192
    _fmt = "The content being inserted is already present."
 
2193
 
 
2194
 
1622
2195
class ExistingLimbo(BzrError):
1623
2196
 
1624
2197
    _fmt = """This tree contains left-over files from a failed operation.
1626
2199
    keep, and delete it when you are done."""
1627
2200
 
1628
2201
    def __init__(self, limbo_dir):
1629
 
        BzrError.__init__(self)
1630
 
        self.limbo_dir = limbo_dir
 
2202
       BzrError.__init__(self)
 
2203
       self.limbo_dir = limbo_dir
1631
2204
 
1632
2205
 
1633
2206
class ExistingPendingDeletion(BzrError):
1637
2210
    wish to keep, and delete it when you are done."""
1638
2211
 
1639
2212
    def __init__(self, pending_deletion):
1640
 
        BzrError.__init__(self, pending_deletion=pending_deletion)
 
2213
       BzrError.__init__(self, pending_deletion=pending_deletion)
 
2214
 
 
2215
 
 
2216
class ImmortalLimbo(BzrError):
 
2217
 
 
2218
    _fmt = """Unable to delete transform temporary directory %(limbo_dir)s.
 
2219
    Please examine %(limbo_dir)s to see if it contains any files you wish to
 
2220
    keep, and delete it when you are done."""
 
2221
 
 
2222
    def __init__(self, limbo_dir):
 
2223
       BzrError.__init__(self)
 
2224
       self.limbo_dir = limbo_dir
1641
2225
 
1642
2226
 
1643
2227
class ImmortalPendingDeletion(BzrError):
1644
2228
 
1645
2229
    _fmt = ("Unable to delete transform temporary directory "
1646
 
            "%(pending_deletion)s.  Please examine %(pending_deletion)s to see if it "
1647
 
            "contains any files you wish to keep, and delete it when you are done.")
 
2230
    "%(pending_deletion)s.  Please examine %(pending_deletion)s to see if it "
 
2231
    "contains any files you wish to keep, and delete it when you are done.")
1648
2232
 
1649
2233
    def __init__(self, pending_deletion):
1650
 
        BzrError.__init__(self, pending_deletion=pending_deletion)
 
2234
       BzrError.__init__(self, pending_deletion=pending_deletion)
1651
2235
 
1652
2236
 
1653
2237
class OutOfDateTree(BzrError):
1654
2238
 
1655
 
    _fmt = "Working tree is out of date, please run 'brz update'.%(more)s"
 
2239
    _fmt = "Working tree is out of date, please run 'bzr update'.%(more)s"
1656
2240
 
1657
2241
    def __init__(self, tree, more=None):
1658
2242
        if more is None:
1670
2254
        '"%(revstring)s".'
1671
2255
 
1672
2256
    def __init__(self, public_location, revstring):
1673
 
        import breezy.urlutils as urlutils
 
2257
        import bzrlib.urlutils as urlutils
1674
2258
        public_location = urlutils.unescape_for_display(public_location,
1675
2259
                                                        'ascii')
1676
2260
        BzrError.__init__(self, public_location=public_location,
1687
2271
    _fmt = "Format error in conflict listings"
1688
2272
 
1689
2273
 
 
2274
class CorruptDirstate(BzrError):
 
2275
 
 
2276
    _fmt = ("Inconsistency in dirstate file %(dirstate_path)s.\n"
 
2277
            "Error: %(description)s")
 
2278
 
 
2279
    def __init__(self, dirstate_path, description):
 
2280
        BzrError.__init__(self)
 
2281
        self.dirstate_path = dirstate_path
 
2282
        self.description = description
 
2283
 
 
2284
 
1690
2285
class CorruptRepository(BzrError):
1691
2286
 
1692
2287
    _fmt = ("An error has been detected in the repository %(repo_path)s.\n"
1693
 
            "Please run brz reconcile on this repository.")
 
2288
            "Please run bzr reconcile on this repository.")
1694
2289
 
1695
2290
    def __init__(self, repo):
1696
2291
        BzrError.__init__(self)
1739
2334
class RichRootUpgradeRequired(UpgradeRequired):
1740
2335
 
1741
2336
    _fmt = ("To use this feature you must upgrade your branch at %(path)s to"
1742
 
            " a format which supports rich roots.")
 
2337
           " a format which supports rich roots.")
1743
2338
 
1744
2339
 
1745
2340
class LocalRequiresBoundBranch(BzrError):
1758
2353
        self.tname = type(method_self).__name__
1759
2354
 
1760
2355
 
1761
 
class FetchLimitUnsupported(UnsupportedOperation):
1762
 
 
1763
 
    fmt = ("InterBranch %(interbranch)r does not support fetching limits.")
1764
 
 
1765
 
    def __init__(self, interbranch):
1766
 
        BzrError.__init__(self, interbranch=interbranch)
 
2356
class CannotSetRevisionId(UnsupportedOperation):
 
2357
    """Raised when a commit is attempting to set a revision id but cant."""
1767
2358
 
1768
2359
 
1769
2360
class NonAsciiRevisionId(UnsupportedOperation):
1772
2363
    """
1773
2364
 
1774
2365
 
1775
 
class SharedRepositoriesUnsupported(UnsupportedOperation):
1776
 
    _fmt = "Shared repositories are not supported by %(format)r."
1777
 
 
1778
 
    def __init__(self, format):
1779
 
        BzrError.__init__(self, format=format)
1780
 
 
1781
 
 
1782
2366
class GhostTagsNotSupported(BzrError):
1783
2367
 
1784
2368
    _fmt = "Ghost tags not supported by format %(format)r."
1866
2450
        self.other = other
1867
2451
 
1868
2452
 
 
2453
class BadInventoryFormat(BzrError):
 
2454
 
 
2455
    _fmt = "Root class for inventory serialization errors"
 
2456
 
 
2457
 
 
2458
class UnexpectedInventoryFormat(BadInventoryFormat):
 
2459
 
 
2460
    _fmt = "The inventory was not in the expected format:\n %(msg)s"
 
2461
 
 
2462
    def __init__(self, msg):
 
2463
        BadInventoryFormat.__init__(self, msg=msg)
 
2464
 
 
2465
 
1869
2466
class RootNotRich(BzrError):
1870
2467
 
1871
2468
    _fmt = """This operation requires rich root data storage"""
1881
2478
 
1882
2479
class UnknownSSH(BzrError):
1883
2480
 
1884
 
    _fmt = "Unrecognised value for BRZ_SSH environment variable: %(vendor)s"
 
2481
    _fmt = "Unrecognised value for BZR_SSH environment variable: %(vendor)s"
1885
2482
 
1886
2483
    def __init__(self, vendor):
1887
2484
        BzrError.__init__(self)
1891
2488
class SSHVendorNotFound(BzrError):
1892
2489
 
1893
2490
    _fmt = ("Don't know how to handle SSH connections."
1894
 
            " Please set BRZ_SSH environment variable.")
 
2491
            " Please set BZR_SSH environment variable.")
1895
2492
 
1896
2493
 
1897
2494
class GhostRevisionsHaveNoRevno(BzrError):
1914
2511
        self.revision_id = revision_id
1915
2512
 
1916
2513
 
 
2514
class IllegalUseOfScopeReplacer(InternalBzrError):
 
2515
 
 
2516
    _fmt = ("ScopeReplacer object %(name)r was used incorrectly:"
 
2517
            " %(msg)s%(extra)s")
 
2518
 
 
2519
    def __init__(self, name, msg, extra=None):
 
2520
        BzrError.__init__(self)
 
2521
        self.name = name
 
2522
        self.msg = msg
 
2523
        if extra:
 
2524
            self.extra = ': ' + str(extra)
 
2525
        else:
 
2526
            self.extra = ''
 
2527
 
 
2528
 
 
2529
class InvalidImportLine(InternalBzrError):
 
2530
 
 
2531
    _fmt = "Not a valid import statement: %(msg)\n%(text)s"
 
2532
 
 
2533
    def __init__(self, text, msg):
 
2534
        BzrError.__init__(self)
 
2535
        self.text = text
 
2536
        self.msg = msg
 
2537
 
 
2538
 
 
2539
class ImportNameCollision(InternalBzrError):
 
2540
 
 
2541
    _fmt = ("Tried to import an object to the same name as"
 
2542
            " an existing object. %(name)s")
 
2543
 
 
2544
    def __init__(self, name):
 
2545
        BzrError.__init__(self)
 
2546
        self.name = name
 
2547
 
 
2548
 
1917
2549
class NotAMergeDirective(BzrError):
1918
2550
    """File starting with %(firstline)r is not a merge directive"""
1919
 
 
1920
2551
    def __init__(self, firstline):
1921
2552
        BzrError.__init__(self, firstline=firstline)
1922
2553
 
1928
2559
        " branch location."
1929
2560
 
1930
2561
 
 
2562
class IllegalMergeDirectivePayload(BzrError):
 
2563
    """A merge directive contained something other than a patch or bundle"""
 
2564
 
 
2565
    _fmt = "Bad merge directive payload %(start)r"
 
2566
 
 
2567
    def __init__(self, start):
 
2568
        BzrError(self)
 
2569
        self.start = start
 
2570
 
 
2571
 
1931
2572
class PatchVerificationFailed(BzrError):
1932
2573
    """A patch from a merge directive could not be verified"""
1933
2574
 
1957
2598
        self.location = location
1958
2599
 
1959
2600
 
 
2601
class UnsupportedInventoryKind(BzrError):
 
2602
 
 
2603
    _fmt = """Unsupported entry kind %(kind)s"""
 
2604
 
 
2605
    def __init__(self, kind):
 
2606
        self.kind = kind
 
2607
 
 
2608
 
1960
2609
class BadSubsumeSource(BzrError):
1961
2610
 
1962
2611
    _fmt = "Can't subsume %(other_tree)s into %(tree)s. %(reason)s"
1975
2624
        self.other_tree = other_tree
1976
2625
 
1977
2626
 
 
2627
class BadReferenceTarget(InternalBzrError):
 
2628
 
 
2629
    _fmt = "Can't add reference to %(other_tree)s into %(tree)s." \
 
2630
           "%(reason)s"
 
2631
 
 
2632
    def __init__(self, tree, other_tree, reason):
 
2633
        self.tree = tree
 
2634
        self.other_tree = other_tree
 
2635
        self.reason = reason
 
2636
 
 
2637
 
1978
2638
class NoSuchTag(BzrError):
1979
2639
 
1980
2640
    _fmt = "No such tag: %(tag_name)s"
1986
2646
class TagsNotSupported(BzrError):
1987
2647
 
1988
2648
    _fmt = ("Tags not supported by %(branch)s;"
1989
 
            " you may be able to use 'brz upgrade %(branch_url)s'.")
 
2649
            " you may be able to use bzr upgrade.")
1990
2650
 
1991
2651
    def __init__(self, branch):
1992
2652
        self.branch = branch
1993
 
        self.branch_url = branch.user_url
1994
2653
 
1995
2654
 
1996
2655
class TagAlreadyExists(BzrError):
2001
2660
        self.tag_name = tag_name
2002
2661
 
2003
2662
 
 
2663
class MalformedBugIdentifier(BzrError):
 
2664
 
 
2665
    _fmt = ('Did not understand bug identifier %(bug_id)s: %(reason)s. '
 
2666
            'See "bzr help bugs" for more information on this feature.')
 
2667
 
 
2668
    def __init__(self, bug_id, reason):
 
2669
        self.bug_id = bug_id
 
2670
        self.reason = reason
 
2671
 
 
2672
 
 
2673
class InvalidBugTrackerURL(BzrError):
 
2674
 
 
2675
    _fmt = ("The URL for bug tracker \"%(abbreviation)s\" doesn't "
 
2676
            "contain {id}: %(url)s")
 
2677
 
 
2678
    def __init__(self, abbreviation, url):
 
2679
        self.abbreviation = abbreviation
 
2680
        self.url = url
 
2681
 
 
2682
 
 
2683
class UnknownBugTrackerAbbreviation(BzrError):
 
2684
 
 
2685
    _fmt = ("Cannot find registered bug tracker called %(abbreviation)s "
 
2686
            "on %(branch)s")
 
2687
 
 
2688
    def __init__(self, abbreviation, branch):
 
2689
        self.abbreviation = abbreviation
 
2690
        self.branch = branch
 
2691
 
 
2692
 
 
2693
class InvalidLineInBugsProperty(BzrError):
 
2694
 
 
2695
    _fmt = ("Invalid line in bugs property: '%(line)s'")
 
2696
 
 
2697
    def __init__(self, line):
 
2698
        self.line = line
 
2699
 
 
2700
 
 
2701
class InvalidBugStatus(BzrError):
 
2702
 
 
2703
    _fmt = ("Invalid bug status: '%(status)s'")
 
2704
 
 
2705
    def __init__(self, status):
 
2706
        self.status = status
 
2707
 
 
2708
 
2004
2709
class UnexpectedSmartServerResponse(BzrError):
2005
2710
 
2006
2711
    _fmt = "Could not understand response from smart server: %(response_tuple)r"
2029
2734
 
2030
2735
 
2031
2736
class UnknownErrorFromSmartServer(BzrError):
2032
 
    """An ErrorFromSmartServer could not be translated into a typical breezy
 
2737
    """An ErrorFromSmartServer could not be translated into a typical bzrlib
2033
2738
    error.
2034
2739
 
2035
2740
    This is distinct from ErrorFromSmartServer so that it is possible to
2104
2809
        self.name = name.decode("utf-8")
2105
2810
 
2106
2811
 
 
2812
class NoDestinationAddress(InternalBzrError):
 
2813
 
 
2814
    _fmt = "Message does not have a destination address."
 
2815
 
 
2816
 
2107
2817
class RepositoryDataStreamError(BzrError):
2108
2818
 
2109
2819
    _fmt = "Corrupt or incompatible data stream: %(reason)s"
2112
2822
        self.reason = reason
2113
2823
 
2114
2824
 
 
2825
class SMTPError(BzrError):
 
2826
 
 
2827
    _fmt = "SMTP error: %(error)s"
 
2828
 
 
2829
    def __init__(self, error):
 
2830
        self.error = error
 
2831
 
 
2832
 
 
2833
class NoMessageSupplied(BzrError):
 
2834
 
 
2835
    _fmt = "No message supplied."
 
2836
 
 
2837
 
 
2838
class NoMailAddressSpecified(BzrError):
 
2839
 
 
2840
    _fmt = "No mail-to address (--mail-to) or output (-o) specified."
 
2841
 
 
2842
 
 
2843
class UnknownMailClient(BzrError):
 
2844
 
 
2845
    _fmt = "Unknown mail client: %(mail_client)s"
 
2846
 
 
2847
    def __init__(self, mail_client):
 
2848
        BzrError.__init__(self, mail_client=mail_client)
 
2849
 
 
2850
 
 
2851
class MailClientNotFound(BzrError):
 
2852
 
 
2853
    _fmt = "Unable to find mail client with the following names:"\
 
2854
        " %(mail_command_list_string)s"
 
2855
 
 
2856
    def __init__(self, mail_command_list):
 
2857
        mail_command_list_string = ', '.join(mail_command_list)
 
2858
        BzrError.__init__(self, mail_command_list=mail_command_list,
 
2859
                          mail_command_list_string=mail_command_list_string)
 
2860
 
 
2861
class SMTPConnectionRefused(SMTPError):
 
2862
 
 
2863
    _fmt = "SMTP connection to %(host)s refused"
 
2864
 
 
2865
    def __init__(self, error, host):
 
2866
        self.error = error
 
2867
        self.host = host
 
2868
 
 
2869
 
 
2870
class DefaultSMTPConnectionRefused(SMTPConnectionRefused):
 
2871
 
 
2872
    _fmt = "Please specify smtp_server.  No server at default %(host)s."
 
2873
 
 
2874
 
 
2875
class BzrDirError(BzrError):
 
2876
 
 
2877
    def __init__(self, bzrdir):
 
2878
        import bzrlib.urlutils as urlutils
 
2879
        display_url = urlutils.unescape_for_display(bzrdir.user_url,
 
2880
                                                    'ascii')
 
2881
        BzrError.__init__(self, bzrdir=bzrdir, display_url=display_url)
 
2882
 
 
2883
 
 
2884
class UnsyncedBranches(BzrDirError):
 
2885
 
 
2886
    _fmt = ("'%(display_url)s' is not in sync with %(target_url)s.  See"
 
2887
            " bzr help sync-for-reconfigure.")
 
2888
 
 
2889
    def __init__(self, bzrdir, target_branch):
 
2890
        BzrDirError.__init__(self, bzrdir)
 
2891
        import bzrlib.urlutils as urlutils
 
2892
        self.target_url = urlutils.unescape_for_display(target_branch.base,
 
2893
                                                        'ascii')
 
2894
 
 
2895
 
 
2896
class AlreadyBranch(BzrDirError):
 
2897
 
 
2898
    _fmt = "'%(display_url)s' is already a branch."
 
2899
 
 
2900
 
 
2901
class AlreadyTree(BzrDirError):
 
2902
 
 
2903
    _fmt = "'%(display_url)s' is already a tree."
 
2904
 
 
2905
 
 
2906
class AlreadyCheckout(BzrDirError):
 
2907
 
 
2908
    _fmt = "'%(display_url)s' is already a checkout."
 
2909
 
 
2910
 
 
2911
class AlreadyLightweightCheckout(BzrDirError):
 
2912
 
 
2913
    _fmt = "'%(display_url)s' is already a lightweight checkout."
 
2914
 
 
2915
 
 
2916
class AlreadyUsingShared(BzrDirError):
 
2917
 
 
2918
    _fmt = "'%(display_url)s' is already using a shared repository."
 
2919
 
 
2920
 
 
2921
class AlreadyStandalone(BzrDirError):
 
2922
 
 
2923
    _fmt = "'%(display_url)s' is already standalone."
 
2924
 
 
2925
 
 
2926
class AlreadyWithTrees(BzrDirError):
 
2927
 
 
2928
    _fmt = ("Shared repository '%(display_url)s' already creates "
 
2929
            "working trees.")
 
2930
 
 
2931
 
 
2932
class AlreadyWithNoTrees(BzrDirError):
 
2933
 
 
2934
    _fmt = ("Shared repository '%(display_url)s' already doesn't create "
 
2935
            "working trees.")
 
2936
 
 
2937
 
 
2938
class ReconfigurationNotSupported(BzrDirError):
 
2939
 
 
2940
    _fmt = "Requested reconfiguration of '%(display_url)s' is not supported."
 
2941
 
 
2942
 
 
2943
class NoBindLocation(BzrDirError):
 
2944
 
 
2945
    _fmt = "No location could be found to bind to at %(display_url)s."
 
2946
 
 
2947
 
2115
2948
class UncommittedChanges(BzrError):
2116
2949
 
2117
2950
    _fmt = ('Working tree "%(display_url)s" has uncommitted changes'
2118
 
            ' (See brz status).%(more)s')
 
2951
            ' (See bzr status).%(more)s')
2119
2952
 
2120
2953
    def __init__(self, tree, more=None):
2121
2954
        if more is None:
2122
2955
            more = ''
2123
2956
        else:
2124
2957
            more = ' ' + more
2125
 
        import breezy.urlutils as urlutils
 
2958
        import bzrlib.urlutils as urlutils
2126
2959
        user_url = getattr(tree, "user_url", None)
2127
2960
        if user_url is None:
2128
2961
            display_url = str(tree)
2131
2964
        BzrError.__init__(self, tree=tree, display_url=display_url, more=more)
2132
2965
 
2133
2966
 
2134
 
class StoringUncommittedNotSupported(BzrError):
2135
 
 
2136
 
    _fmt = ('Branch "%(display_url)s" does not support storing uncommitted'
2137
 
            ' changes.')
2138
 
 
2139
 
    def __init__(self, branch):
2140
 
        import breezy.urlutils as urlutils
2141
 
        user_url = getattr(branch, "user_url", None)
2142
 
        if user_url is None:
2143
 
            display_url = str(branch)
2144
 
        else:
2145
 
            display_url = urlutils.unescape_for_display(user_url, 'ascii')
2146
 
        BzrError.__init__(self, branch=branch, display_url=display_url)
2147
 
 
2148
 
 
2149
2967
class ShelvedChanges(UncommittedChanges):
2150
2968
 
2151
2969
    _fmt = ('Working tree "%(display_url)s" has shelved changes'
2152
 
            ' (See brz shelve --list).%(more)s')
 
2970
            ' (See bzr shelve --list).%(more)s')
 
2971
 
 
2972
 
 
2973
class MissingTemplateVariable(BzrError):
 
2974
 
 
2975
    _fmt = 'Variable {%(name)s} is not available.'
 
2976
 
 
2977
    def __init__(self, name):
 
2978
        self.name = name
 
2979
 
 
2980
 
 
2981
class NoTemplate(BzrError):
 
2982
 
 
2983
    _fmt = 'No template specified.'
 
2984
 
 
2985
 
 
2986
class UnableCreateSymlink(BzrError):
 
2987
 
 
2988
    _fmt = 'Unable to create symlink %(path_str)son this platform'
 
2989
 
 
2990
    def __init__(self, path=None):
 
2991
        path_str = ''
 
2992
        if path:
 
2993
            try:
 
2994
                path_str = repr(str(path))
 
2995
            except UnicodeEncodeError:
 
2996
                path_str = repr(path)
 
2997
            path_str += ' '
 
2998
        self.path_str = path_str
 
2999
 
 
3000
 
 
3001
class UnsupportedTimezoneFormat(BzrError):
 
3002
 
 
3003
    _fmt = ('Unsupported timezone format "%(timezone)s", '
 
3004
            'options are "utc", "original", "local".')
 
3005
 
 
3006
    def __init__(self, timezone):
 
3007
        self.timezone = timezone
 
3008
 
 
3009
 
 
3010
class CommandAvailableInPlugin(StandardError):
 
3011
 
 
3012
    internal_error = False
 
3013
 
 
3014
    def __init__(self, cmd_name, plugin_metadata, provider):
 
3015
 
 
3016
        self.plugin_metadata = plugin_metadata
 
3017
        self.cmd_name = cmd_name
 
3018
        self.provider = provider
 
3019
 
 
3020
    def __str__(self):
 
3021
 
 
3022
        _fmt = ('"%s" is not a standard bzr command. \n'
 
3023
                'However, the following official plugin provides this command: %s\n'
 
3024
                'You can install it by going to: %s'
 
3025
                % (self.cmd_name, self.plugin_metadata['name'],
 
3026
                    self.plugin_metadata['url']))
 
3027
 
 
3028
        return _fmt
 
3029
 
 
3030
 
 
3031
class NoPluginAvailable(BzrError):
 
3032
    pass
2153
3033
 
2154
3034
 
2155
3035
class UnableEncodePath(BzrError):
2158
3038
            'user encoding %(user_encoding)s')
2159
3039
 
2160
3040
    def __init__(self, path, kind):
2161
 
        from breezy.osutils import get_user_encoding
 
3041
        from bzrlib.osutils import get_user_encoding
2162
3042
        self.path = path
2163
3043
        self.kind = kind
2164
 
        self.user_encoding = get_user_encoding()
 
3044
        self.user_encoding = osutils.get_user_encoding()
 
3045
 
 
3046
 
 
3047
class NoSuchConfig(BzrError):
 
3048
 
 
3049
    _fmt = ('The "%(config_id)s" configuration does not exist.')
 
3050
 
 
3051
    def __init__(self, config_id):
 
3052
        BzrError.__init__(self, config_id=config_id)
 
3053
 
 
3054
 
 
3055
class NoSuchConfigOption(BzrError):
 
3056
 
 
3057
    _fmt = ('The "%(option_name)s" configuration option does not exist.')
 
3058
 
 
3059
    def __init__(self, option_name):
 
3060
        BzrError.__init__(self, option_name=option_name)
2165
3061
 
2166
3062
 
2167
3063
class NoSuchAlias(BzrError):
2172
3068
        BzrError.__init__(self, alias_name=alias_name)
2173
3069
 
2174
3070
 
 
3071
class DirectoryLookupFailure(BzrError):
 
3072
    """Base type for lookup errors."""
 
3073
 
 
3074
    pass
 
3075
 
 
3076
 
 
3077
class InvalidLocationAlias(DirectoryLookupFailure):
 
3078
 
 
3079
    _fmt = '"%(alias_name)s" is not a valid location alias.'
 
3080
 
 
3081
    def __init__(self, alias_name):
 
3082
        DirectoryLookupFailure.__init__(self, alias_name=alias_name)
 
3083
 
 
3084
 
 
3085
class UnsetLocationAlias(DirectoryLookupFailure):
 
3086
 
 
3087
    _fmt = 'No %(alias_name)s location assigned.'
 
3088
 
 
3089
    def __init__(self, alias_name):
 
3090
        DirectoryLookupFailure.__init__(self, alias_name=alias_name[1:])
 
3091
 
 
3092
 
2175
3093
class CannotBindAddress(BzrError):
2176
3094
 
2177
3095
    _fmt = 'Cannot bind address "%(host)s:%(port)i": %(orig_error)s.'
2179
3097
    def __init__(self, host, port, orig_error):
2180
3098
        # nb: in python2.4 socket.error doesn't have a useful repr
2181
3099
        BzrError.__init__(self, host=host, port=port,
2182
 
                          orig_error=repr(orig_error.args))
 
3100
            orig_error=repr(orig_error.args))
 
3101
 
 
3102
 
 
3103
class UnknownRules(BzrError):
 
3104
 
 
3105
    _fmt = ('Unknown rules detected: %(unknowns_str)s.')
 
3106
 
 
3107
    def __init__(self, unknowns):
 
3108
        BzrError.__init__(self, unknowns_str=", ".join(unknowns))
 
3109
 
 
3110
 
 
3111
class HookFailed(BzrError):
 
3112
    """Raised when a pre_change_branch_tip hook function fails anything other
 
3113
    than TipChangeRejected.
 
3114
 
 
3115
    Note that this exception is no longer raised, and the import is only left
 
3116
    to be nice to code which might catch it in a plugin.
 
3117
    """
 
3118
 
 
3119
    _fmt = ("Hook '%(hook_name)s' during %(hook_stage)s failed:\n"
 
3120
            "%(traceback_text)s%(exc_value)s")
 
3121
 
 
3122
    def __init__(self, hook_stage, hook_name, exc_info, warn=True):
 
3123
        if warn:
 
3124
            symbol_versioning.warn("BzrError HookFailed has been deprecated "
 
3125
                "as of bzrlib 2.1.", DeprecationWarning, stacklevel=2)
 
3126
        import traceback
 
3127
        self.hook_stage = hook_stage
 
3128
        self.hook_name = hook_name
 
3129
        self.exc_info = exc_info
 
3130
        self.exc_type = exc_info[0]
 
3131
        self.exc_value = exc_info[1]
 
3132
        self.exc_tb = exc_info[2]
 
3133
        self.traceback_text = ''.join(traceback.format_tb(self.exc_tb))
2183
3134
 
2184
3135
 
2185
3136
class TipChangeRejected(BzrError):
2193
3144
        self.msg = msg
2194
3145
 
2195
3146
 
 
3147
class ShelfCorrupt(BzrError):
 
3148
 
 
3149
    _fmt = "Shelf corrupt."
 
3150
 
 
3151
 
 
3152
class DecompressCorruption(BzrError):
 
3153
 
 
3154
    _fmt = "Corruption while decompressing repository file%(orig_error)s"
 
3155
 
 
3156
    def __init__(self, orig_error=None):
 
3157
        if orig_error is not None:
 
3158
            self.orig_error = ", %s" % (orig_error,)
 
3159
        else:
 
3160
            self.orig_error = ""
 
3161
        BzrError.__init__(self)
 
3162
 
 
3163
 
 
3164
class NoSuchShelfId(BzrError):
 
3165
 
 
3166
    _fmt = 'No changes are shelved with id "%(shelf_id)d".'
 
3167
 
 
3168
    def __init__(self, shelf_id):
 
3169
        BzrError.__init__(self, shelf_id=shelf_id)
 
3170
 
 
3171
 
 
3172
class InvalidShelfId(BzrError):
 
3173
 
 
3174
    _fmt = '"%(invalid_id)s" is not a valid shelf id, try a number instead.'
 
3175
 
 
3176
    def __init__(self, invalid_id):
 
3177
        BzrError.__init__(self, invalid_id=invalid_id)
 
3178
 
 
3179
 
2196
3180
class JailBreak(BzrError):
2197
3181
 
2198
3182
    _fmt = "An attempt to access a url outside the server jail was made: '%(url)s'."
2206
3190
    _fmt = 'The user aborted the operation.'
2207
3191
 
2208
3192
 
 
3193
class MustHaveWorkingTree(BzrError):
 
3194
 
 
3195
    _fmt = ("Branching '%(url)s'(%(format)s) must create a working tree.")
 
3196
 
 
3197
    def __init__(self, format, url):
 
3198
        BzrError.__init__(self, format=format, url=url)
 
3199
 
 
3200
 
 
3201
class NoSuchView(BzrError):
 
3202
    """A view does not exist.
 
3203
    """
 
3204
 
 
3205
    _fmt = u"No such view: %(view_name)s."
 
3206
 
 
3207
    def __init__(self, view_name):
 
3208
        self.view_name = view_name
 
3209
 
 
3210
 
 
3211
class ViewsNotSupported(BzrError):
 
3212
    """Views are not supported by a tree format.
 
3213
    """
 
3214
 
 
3215
    _fmt = ("Views are not supported by %(tree)s;"
 
3216
            " use 'bzr upgrade' to change your tree to a later format.")
 
3217
 
 
3218
    def __init__(self, tree):
 
3219
        self.tree = tree
 
3220
 
 
3221
 
 
3222
class FileOutsideView(BzrError):
 
3223
 
 
3224
    _fmt = ('Specified file "%(file_name)s" is outside the current view: '
 
3225
            '%(view_str)s')
 
3226
 
 
3227
    def __init__(self, file_name, view_files):
 
3228
        self.file_name = file_name
 
3229
        self.view_str = ", ".join(view_files)
 
3230
 
 
3231
 
2209
3232
class UnresumableWriteGroup(BzrError):
2210
3233
 
2211
3234
    _fmt = ("Repository %(repository)s cannot resume write group "
2253
3276
        self.target_branch = target_branch
2254
3277
 
2255
3278
 
 
3279
class FileTimestampUnavailable(BzrError):
 
3280
 
 
3281
    _fmt = "The filestamp for %(path)s is not available."
 
3282
 
 
3283
    internal_error = True
 
3284
 
 
3285
    def __init__(self, path):
 
3286
        self.path = path
 
3287
 
 
3288
 
2256
3289
class NoColocatedBranchSupport(BzrError):
2257
3290
 
2258
 
    _fmt = ("%(controldir)r does not support co-located branches.")
2259
 
 
2260
 
    def __init__(self, controldir):
2261
 
        self.controldir = controldir
 
3291
    _fmt = ("%(bzrdir)r does not support co-located branches.")
 
3292
 
 
3293
    def __init__(self, bzrdir):
 
3294
        self.bzrdir = bzrdir
 
3295
 
 
3296
 
 
3297
class NoWhoami(BzrError):
 
3298
 
 
3299
    _fmt = ('Unable to determine your name.\n'
 
3300
        "Please, set your name with the 'whoami' command.\n"
 
3301
        'E.g. bzr whoami "Your Name <name@example.com>"')
 
3302
 
 
3303
 
 
3304
class InvalidPattern(BzrError):
 
3305
 
 
3306
    _fmt = ('Invalid pattern(s) found. %(msg)s')
 
3307
 
 
3308
    def __init__(self, msg):
 
3309
        self.msg = msg
2262
3310
 
2263
3311
 
2264
3312
class RecursiveBind(BzrError):
2265
3313
 
2266
3314
    _fmt = ('Branch "%(branch_url)s" appears to be bound to itself. '
2267
 
            'Please use `brz unbind` to fix.')
 
3315
        'Please use `bzr unbind` to fix.')
2268
3316
 
2269
3317
    def __init__(self, branch_url):
2270
3318
        self.branch_url = branch_url
2271
3319
 
2272
3320
 
 
3321
# FIXME: I would prefer to define the config related exception classes in
 
3322
# config.py but the lazy import mechanism proscribes this -- vila 20101222
 
3323
class OptionExpansionLoop(BzrError):
 
3324
 
 
3325
    _fmt = 'Loop involving %(refs)r while expanding "%(string)s".'
 
3326
 
 
3327
    def __init__(self, string, refs):
 
3328
        self.string = string
 
3329
        self.refs = '->'.join(refs)
 
3330
 
 
3331
 
 
3332
class ExpandingUnknownOption(BzrError):
 
3333
 
 
3334
    _fmt = 'Option %(name)s is not defined while expanding "%(string)s".'
 
3335
 
 
3336
    def __init__(self, name, string):
 
3337
        self.name = name
 
3338
        self.string = string
 
3339
 
 
3340
 
 
3341
class NoCompatibleInter(BzrError):
 
3342
 
 
3343
    _fmt = ('No compatible object available for operations from %(source)r '
 
3344
            'to %(target)r.')
 
3345
 
 
3346
    def __init__(self, source, target):
 
3347
        self.source = source
 
3348
        self.target = target
 
3349
 
 
3350
 
 
3351
class HpssVfsRequestNotAllowed(BzrError):
 
3352
 
 
3353
    _fmt = ("VFS requests over the smart server are not allowed. Encountered: "
 
3354
            "%(method)s, %(arguments)s.")
 
3355
 
 
3356
    def __init__(self, method, arguments):
 
3357
        self.method = method
 
3358
        self.arguments = arguments
 
3359
 
 
3360
 
2273
3361
class UnsupportedKindChange(BzrError):
2274
3362
 
2275
3363
    _fmt = ("Kind change from %(from_kind)s to %(to_kind)s for "
2280
3368
        self.from_kind = from_kind
2281
3369
        self.to_kind = to_kind
2282
3370
        self.format = format
2283
 
 
2284
 
 
2285
 
class ChangesAlreadyStored(CommandError):
2286
 
 
2287
 
    _fmt = ('Cannot store uncommitted changes because this branch already'
2288
 
            ' stores uncommitted changes.')
2289
 
 
2290
 
 
2291
 
class RevnoOutOfBounds(InternalBzrError):
2292
 
 
2293
 
    _fmt = ("The requested revision number %(revno)d is outside of the "
2294
 
            "expected boundaries (%(minimum)d <= %(maximum)d).")
2295
 
 
2296
 
    def __init__(self, revno, bounds):
2297
 
        InternalBzrError.__init__(
2298
 
            self, revno=revno, minimum=bounds[0], maximum=bounds[1])