/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: Ian Clatworthy
  • Date: 2008-07-17 01:08:21 UTC
  • mto: This revision was merged to the branch mainline in revision 3546.
  • Revision ID: ian.clatworthy@canonical.com-20080717010821-qg05ah7iobvl8hin
workaround docutils dot-in-option name bug (Mark Hammond)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005-2013, 2016 Canonical Ltd
 
1
# Copyright (C) 2005, 2006, 2007, 2008 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
12
12
#
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
 
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
16
 
17
17
"""Exceptions for bzr, and reporting of them.
18
18
"""
19
19
 
20
 
from __future__ import absolute_import
21
 
 
22
 
from .sixish import (
23
 
    PY3,
24
 
    )
 
20
 
 
21
from bzrlib import (
 
22
    osutils,
 
23
    symbol_versioning,
 
24
    )
 
25
from bzrlib.patches import (
 
26
    MalformedHunkHeader,
 
27
    MalformedLine,
 
28
    MalformedPatchHeader,
 
29
    PatchConflict,
 
30
    PatchSyntax,
 
31
    )
 
32
 
25
33
 
26
34
# TODO: is there any value in providing the .args field used by standard
27
 
# python exceptions?   A list of values with no names seems less useful
 
35
# python exceptions?   A list of values with no names seems less useful 
28
36
# to me.
29
37
 
30
 
# TODO: Perhaps convert the exception to a string at the moment it's
 
38
# TODO: Perhaps convert the exception to a string at the moment it's 
31
39
# constructed to make sure it will succeed.  But that says nothing about
32
40
# exceptions that are never raised.
33
41
 
36
44
# 'unprintable'.
37
45
 
38
46
 
39
 
# return codes from the brz program
 
47
# return codes from the bzr program
40
48
EXIT_OK = 0
41
49
EXIT_ERROR = 3
42
50
EXIT_INTERNAL_ERROR = 4
43
51
 
44
52
 
45
 
class BzrError(Exception):
 
53
class BzrError(StandardError):
46
54
    """
47
 
    Base class for errors raised by breezy.
 
55
    Base class for errors raised by bzrlib.
48
56
 
49
 
    :cvar internal_error: if True this was probably caused by a brz bug and
50
 
        should be displayed with a traceback; if False (or absent) this was
51
 
        probably a user or environment error and they don't need the gory
52
 
        details.  (That can be overridden by -Derror on the command line.)
 
57
    :cvar internal_error: if True this was probably caused by a bzr bug and
 
58
    should be displayed with a traceback; if False (or absent) this was
 
59
    probably a user or environment error and they don't need the gory details.
 
60
    (That can be overridden by -Derror on the command line.)
53
61
 
54
62
    :cvar _fmt: Format string to display the error; this is expanded
55
 
        by the instance's dict.
 
63
    by the instance's dict.
56
64
    """
57
 
 
 
65
    
58
66
    internal_error = False
59
67
 
60
68
    def __init__(self, msg=None, **kwds):
65
73
        arguments can be given.  The first is for generic "user" errors which
66
74
        are not intended to be caught and so do not need a specific subclass.
67
75
        The second case is for use with subclasses that provide a _fmt format
68
 
        string to print the arguments.
 
76
        string to print the arguments.  
69
77
 
70
 
        Keyword arguments are taken as parameters to the error, which can
71
 
        be inserted into the format string template.  It's recommended
72
 
        that subclasses override the __init__ method to require specific
 
78
        Keyword arguments are taken as parameters to the error, which can 
 
79
        be inserted into the format string template.  It's recommended 
 
80
        that subclasses override the __init__ method to require specific 
73
81
        parameters.
74
82
 
75
83
        :param msg: If given, this is the literal complete text for the error,
76
 
           not subject to expansion. 'msg' is used instead of 'message' because
77
 
           python evolved and, in 2.6, forbids the use of 'message'.
 
84
        not subject to expansion.
78
85
        """
79
 
        Exception.__init__(self)
 
86
        StandardError.__init__(self)
80
87
        if msg is not None:
81
88
            # I was going to deprecate this, but it actually turns out to be
82
89
            # quite handy - mbp 20061103.
86
93
            for key, value in kwds.items():
87
94
                setattr(self, key, value)
88
95
 
89
 
    def _format(self):
 
96
    def __str__(self):
90
97
        s = getattr(self, '_preformatted_string', None)
91
98
        if s is not None:
92
 
            # contains a preformatted message
93
 
            return s
94
 
        err = None
 
99
            # contains a preformatted message; must be cast to plain str
 
100
            return str(s)
95
101
        try:
96
102
            fmt = self._get_format_string()
97
103
            if fmt:
98
104
                d = dict(self.__dict__)
 
105
                # special case: python2.5 puts the 'message' attribute in a
 
106
                # slot, so it isn't seen in __dict__
 
107
                d['message'] = getattr(self, 'message', 'no message')
99
108
                s = fmt % d
100
109
                # __str__() should always return a 'str' object
101
110
                # never a 'unicode' object.
 
111
                if isinstance(s, unicode):
 
112
                    return s.encode('utf8')
102
113
                return s
103
 
        except Exception as e:
104
 
            err = e
105
 
        return 'Unprintable exception %s: dict=%r, fmt=%r, error=%r' \
 
114
        except (AttributeError, TypeError, NameError, ValueError, KeyError), e:
 
115
            return 'Unprintable exception %s: dict=%r, fmt=%r, error=%r' \
 
116
                % (self.__class__.__name__,
 
117
                   self.__dict__,
 
118
                   getattr(self, '_fmt', None),
 
119
                   e)
 
120
 
 
121
    def _get_format_string(self):
 
122
        """Return format string for this exception or None"""
 
123
        fmt = getattr(self, '_fmt', None)
 
124
        if fmt is not None:
 
125
            return fmt
 
126
        fmt = getattr(self, '__doc__', None)
 
127
        if fmt is not None:
 
128
            symbol_versioning.warn("%s uses its docstring as a format, "
 
129
                    "it should use _fmt instead" % self.__class__.__name__,
 
130
                    DeprecationWarning)
 
131
            return fmt
 
132
        return 'Unprintable exception %s: dict=%r, fmt=%r' \
106
133
            % (self.__class__.__name__,
107
134
               self.__dict__,
108
135
               getattr(self, '_fmt', None),
109
 
               err)
110
 
 
111
 
    if PY3:
112
 
        __str__ = _format
113
 
    else:
114
 
        def __str__(self):
115
 
            return self._format().encode('utf-8')
116
 
 
117
 
        __unicode__ = _format
118
 
 
119
 
    def __repr__(self):
120
 
        return '%s(%s)' % (self.__class__.__name__, str(self))
121
 
 
122
 
    def _get_format_string(self):
123
 
        """Return format string for this exception or None"""
124
 
        fmt = getattr(self, '_fmt', None)
125
 
        if fmt is not None:
126
 
            from breezy.i18n import gettext
127
 
            return gettext(fmt) # _fmt strings should be ascii
128
 
 
129
 
    def __eq__(self, other):
130
 
        if self.__class__ is not other.__class__:
131
 
            return NotImplemented
132
 
        return self.__dict__ == other.__dict__
133
 
 
134
 
    def __hash__(self):
135
 
        return id(self)
 
136
               )
136
137
 
137
138
 
138
139
class InternalBzrError(BzrError):
146
147
    internal_error = True
147
148
 
148
149
 
 
150
class BzrNewError(BzrError):
 
151
    """Deprecated error base class."""
 
152
    # base classes should override the docstring with their human-
 
153
    # readable explanation
 
154
 
 
155
    def __init__(self, *args, **kwds):
 
156
        # XXX: Use the underlying BzrError to always generate the args
 
157
        # attribute if it doesn't exist.  We can't use super here, because
 
158
        # exceptions are old-style classes in python2.4 (but new in 2.5).
 
159
        # --bmc, 20060426
 
160
        symbol_versioning.warn('BzrNewError was deprecated in bzr 0.13; '
 
161
             'please convert %s to use BzrError instead'
 
162
             % self.__class__.__name__,
 
163
             DeprecationWarning,
 
164
             stacklevel=2)
 
165
        BzrError.__init__(self, *args)
 
166
        for key, value in kwds.items():
 
167
            setattr(self, key, value)
 
168
 
 
169
    def __str__(self):
 
170
        try:
 
171
            # __str__() should always return a 'str' object
 
172
            # never a 'unicode' object.
 
173
            s = self.__doc__ % self.__dict__
 
174
            if isinstance(s, unicode):
 
175
                return s.encode('utf8')
 
176
            return s
 
177
        except (TypeError, NameError, ValueError, KeyError), e:
 
178
            return 'Unprintable exception %s(%r): %r' \
 
179
                % (self.__class__.__name__,
 
180
                   self.__dict__, e)
 
181
 
 
182
 
 
183
class AlreadyBuilding(BzrError):
 
184
    
 
185
    _fmt = "The tree builder is already building a tree."
 
186
 
 
187
 
149
188
class BranchError(BzrError):
150
189
    """Base class for concrete 'errors about a branch'."""
151
190
 
154
193
 
155
194
 
156
195
class BzrCheckError(InternalBzrError):
157
 
 
158
 
    _fmt = "Internal check failed: %(msg)s"
159
 
 
160
 
    def __init__(self, msg):
161
 
        BzrError.__init__(self)
162
 
        self.msg = msg
163
 
 
164
 
 
165
 
class IncompatibleVersion(BzrError):
166
 
 
167
 
    _fmt = 'API %(api)s is not compatible; one of versions %(wanted)r '\
168
 
           'is required, but current version is %(current)r.'
169
 
 
170
 
    def __init__(self, api, wanted, current):
 
196
    
 
197
    _fmt = "Internal check failed: %(message)s"
 
198
 
 
199
    def __init__(self, message):
 
200
        BzrError.__init__(self)
 
201
        self.message = message
 
202
 
 
203
 
 
204
class DisabledMethod(InternalBzrError):
 
205
 
 
206
    _fmt = "The smart server method '%(class_name)s' is disabled."
 
207
 
 
208
    def __init__(self, class_name):
 
209
        BzrError.__init__(self)
 
210
        self.class_name = class_name
 
211
 
 
212
 
 
213
class IncompatibleAPI(BzrError):
 
214
 
 
215
    _fmt = 'The API for "%(api)s" is not compatible with "%(wanted)s". '\
 
216
        'It supports versions "%(minimum)s" to "%(current)s".'
 
217
 
 
218
    def __init__(self, api, wanted, minimum, current):
171
219
        self.api = api
172
220
        self.wanted = wanted
 
221
        self.minimum = minimum
173
222
        self.current = current
174
223
 
175
224
 
183
232
 
184
233
 
185
234
class InvalidEntryName(InternalBzrError):
186
 
 
 
235
    
187
236
    _fmt = "Invalid entry name: %(name)s"
188
237
 
189
238
    def __init__(self, name):
192
241
 
193
242
 
194
243
class InvalidRevisionNumber(BzrError):
195
 
 
 
244
    
196
245
    _fmt = "Invalid revision number %(revno)s"
197
246
 
198
247
    def __init__(self, revno):
222
271
class RootMissing(InternalBzrError):
223
272
 
224
273
    _fmt = ("The root entry of a tree must be the first entry supplied to "
225
 
        "the commit builder.")
 
274
        "record_entry_contents.")
226
275
 
227
276
 
228
277
class NoPublicBranch(BzrError):
230
279
    _fmt = 'There is no public branch set for "%(branch_url)s".'
231
280
 
232
281
    def __init__(self, branch):
233
 
        from . import urlutils
 
282
        import bzrlib.urlutils as urlutils
234
283
        public_location = urlutils.unescape_for_display(branch.base, 'ascii')
235
284
        BzrError.__init__(self, branch_url=public_location)
236
285
 
237
286
 
 
287
class NoHelpTopic(BzrError):
 
288
 
 
289
    _fmt = ("No help could be found for '%(topic)s'. "
 
290
        "Please use 'bzr help topics' to obtain a list of topics.")
 
291
 
 
292
    def __init__(self, topic):
 
293
        self.topic = topic
 
294
 
 
295
 
238
296
class NoSuchId(BzrError):
239
297
 
240
298
    _fmt = 'The file id "%(file_id)s" is not present in the tree %(tree)s.'
241
 
 
 
299
    
242
300
    def __init__(self, tree, file_id):
243
301
        BzrError.__init__(self)
244
302
        self.file_id = file_id
245
303
        self.tree = tree
246
304
 
247
305
 
 
306
class NoSuchIdInRepository(NoSuchId):
 
307
 
 
308
    _fmt = ('The file id "%(file_id)s" is not present in the repository'
 
309
            ' %(repository)r')
 
310
 
 
311
    def __init__(self, repository, file_id):
 
312
        BzrError.__init__(self, repository=repository, file_id=file_id)
 
313
 
 
314
 
248
315
class NotStacked(BranchError):
249
316
 
250
317
    _fmt = "The branch '%(branch)s' is not stacked."
262
329
class NoWorkingTree(BzrError):
263
330
 
264
331
    _fmt = 'No WorkingTree exists for "%(base)s".'
265
 
 
 
332
    
266
333
    def __init__(self, base):
267
334
        BzrError.__init__(self)
268
335
        self.base = base
269
336
 
270
337
 
 
338
class NotBuilding(BzrError):
 
339
 
 
340
    _fmt = "Not currently building a tree."
 
341
 
 
342
 
271
343
class NotLocalUrl(BzrError):
272
344
 
273
345
    _fmt = "%(url)s is not a local path."
294
366
    # are not intended to be caught anyway.  UI code need not subclass
295
367
    # BzrCommandError, and non-UI code should not throw a subclass of
296
368
    # BzrCommandError.  ADHB 20051211
 
369
    def __init__(self, msg):
 
370
        # Object.__str__() must return a real string
 
371
        # returning a Unicode string is a python error.
 
372
        if isinstance(msg, unicode):
 
373
            self.msg = msg.encode('utf8')
 
374
        else:
 
375
            self.msg = msg
 
376
 
 
377
    def __str__(self):
 
378
        return self.msg
297
379
 
298
380
 
299
381
class NotWriteLocked(BzrError):
304
386
        self.not_locked = not_locked
305
387
 
306
388
 
 
389
class BzrOptionError(BzrCommandError):
 
390
 
 
391
    _fmt = "Error in command line options"
 
392
 
 
393
 
 
394
class BadIndexFormatSignature(BzrError):
 
395
 
 
396
    _fmt = "%(value)s is not an index of type %(_type)s."
 
397
 
 
398
    def __init__(self, value, _type):
 
399
        BzrError.__init__(self)
 
400
        self.value = value
 
401
        self._type = _type
 
402
 
 
403
 
 
404
class BadIndexData(BzrError):
 
405
 
 
406
    _fmt = "Error in data for index %(value)s."
 
407
 
 
408
    def __init__(self, value):
 
409
        BzrError.__init__(self)
 
410
        self.value = value
 
411
 
 
412
 
 
413
class BadIndexDuplicateKey(BzrError):
 
414
 
 
415
    _fmt = "The key '%(key)s' is already in index '%(index)s'."
 
416
 
 
417
    def __init__(self, key, index):
 
418
        BzrError.__init__(self)
 
419
        self.key = key
 
420
        self.index = index
 
421
 
 
422
 
 
423
class BadIndexKey(BzrError):
 
424
 
 
425
    _fmt = "The key '%(key)s' is not a valid key."
 
426
 
 
427
    def __init__(self, key):
 
428
        BzrError.__init__(self)
 
429
        self.key = key
 
430
 
 
431
 
 
432
class BadIndexOptions(BzrError):
 
433
 
 
434
    _fmt = "Could not parse options for index %(value)s."
 
435
 
 
436
    def __init__(self, value):
 
437
        BzrError.__init__(self)
 
438
        self.value = value
 
439
 
 
440
 
 
441
class BadIndexValue(BzrError):
 
442
 
 
443
    _fmt = "The value '%(value)s' is not a valid value."
 
444
 
 
445
    def __init__(self, value):
 
446
        BzrError.__init__(self)
 
447
        self.value = value
 
448
 
 
449
 
 
450
class BadOptionValue(BzrError):
 
451
 
 
452
    _fmt = """Bad value "%(value)s" for option "%(name)s"."""
 
453
 
 
454
    def __init__(self, name, value):
 
455
        BzrError.__init__(self, name=name, value=value)
 
456
 
 
457
    
307
458
class StrictCommitFailed(BzrError):
308
459
 
309
460
    _fmt = "Commit refused because there are unknown files in the tree"
312
463
# XXX: Should be unified with TransportError; they seem to represent the
313
464
# same thing
314
465
# RBC 20060929: I think that unifiying with TransportError would be a mistake
315
 
# - this is finer than a TransportError - and more useful as such. It
 
466
# - this is finer than a TransportError - and more useful as such. It 
316
467
# differentiates between 'transport has failed' and 'operation on a transport
317
468
# has failed.'
318
469
class PathError(BzrError):
319
 
 
 
470
    
320
471
    _fmt = "Generic path error: %(path)r%(extra)s)"
321
472
 
322
473
    def __init__(self, path, extra=None):
342
493
    """Used when renaming and both source and dest exist."""
343
494
 
344
495
    _fmt = ("Could not rename %(source)s => %(dest)s because both files exist."
345
 
            " (Use --after to tell brz about a rename that has already"
 
496
            " (Use --after to tell bzr about a rename that has already"
346
497
            " happened)%(extra)s")
347
498
 
348
499
    def __init__(self, source, dest, extra=None):
376
527
 
377
528
 
378
529
class ReadingCompleted(InternalBzrError):
379
 
 
 
530
    
380
531
    _fmt = ("The MediumRequest '%(request)s' has already had finish_reading "
381
532
            "called upon it - the request has been completed and no more "
382
533
            "data may be read.")
395
546
    _fmt = 'Permission denied: "%(path)s"%(extra)s'
396
547
 
397
548
 
 
549
class InvalidURL(PathError):
 
550
 
 
551
    _fmt = 'Invalid url supplied to transport: "%(path)s"%(extra)s'
 
552
 
 
553
 
 
554
class InvalidURLJoin(PathError):
 
555
 
 
556
    _fmt = "Invalid URL join request: %(reason)s: %(base)r + %(join_args)r"
 
557
 
 
558
    def __init__(self, reason, base, join_args):
 
559
        self.reason = reason
 
560
        self.base = base
 
561
        self.join_args = join_args
 
562
        PathError.__init__(self, base, reason)
 
563
 
 
564
 
 
565
class InvalidRebaseURLs(PathError):
 
566
 
 
567
    _fmt = "URLs differ by more than path: %(from_)r and %(to)r"
 
568
 
 
569
    def __init__(self, from_, to):
 
570
        self.from_ = from_
 
571
        self.to = to
 
572
        PathError.__init__(self, from_, 'URLs differ by more than path.')
 
573
 
 
574
 
398
575
class UnavailableRepresentation(InternalBzrError):
399
576
 
400
577
    _fmt = ("The encoding '%(wanted)s' is not available for key %(key)s which "
407
584
        self.key = key
408
585
 
409
586
 
 
587
class UnknownHook(BzrError):
 
588
 
 
589
    _fmt = "The %(type)s hook '%(hook)s' is unknown in this version of bzrlib."
 
590
 
 
591
    def __init__(self, hook_type, hook_name):
 
592
        BzrError.__init__(self)
 
593
        self.type = hook_type
 
594
        self.hook = hook_name
 
595
 
 
596
 
410
597
class UnsupportedProtocol(PathError):
411
598
 
412
599
    _fmt = 'Unsupported protocol for url "%(path)s"%(extra)s'
413
600
 
414
 
    def __init__(self, url, extra=""):
 
601
    def __init__(self, url, extra):
415
602
        PathError.__init__(self, url, extra=extra)
416
603
 
417
604
 
418
 
class UnstackableLocationError(BzrError):
419
 
 
420
 
    _fmt = "The branch '%(branch_url)s' cannot be stacked on '%(target_url)s'."
421
 
 
422
 
    def __init__(self, branch_url, target_url):
 
605
class UnstackableBranchFormat(BzrError):
 
606
 
 
607
    _fmt = ("The branch '%(url)s'(%(format)s) is not a stackable format. "
 
608
        "You will need to upgrade the branch to permit branch stacking.")
 
609
 
 
610
    def __init__(self, format, url):
423
611
        BzrError.__init__(self)
424
 
        self.branch_url = branch_url
425
 
        self.target_url = target_url
 
612
        self.format = format
 
613
        self.url = url
426
614
 
427
615
 
428
616
class UnstackableRepositoryFormat(BzrError):
437
625
 
438
626
 
439
627
class ReadError(PathError):
440
 
 
 
628
    
441
629
    _fmt = """Error reading from %(path)r."""
442
630
 
443
631
 
459
647
 
460
648
    _fmt = 'Path "%(path)s" is not a child of path "%(base)s"%(extra)s'
461
649
 
462
 
    internal_error = False
 
650
    internal_error = True
463
651
 
464
652
    def __init__(self, path, base, extra=None):
465
653
        BzrError.__init__(self)
478
666
 
479
667
# TODO: This is given a URL; we try to unescape it but doing that from inside
480
668
# the exception object is a bit undesirable.
481
 
# TODO: Probably this behavior of should be a common superclass
 
669
# TODO: Probably this behavior of should be a common superclass 
482
670
class NotBranchError(PathError):
483
671
 
484
 
    _fmt = 'Not a branch: "%(path)s"%(detail)s.'
485
 
 
486
 
    def __init__(self, path, detail=None, controldir=None):
487
 
       from . import urlutils
488
 
       path = urlutils.unescape_for_display(path, 'ascii')
489
 
       if detail is not None:
490
 
           detail = ': ' + detail
491
 
       self.detail = detail
492
 
       self.controldir = controldir
493
 
       PathError.__init__(self, path=path)
494
 
 
495
 
    def __repr__(self):
496
 
        return '<%s %r>' % (self.__class__.__name__, self.__dict__)
497
 
 
498
 
    def _get_format_string(self):
499
 
        # GZ 2017-06-08: Not the best place to lazy fill detail in.
500
 
        if self.detail is None:
501
 
           self.detail = self._get_detail()
502
 
        return super(NotBranchError, self)._get_format_string()
503
 
 
504
 
    def _get_detail(self):
505
 
        if self.controldir is not None:
506
 
            try:
507
 
                self.controldir.open_repository()
508
 
            except NoRepositoryPresent:
509
 
                return ''
510
 
            except Exception as e:
511
 
                # Just ignore unexpected errors.  Raising arbitrary errors
512
 
                # during str(err) can provoke strange bugs.  Concretely
513
 
                # Launchpad's codehosting managed to raise NotBranchError
514
 
                # here, and then get stuck in an infinite loop/recursion
515
 
                # trying to str() that error.  All this error really cares
516
 
                # about that there's no working repository there, and if
517
 
                # open_repository() fails, there probably isn't.
518
 
                return ': ' + e.__class__.__name__
519
 
            else:
520
 
                return ': location is a repository'
521
 
        return ''
 
672
    _fmt = 'Not a branch: "%(path)s".'
 
673
 
 
674
    def __init__(self, path):
 
675
       import bzrlib.urlutils as urlutils
 
676
       self.path = urlutils.unescape_for_display(path, 'ascii')
522
677
 
523
678
 
524
679
class NoSubmitBranch(PathError):
526
681
    _fmt = 'No submit branch available for branch "%(path)s"'
527
682
 
528
683
    def __init__(self, branch):
529
 
       from . import urlutils
 
684
       import bzrlib.urlutils as urlutils
530
685
       self.path = urlutils.unescape_for_display(branch.base, 'ascii')
531
686
 
532
687
 
533
 
class AlreadyControlDirError(PathError):
534
 
 
535
 
    _fmt = 'A control directory already exists: "%(path)s".'
536
 
 
537
 
 
538
688
class AlreadyBranchError(PathError):
539
689
 
540
690
    _fmt = 'Already a branch: "%(path)s".'
541
691
 
542
692
 
543
 
class InvalidBranchName(PathError):
544
 
 
545
 
    _fmt = "Invalid branch name: %(name)s"
546
 
 
547
 
    def __init__(self, name):
548
 
        BzrError.__init__(self)
549
 
        self.name = name
550
 
 
551
 
 
552
 
class ParentBranchExists(AlreadyBranchError):
553
 
 
554
 
    _fmt = 'Parent branch already exists: "%(path)s".'
555
 
 
556
 
 
557
693
class BranchExistsWithoutWorkingTree(PathError):
558
694
 
559
695
    _fmt = 'Directory contains a branch, but no working tree \
560
 
(use brz checkout if you wish to build a working tree): "%(path)s"'
 
696
(use bzr checkout if you wish to build a working tree): "%(path)s"'
 
697
 
 
698
 
 
699
class AtomicFileAlreadyClosed(PathError):
 
700
 
 
701
    _fmt = ('"%(function)s" called on an AtomicFile after it was closed:'
 
702
            ' "%(path)s"')
 
703
 
 
704
    def __init__(self, path, function):
 
705
        PathError.__init__(self, path=path, extra=None)
 
706
        self.function = function
561
707
 
562
708
 
563
709
class InaccessibleParent(PathError):
573
719
class NoRepositoryPresent(BzrError):
574
720
 
575
721
    _fmt = 'No repository present: "%(path)s"'
576
 
    def __init__(self, controldir):
577
 
        BzrError.__init__(self)
578
 
        self.path = controldir.transport.clone('..').base
 
722
    def __init__(self, bzrdir):
 
723
        BzrError.__init__(self)
 
724
        self.path = bzrdir.transport.clone('..').base
 
725
 
 
726
 
 
727
class FileInWrongBranch(BzrError):
 
728
 
 
729
    _fmt = 'File "%(path)s" is not in branch %(branch_base)s.'
 
730
 
 
731
    def __init__(self, branch, path):
 
732
        BzrError.__init__(self)
 
733
        self.branch = branch
 
734
        self.branch_base = branch.base
 
735
        self.path = path
579
736
 
580
737
 
581
738
class UnsupportedFormatError(BzrError):
582
739
 
583
 
    _fmt = "Unsupported branch format: %(format)s\nPlease run 'brz upgrade'"
 
740
    _fmt = "Unsupported branch format: %(format)s\nPlease run 'bzr upgrade'"
584
741
 
585
742
 
586
743
class UnknownFormatError(BzrError):
587
 
 
 
744
    
588
745
    _fmt = "Unknown %(kind)s format: %(format)r"
589
746
 
590
747
    def __init__(self, format, kind='branch'):
593
750
 
594
751
 
595
752
class IncompatibleFormat(BzrError):
596
 
 
597
 
    _fmt = "Format %(format)s is not compatible with .bzr version %(controldir)s."
598
 
 
599
 
    def __init__(self, format, controldir_format):
600
 
        BzrError.__init__(self)
601
 
        self.format = format
602
 
        self.controldir = controldir_format
603
 
 
604
 
 
605
 
class ParseFormatError(BzrError):
606
 
 
607
 
    _fmt = "Parse error on line %(lineno)d of %(format)s format: %(line)s"
608
 
 
609
 
    def __init__(self, format, lineno, line, text):
610
 
        BzrError.__init__(self)
611
 
        self.format = format
612
 
        self.lineno = lineno
613
 
        self.line = line
614
 
        self.text = text
 
753
    
 
754
    _fmt = "Format %(format)s is not compatible with .bzr version %(bzrdir)s."
 
755
 
 
756
    def __init__(self, format, bzrdir_format):
 
757
        BzrError.__init__(self)
 
758
        self.format = format
 
759
        self.bzrdir = bzrdir_format
615
760
 
616
761
 
617
762
class IncompatibleRepositories(BzrError):
618
 
    """Report an error that two repositories are not compatible.
619
 
 
620
 
    Note that the source and target repositories are permitted to be strings:
621
 
    this exception is thrown from the smart server and may refer to a
622
 
    repository the client hasn't opened.
623
 
    """
624
 
 
625
 
    _fmt = "%(target)s\n" \
626
 
            "is not compatible with\n" \
627
 
            "%(source)s\n" \
628
 
            "%(details)s"
629
 
 
630
 
    def __init__(self, source, target, details=None):
631
 
        if details is None:
632
 
            details = "(no details)"
633
 
        BzrError.__init__(self, target=target, source=source, details=details)
 
763
 
 
764
    _fmt = "Repository %(target)s is not compatible with repository"\
 
765
        " %(source)s"
 
766
 
 
767
    def __init__(self, source, target):
 
768
        BzrError.__init__(self, target=target, source=source)
634
769
 
635
770
 
636
771
class IncompatibleRevision(BzrError):
637
 
 
 
772
    
638
773
    _fmt = "Revision is not compatible with %(repo_format)s"
639
774
 
640
775
    def __init__(self, repo_format):
651
786
        """Construct a new AlreadyVersionedError.
652
787
 
653
788
        :param path: This is the path which is versioned,
654
 
            which should be in a user friendly form.
 
789
        which should be in a user friendly form.
655
790
        :param context_info: If given, this is information about the context,
656
 
            which could explain why this is expected to not be versioned.
 
791
        which could explain why this is expected to not be versioned.
657
792
        """
658
793
        BzrError.__init__(self)
659
794
        self.path = path
672
807
        """Construct a new NotVersionedError.
673
808
 
674
809
        :param path: This is the path which is not versioned,
675
 
            which should be in a user friendly form.
 
810
        which should be in a user friendly form.
676
811
        :param context_info: If given, this is information about the context,
677
 
            which could explain why this is expected to be versioned.
 
812
        which could explain why this is expected to be versioned.
678
813
        """
679
814
        BzrError.__init__(self)
680
815
        self.path = path
690
825
    _fmt = "Path(s) are not versioned: %(paths_as_string)s"
691
826
 
692
827
    def __init__(self, paths):
693
 
        from breezy.osutils import quotefn
 
828
        from bzrlib.osutils import quotefn
694
829
        BzrError.__init__(self)
695
830
        self.paths = paths
696
831
        self.paths_as_string = ' '.join([quotefn(p) for p in paths])
705
840
 
706
841
    def __init__(self, paths, extra=None):
707
842
        # circular import
708
 
        from breezy.osutils import quotefn
 
843
        from bzrlib.osutils import quotefn
709
844
        BzrError.__init__(self)
710
845
        self.paths = paths
711
846
        self.paths_as_string = ' '.join([quotefn(p) for p in paths])
748
883
    # original exception is available as e.original_error
749
884
    #
750
885
    # New code should prefer to raise specific subclasses
751
 
    def __init__(self, msg):
752
 
        self.msg = msg
 
886
    def __init__(self, message):
 
887
        # Python 2.5 uses a slot for StandardError.message,
 
888
        # so use a different variable name.  We now work around this in
 
889
        # BzrError.__str__, but this member name is kept for compatability.
 
890
        self.msg = message
753
891
 
754
892
 
755
893
class LockActive(LockError):
838
976
 
839
977
class LockContention(LockError):
840
978
 
841
 
    _fmt = 'Could not acquire lock "%(lock)s": %(msg)s'
 
979
    _fmt = 'Could not acquire lock "%(lock)s"'
 
980
    # TODO: show full url for lock, combining the transport and relative
 
981
    # bits?
842
982
 
843
983
    internal_error = False
844
984
 
845
 
    def __init__(self, lock, msg=''):
 
985
    def __init__(self, lock):
846
986
        self.lock = lock
847
 
        self.msg = msg
848
987
 
849
988
 
850
989
class LockBroken(LockError):
871
1010
        self.target = target
872
1011
 
873
1012
 
874
 
class LockCorrupt(LockError):
875
 
 
876
 
    _fmt = ("Lock is apparently held, but corrupted: %(corruption_info)s\n"
877
 
            "Use 'brz break-lock' to clear it")
878
 
 
879
 
    internal_error = False
880
 
 
881
 
    def __init__(self, corruption_info, file_data=None):
882
 
        self.corruption_info = corruption_info
883
 
        self.file_data = file_data
884
 
 
885
 
 
886
1013
class LockNotHeld(LockError):
887
1014
 
888
1015
    _fmt = "Lock not held: %(lock)s"
912
1039
        self.lock_token = lock_token
913
1040
 
914
1041
 
 
1042
class PointlessCommit(BzrError):
 
1043
 
 
1044
    _fmt = "No changes to commit"
 
1045
 
 
1046
 
 
1047
class CannotCommitSelectedFileMerge(BzrError):
 
1048
 
 
1049
    _fmt = 'Selected-file commit of merges is not supported yet:'\
 
1050
        ' files %(files_str)s'
 
1051
 
 
1052
    def __init__(self, files):
 
1053
        files_str = ', '.join(files)
 
1054
        BzrError.__init__(self, files=files, files_str=files_str)
 
1055
 
 
1056
 
 
1057
class BadCommitMessageEncoding(BzrError):
 
1058
 
 
1059
    _fmt = 'The specified commit message contains characters unsupported by '\
 
1060
        'the current encoding.'
 
1061
 
 
1062
 
915
1063
class UpgradeReadonly(BzrError):
916
1064
 
917
1065
    _fmt = "Upgrade URL cannot work with readonly URLs."
926
1074
        self.format = format
927
1075
 
928
1076
 
 
1077
class StrictCommitFailed(Exception):
 
1078
 
 
1079
    _fmt = "Commit refused because there are unknowns in the tree."
 
1080
 
 
1081
 
929
1082
class NoSuchRevision(InternalBzrError):
930
1083
 
931
1084
    _fmt = "%(branch)s has no revision %(revision)s"
950
1103
 
951
1104
class NoSuchRevisionInTree(NoSuchRevision):
952
1105
    """When using Tree.revision_tree, and the revision is not accessible."""
953
 
 
 
1106
    
954
1107
    _fmt = "The revision id {%(revision_id)s} is not present in the tree %(tree)s."
955
1108
 
956
1109
    def __init__(self, tree, revision_id):
961
1114
 
962
1115
class InvalidRevisionSpec(BzrError):
963
1116
 
964
 
    _fmt = ("Requested revision: '%(spec)s' does not exist in branch:"
965
 
            " %(branch_url)s%(extra)s")
 
1117
    _fmt = ("Requested revision: %(spec)r does not exist in branch:"
 
1118
            " %(branch)s%(extra)s")
966
1119
 
967
1120
    def __init__(self, spec, branch, extra=None):
968
1121
        BzrError.__init__(self, branch=branch, spec=spec)
969
 
        self.branch_url = getattr(branch, 'user_url', str(branch))
970
1122
        if extra:
971
1123
            self.extra = '\n' + str(extra)
972
1124
        else:
973
1125
            self.extra = ''
974
1126
 
975
1127
 
 
1128
class HistoryMissing(BzrError):
 
1129
 
 
1130
    _fmt = "%(branch)s is missing %(object_type)s {%(object_id)s}"
 
1131
 
 
1132
 
976
1133
class AppendRevisionsOnlyViolation(BzrError):
977
1134
 
978
1135
    _fmt = ('Operation denied because it would change the main history,'
980
1137
           ' branch "%(location)s".')
981
1138
 
982
1139
    def __init__(self, location):
983
 
       import breezy.urlutils as urlutils
 
1140
       import bzrlib.urlutils as urlutils
984
1141
       location = urlutils.unescape_for_display(location, 'ascii')
985
1142
       BzrError.__init__(self, location=location)
986
1143
 
988
1145
class DivergedBranches(BzrError):
989
1146
 
990
1147
    _fmt = ("These branches have diverged."
991
 
            " Use the missing command to see how.\n"
992
 
            "Use the merge command to reconcile them.")
 
1148
            " Use the merge command to reconcile them.")
993
1149
 
994
1150
    def __init__(self, branch1, branch2):
995
1151
        self.branch1 = branch1
1017
1173
 
1018
1174
 
1019
1175
class NoCommonAncestor(BzrError):
1020
 
 
 
1176
    
1021
1177
    _fmt = "Revisions have no common ancestor: %(revision_a)s %(revision_b)s"
1022
1178
 
1023
1179
    def __init__(self, revision_a, revision_b):
1043
1199
            not_ancestor_id=not_ancestor_id)
1044
1200
 
1045
1201
 
 
1202
class InstallFailed(BzrError):
 
1203
 
 
1204
    def __init__(self, revisions):
 
1205
        revision_str = ", ".join(str(r) for r in revisions)
 
1206
        msg = "Could not install revisions:\n%s" % revision_str
 
1207
        BzrError.__init__(self, msg)
 
1208
        self.revisions = revisions
 
1209
 
 
1210
 
 
1211
class AmbiguousBase(BzrError):
 
1212
 
 
1213
    def __init__(self, bases):
 
1214
        warn("BzrError AmbiguousBase has been deprecated as of bzrlib 0.8.",
 
1215
                DeprecationWarning)
 
1216
        msg = ("The correct base is unclear, because %s are all equally close"
 
1217
                % ", ".join(bases))
 
1218
        BzrError.__init__(self, msg)
 
1219
        self.bases = bases
 
1220
 
 
1221
 
1046
1222
class NoCommits(BranchError):
1047
1223
 
1048
1224
    _fmt = "Branch %(branch)s has no commits."
1064
1240
class BoundBranchOutOfDate(BzrError):
1065
1241
 
1066
1242
    _fmt = ("Bound branch %(branch)s is out of date with master branch"
1067
 
            " %(master)s.%(extra_help)s")
 
1243
            " %(master)s.")
1068
1244
 
1069
1245
    def __init__(self, branch, master):
1070
1246
        BzrError.__init__(self)
1071
1247
        self.branch = branch
1072
1248
        self.master = master
1073
 
        self.extra_help = ''
1074
 
 
1075
 
 
 
1249
 
 
1250
        
1076
1251
class CommitToDoubleBoundBranch(BzrError):
1077
1252
 
1078
1253
    _fmt = ("Cannot commit to branch %(branch)s."
1106
1281
        self.error = error
1107
1282
 
1108
1283
 
 
1284
class WeaveError(BzrError):
 
1285
 
 
1286
    _fmt = "Error in processing weave: %(message)s"
 
1287
 
 
1288
    def __init__(self, message=None):
 
1289
        BzrError.__init__(self)
 
1290
        self.message = message
 
1291
 
 
1292
 
 
1293
class WeaveRevisionAlreadyPresent(WeaveError):
 
1294
 
 
1295
    _fmt = "Revision {%(revision_id)s} already present in %(weave)s"
 
1296
 
 
1297
    def __init__(self, revision_id, weave):
 
1298
 
 
1299
        WeaveError.__init__(self)
 
1300
        self.revision_id = revision_id
 
1301
        self.weave = weave
 
1302
 
 
1303
 
 
1304
class WeaveRevisionNotPresent(WeaveError):
 
1305
 
 
1306
    _fmt = "Revision {%(revision_id)s} not present in %(weave)s"
 
1307
 
 
1308
    def __init__(self, revision_id, weave):
 
1309
        WeaveError.__init__(self)
 
1310
        self.revision_id = revision_id
 
1311
        self.weave = weave
 
1312
 
 
1313
 
 
1314
class WeaveFormatError(WeaveError):
 
1315
 
 
1316
    _fmt = "Weave invariant violated: %(what)s"
 
1317
 
 
1318
    def __init__(self, what):
 
1319
        WeaveError.__init__(self)
 
1320
        self.what = what
 
1321
 
 
1322
 
 
1323
class WeaveParentMismatch(WeaveError):
 
1324
 
 
1325
    _fmt = "Parents are mismatched between two revisions. %(message)s"
 
1326
    
 
1327
 
 
1328
class WeaveInvalidChecksum(WeaveError):
 
1329
 
 
1330
    _fmt = "Text did not match it's checksum: %(message)s"
 
1331
 
 
1332
 
 
1333
class WeaveTextDiffers(WeaveError):
 
1334
 
 
1335
    _fmt = ("Weaves differ on text content. Revision:"
 
1336
            " {%(revision_id)s}, %(weave_a)s, %(weave_b)s")
 
1337
 
 
1338
    def __init__(self, revision_id, weave_a, weave_b):
 
1339
        WeaveError.__init__(self)
 
1340
        self.revision_id = revision_id
 
1341
        self.weave_a = weave_a
 
1342
        self.weave_b = weave_b
 
1343
 
 
1344
 
 
1345
class WeaveTextDiffers(WeaveError):
 
1346
 
 
1347
    _fmt = ("Weaves differ on text content. Revision:"
 
1348
            " {%(revision_id)s}, %(weave_a)s, %(weave_b)s")
 
1349
 
 
1350
    def __init__(self, revision_id, weave_a, weave_b):
 
1351
        WeaveError.__init__(self)
 
1352
        self.revision_id = revision_id
 
1353
        self.weave_a = weave_a
 
1354
        self.weave_b = weave_b
 
1355
 
 
1356
 
1109
1357
class VersionedFileError(BzrError):
1110
 
 
 
1358
    
1111
1359
    _fmt = "Versioned file error"
1112
1360
 
1113
1361
 
1114
1362
class RevisionNotPresent(VersionedFileError):
1115
 
 
 
1363
    
1116
1364
    _fmt = 'Revision {%(revision_id)s} not present in "%(file_id)s".'
1117
1365
 
1118
1366
    def __init__(self, revision_id, file_id):
1122
1370
 
1123
1371
 
1124
1372
class RevisionAlreadyPresent(VersionedFileError):
1125
 
 
 
1373
    
1126
1374
    _fmt = 'Revision {%(revision_id)s} already present in "%(file_id)s".'
1127
1375
 
1128
1376
    def __init__(self, revision_id, file_id):
1133
1381
 
1134
1382
class VersionedFileInvalidChecksum(VersionedFileError):
1135
1383
 
1136
 
    _fmt = "Text did not match its checksum: %(msg)s"
1137
 
 
1138
 
 
1139
 
class RetryWithNewPacks(BzrError):
1140
 
    """Raised when we realize that the packs on disk have changed.
1141
 
 
1142
 
    This is meant as more of a signaling exception, to trap between where a
1143
 
    local error occurred and the code that can actually handle the error and
1144
 
    code that can retry appropriately.
1145
 
    """
1146
 
 
1147
 
    internal_error = True
1148
 
 
1149
 
    _fmt = ("Pack files have changed, reload and retry. context: %(context)s"
1150
 
            " %(orig_error)s")
1151
 
 
1152
 
    def __init__(self, context, reload_occurred, exc_info):
1153
 
        """create a new RetryWithNewPacks error.
1154
 
 
1155
 
        :param reload_occurred: Set to True if we know that the packs have
1156
 
            already been reloaded, and we are failing because of an in-memory
1157
 
            cache miss. If set to True then we will ignore if a reload says
1158
 
            nothing has changed, because we assume it has already reloaded. If
1159
 
            False, then a reload with nothing changed will force an error.
1160
 
        :param exc_info: The original exception traceback, so if there is a
1161
 
            problem we can raise the original error (value from sys.exc_info())
1162
 
        """
1163
 
        BzrError.__init__(self)
1164
 
        self.context = context
1165
 
        self.reload_occurred = reload_occurred
1166
 
        self.exc_info = exc_info
1167
 
        self.orig_error = exc_info[1]
1168
 
        # TODO: The global error handler should probably treat this by
1169
 
        #       raising/printing the original exception with a bit about
1170
 
        #       RetryWithNewPacks also not being caught
1171
 
 
1172
 
 
1173
 
class RetryAutopack(RetryWithNewPacks):
1174
 
    """Raised when we are autopacking and we find a missing file.
1175
 
 
1176
 
    Meant as a signaling exception, to tell the autopack code it should try
1177
 
    again.
1178
 
    """
1179
 
 
1180
 
    internal_error = True
1181
 
 
1182
 
    _fmt = ("Pack files have changed, reload and try autopack again."
1183
 
            " context: %(context)s %(orig_error)s")
 
1384
    _fmt = "Text did not match its checksum: %(message)s"
 
1385
 
 
1386
 
 
1387
class KnitError(InternalBzrError):
 
1388
    
 
1389
    _fmt = "Knit error"
 
1390
 
 
1391
 
 
1392
class KnitCorrupt(KnitError):
 
1393
 
 
1394
    _fmt = "Knit %(filename)s corrupt: %(how)s"
 
1395
 
 
1396
    def __init__(self, filename, how):
 
1397
        KnitError.__init__(self)
 
1398
        self.filename = filename
 
1399
        self.how = how
 
1400
 
 
1401
 
 
1402
class KnitDataStreamIncompatible(KnitError):
 
1403
    # Not raised anymore, as we can convert data streams.  In future we may
 
1404
    # need it again for more exotic cases, so we're keeping it around for now.
 
1405
 
 
1406
    _fmt = "Cannot insert knit data stream of format \"%(stream_format)s\" into knit of format \"%(target_format)s\"."
 
1407
 
 
1408
    def __init__(self, stream_format, target_format):
 
1409
        self.stream_format = stream_format
 
1410
        self.target_format = target_format
 
1411
        
 
1412
 
 
1413
class KnitDataStreamUnknown(KnitError):
 
1414
    # Indicates a data stream we don't know how to handle.
 
1415
 
 
1416
    _fmt = "Cannot parse knit data stream of format \"%(stream_format)s\"."
 
1417
 
 
1418
    def __init__(self, stream_format):
 
1419
        self.stream_format = stream_format
 
1420
        
 
1421
 
 
1422
class KnitHeaderError(KnitError):
 
1423
 
 
1424
    _fmt = 'Knit header error: %(badline)r unexpected for file "%(filename)s".'
 
1425
 
 
1426
    def __init__(self, badline, filename):
 
1427
        KnitError.__init__(self)
 
1428
        self.badline = badline
 
1429
        self.filename = filename
 
1430
 
 
1431
class KnitIndexUnknownMethod(KnitError):
 
1432
    """Raised when we don't understand the storage method.
 
1433
 
 
1434
    Currently only 'fulltext' and 'line-delta' are supported.
 
1435
    """
 
1436
    
 
1437
    _fmt = ("Knit index %(filename)s does not have a known method"
 
1438
            " in options: %(options)r")
 
1439
 
 
1440
    def __init__(self, filename, options):
 
1441
        KnitError.__init__(self)
 
1442
        self.filename = filename
 
1443
        self.options = options
1184
1444
 
1185
1445
 
1186
1446
class NoSuchExportFormat(BzrError):
1187
 
 
 
1447
    
1188
1448
    _fmt = "Export format %(format)r not supported"
1189
1449
 
1190
1450
    def __init__(self, format):
1193
1453
 
1194
1454
 
1195
1455
class TransportError(BzrError):
1196
 
 
 
1456
    
1197
1457
    _fmt = "Transport error: %(msg)s %(orig_error)s"
1198
1458
 
1199
1459
    def __init__(self, msg=None, orig_error=None):
1244
1504
 
1245
1505
class SmartMessageHandlerError(InternalBzrError):
1246
1506
 
1247
 
    _fmt = ("The message handler raised an exception:\n"
1248
 
            "%(traceback_text)s")
 
1507
    _fmt = "The message handler raised an exception: %(exc_value)s."
1249
1508
 
1250
1509
    def __init__(self, exc_info):
1251
 
        import traceback
1252
 
        # GZ 2010-08-10: Cycle with exc_tb/exc_info affects at least one test
1253
 
        self.exc_type, self.exc_value, self.exc_tb = exc_info
1254
 
        self.exc_info = exc_info
1255
 
        traceback_strings = traceback.format_exception(
1256
 
                self.exc_type, self.exc_value, self.exc_tb)
1257
 
        self.traceback_text = ''.join(traceback_strings)
1258
 
 
 
1510
        self.exc_type, self.exc_value, self.tb = exc_info
 
1511
        
1259
1512
 
1260
1513
# A set of semi-meaningful errors which can be thrown
1261
1514
class TransportNotPossible(TransportError):
1287
1540
            self.port = ':%s' % port
1288
1541
 
1289
1542
 
1290
 
# XXX: This is also used for unexpected end of file, which is different at the
1291
 
# TCP level from "connection reset".
1292
1543
class ConnectionReset(TransportError):
1293
1544
 
1294
1545
    _fmt = "Connection closed: %(msg)s %(orig_error)s"
1295
1546
 
1296
1547
 
1297
 
class ConnectionTimeout(ConnectionError):
1298
 
 
1299
 
    _fmt = "Connection Timeout: %(msg)s%(orig_error)s"
1300
 
 
1301
 
 
1302
1548
class InvalidRange(TransportError):
1303
1549
 
1304
1550
    _fmt = "Invalid range access in %(path)s at %(offset)s: %(msg)s"
1311
1557
 
1312
1558
class InvalidHttpResponse(TransportError):
1313
1559
 
1314
 
    _fmt = "Invalid http response for %(path)s: %(msg)s%(orig_error)s"
 
1560
    _fmt = "Invalid http response for %(path)s: %(msg)s"
1315
1561
 
1316
1562
    def __init__(self, path, msg, orig_error=None):
1317
1563
        self.path = path
1318
 
        if orig_error is None:
1319
 
            orig_error = ''
1320
 
        else:
1321
 
            # This is reached for obscure and unusual errors so we want to
1322
 
            # preserve as much info as possible to ease debug.
1323
 
            orig_error = ': %r' % (orig_error,)
1324
1564
        TransportError.__init__(self, msg, orig_error=orig_error)
1325
1565
 
1326
1566
 
1333
1573
        InvalidHttpResponse.__init__(self, path, msg)
1334
1574
 
1335
1575
 
1336
 
class HttpBoundaryMissing(InvalidHttpResponse):
1337
 
    """A multipart response ends with no boundary marker.
1338
 
 
1339
 
    This is a special case caused by buggy proxies, described in
1340
 
    <https://bugs.launchpad.net/bzr/+bug/198646>.
1341
 
    """
1342
 
 
1343
 
    _fmt = "HTTP MIME Boundary missing for %(path)s: %(msg)s"
1344
 
 
1345
 
    def __init__(self, path, msg):
1346
 
        InvalidHttpResponse.__init__(self, path, msg)
1347
 
 
1348
 
 
1349
1576
class InvalidHttpContentType(InvalidHttpResponse):
1350
1577
 
1351
1578
    _fmt = 'Invalid http Content-type "%(ctype)s" for %(path)s: %(msg)s'
1359
1586
 
1360
1587
    _fmt = '%(source)s is%(permanently)s redirected to %(target)s'
1361
1588
 
1362
 
    def __init__(self, source, target, is_permanent=False):
 
1589
    def __init__(self, source, target, is_permanent=False, qual_proto=None):
1363
1590
        self.source = source
1364
1591
        self.target = target
1365
1592
        if is_permanent:
1366
1593
            self.permanently = ' permanently'
1367
1594
        else:
1368
1595
            self.permanently = ''
 
1596
        self._qualified_proto = qual_proto
1369
1597
        TransportError.__init__(self)
1370
1598
 
 
1599
    def _requalify_url(self, url):
 
1600
        """Restore the qualified proto in front of the url"""
 
1601
        # When this exception is raised, source and target are in
 
1602
        # user readable format. But some transports may use a
 
1603
        # different proto (http+urllib:// will present http:// to
 
1604
        # the user. If a qualified proto is specified, the code
 
1605
        # trapping the exception can get the qualified urls to
 
1606
        # properly handle the redirection themself (creating a
 
1607
        # new transport object from the target url for example).
 
1608
        # But checking that the scheme of the original and
 
1609
        # redirected urls are the same can be tricky. (see the
 
1610
        # FIXME in BzrDir.open_from_transport for the unique use
 
1611
        # case so far).
 
1612
        if self._qualified_proto is None:
 
1613
            return url
 
1614
 
 
1615
        # The TODO related to NotBranchError mention that doing
 
1616
        # that kind of manipulation on the urls may not be the
 
1617
        # exception object job. On the other hand, this object is
 
1618
        # the interface between the code and the user so
 
1619
        # presenting the urls in different ways is indeed its
 
1620
        # job...
 
1621
        import urlparse
 
1622
        proto, netloc, path, query, fragment = urlparse.urlsplit(url)
 
1623
        return urlparse.urlunsplit((self._qualified_proto, netloc, path,
 
1624
                                   query, fragment))
 
1625
 
 
1626
    def get_source_url(self):
 
1627
        return self._requalify_url(self.source)
 
1628
 
 
1629
    def get_target_url(self):
 
1630
        return self._requalify_url(self.target)
 
1631
 
1371
1632
 
1372
1633
class TooManyRedirections(TransportError):
1373
1634
 
1379
1640
    _fmt = "Working tree has conflicts."
1380
1641
 
1381
1642
 
1382
 
class DependencyNotPresent(BzrError):
1383
 
 
1384
 
    _fmt = 'Unable to import library "%(library)s": %(error)s'
1385
 
 
1386
 
    def __init__(self, library, error):
1387
 
        BzrError.__init__(self, library=library, error=error)
 
1643
class ParseConfigError(BzrError):
 
1644
 
 
1645
    def __init__(self, errors, filename):
 
1646
        if filename is None:
 
1647
            filename = ""
 
1648
        message = "Error(s) parsing config file %s:\n%s" % \
 
1649
            (filename, ('\n'.join(e.message for e in errors)))
 
1650
        BzrError.__init__(self, message)
 
1651
 
 
1652
 
 
1653
class NoEmailInUsername(BzrError):
 
1654
 
 
1655
    _fmt = "%(username)r does not seem to contain a reasonable email address"
 
1656
 
 
1657
    def __init__(self, username):
 
1658
        BzrError.__init__(self)
 
1659
        self.username = username
 
1660
 
 
1661
 
 
1662
class SigningFailed(BzrError):
 
1663
 
 
1664
    _fmt = 'Failed to gpg sign data with command "%(command_line)s"'
 
1665
 
 
1666
    def __init__(self, command_line):
 
1667
        BzrError.__init__(self, command_line=command_line)
1388
1668
 
1389
1669
 
1390
1670
class WorkingTreeNotRevision(BzrError):
1391
1671
 
1392
 
    _fmt = ("The working tree for %(basedir)s has changed since"
 
1672
    _fmt = ("The working tree for %(basedir)s has changed since" 
1393
1673
            " the last commit, but weave merge requires that it be"
1394
1674
            " unchanged")
1395
1675
 
1397
1677
        BzrError.__init__(self, basedir=tree.basedir)
1398
1678
 
1399
1679
 
 
1680
class CantReprocessAndShowBase(BzrError):
 
1681
 
 
1682
    _fmt = ("Can't reprocess and show base, because reprocessing obscures "
 
1683
           "the relationship of conflicting lines to the base")
 
1684
 
 
1685
 
1400
1686
class GraphCycleError(BzrError):
1401
1687
 
1402
1688
    _fmt = "Cycle in graph %(graph)r"
1502
1788
        self.prefix = prefix
1503
1789
 
1504
1790
 
1505
 
class MalformedTransform(InternalBzrError):
 
1791
class MalformedTransform(BzrError):
1506
1792
 
1507
1793
    _fmt = "Tree transform is malformed %(conflicts)r"
1508
1794
 
1546
1832
    _fmt = "Moving the root directory is not supported at this time"
1547
1833
 
1548
1834
 
1549
 
class TransformRenameFailed(BzrError):
1550
 
 
1551
 
    _fmt = "Failed to rename %(from_path)s to %(to_path)s: %(why)s"
1552
 
 
1553
 
    def __init__(self, from_path, to_path, why, errno):
1554
 
        self.from_path = from_path
1555
 
        self.to_path = to_path
1556
 
        self.why = why
1557
 
        self.errno = errno
1558
 
 
1559
 
 
1560
1835
class BzrMoveFailedError(BzrError):
1561
1836
 
1562
 
    _fmt = ("Could not move %(from_path)s%(operator)s %(to_path)s"
1563
 
        "%(_has_extra)s%(extra)s")
 
1837
    _fmt = "Could not move %(from_path)s%(operator)s %(to_path)s%(extra)s"
1564
1838
 
1565
1839
    def __init__(self, from_path='', to_path='', extra=None):
1566
 
        from breezy.osutils import splitpath
1567
1840
        BzrError.__init__(self)
1568
1841
        if extra:
1569
 
            self.extra, self._has_extra = extra, ': '
 
1842
            self.extra = ': ' + str(extra)
1570
1843
        else:
1571
 
            self.extra = self._has_extra = ''
 
1844
            self.extra = ''
1572
1845
 
1573
1846
        has_from = len(from_path) > 0
1574
1847
        has_to = len(to_path) > 0
1575
1848
        if has_from:
1576
 
            self.from_path = splitpath(from_path)[-1]
 
1849
            self.from_path = osutils.splitpath(from_path)[-1]
1577
1850
        else:
1578
1851
            self.from_path = ''
1579
1852
 
1580
1853
        if has_to:
1581
 
            self.to_path = splitpath(to_path)[-1]
 
1854
            self.to_path = osutils.splitpath(to_path)[-1]
1582
1855
        else:
1583
1856
            self.to_path = ''
1584
1857
 
1595
1868
 
1596
1869
class BzrRenameFailedError(BzrMoveFailedError):
1597
1870
 
1598
 
    _fmt = ("Could not rename %(from_path)s%(operator)s %(to_path)s"
1599
 
        "%(_has_extra)s%(extra)s")
 
1871
    _fmt = "Could not rename %(from_path)s%(operator)s %(to_path)s%(extra)s"
1600
1872
 
1601
1873
    def __init__(self, from_path, to_path, extra=None):
1602
1874
        BzrMoveFailedError.__init__(self, from_path, to_path, extra)
1603
1875
 
 
1876
class BzrRemoveChangedFilesError(BzrError):
 
1877
    """Used when user is trying to remove changed files."""
 
1878
 
 
1879
    _fmt = ("Can't safely remove modified or unknown files:\n"
 
1880
        "%(changes_as_text)s"
 
1881
        "Use --keep to not delete them, or --force to delete them regardless.")
 
1882
 
 
1883
    def __init__(self, tree_delta):
 
1884
        BzrError.__init__(self)
 
1885
        self.changes_as_text = tree_delta.get_changes_as_text()
 
1886
        #self.paths_as_string = '\n'.join(changed_files)
 
1887
        #self.paths_as_string = '\n'.join([quotefn(p) for p in changed_files])
 
1888
 
1604
1889
 
1605
1890
class BzrBadParameterNotString(BzrBadParameter):
1606
1891
 
1609
1894
 
1610
1895
class BzrBadParameterMissing(BzrBadParameter):
1611
1896
 
1612
 
    _fmt = "Parameter %(param)s is required but not present."
 
1897
    _fmt = "Parameter $(param)s is required but not present."
1613
1898
 
1614
1899
 
1615
1900
class BzrBadParameterUnicode(BzrBadParameter):
1623
1908
    _fmt = "Parameter %(param)s contains a newline."
1624
1909
 
1625
1910
 
 
1911
class DependencyNotPresent(BzrError):
 
1912
 
 
1913
    _fmt = 'Unable to import library "%(library)s": %(error)s'
 
1914
 
 
1915
    def __init__(self, library, error):
 
1916
        BzrError.__init__(self, library=library, error=error)
 
1917
 
 
1918
 
1626
1919
class ParamikoNotPresent(DependencyNotPresent):
1627
1920
 
1628
1921
    _fmt = "Unable to import paramiko (required for sftp support): %(error)s"
1638
1931
 
1639
1932
class UninitializableFormat(BzrError):
1640
1933
 
1641
 
    _fmt = "Format %(format)s cannot be initialised by this version of brz."
 
1934
    _fmt = "Format %(format)s cannot be initialised by this version of bzr."
1642
1935
 
1643
1936
    def __init__(self, format):
1644
1937
        BzrError.__init__(self)
1647
1940
 
1648
1941
class BadConversionTarget(BzrError):
1649
1942
 
1650
 
    _fmt = "Cannot convert from format %(from_format)s to format %(format)s." \
1651
 
            "    %(problem)s"
 
1943
    _fmt = "Cannot convert to format %(format)s.  %(problem)s"
1652
1944
 
1653
 
    def __init__(self, problem, format, from_format=None):
 
1945
    def __init__(self, problem, format):
1654
1946
        BzrError.__init__(self)
1655
1947
        self.problem = problem
1656
1948
        self.format = format
1657
 
        self.from_format = from_format or '(unspecified)'
1658
1949
 
1659
1950
 
1660
1951
class NoDiffFound(BzrError):
1687
1978
 
1688
1979
 
1689
1980
class ExistingContent(BzrError):
1690
 
    # Added in breezy 0.92, used by VersionedFile.add_lines.
 
1981
    # Added in bzrlib 0.92, used by VersionedFile.add_lines.
1691
1982
 
1692
1983
    _fmt = "The content being inserted is already present."
1693
1984
 
1697
1988
    _fmt = """This tree contains left-over files from a failed operation.
1698
1989
    Please examine %(limbo_dir)s to see if it contains any files you wish to
1699
1990
    keep, and delete it when you are done."""
1700
 
 
 
1991
    
1701
1992
    def __init__(self, limbo_dir):
1702
1993
       BzrError.__init__(self)
1703
1994
       self.limbo_dir = limbo_dir
1736
2027
 
1737
2028
class OutOfDateTree(BzrError):
1738
2029
 
1739
 
    _fmt = "Working tree is out of date, please run 'brz update'.%(more)s"
 
2030
    _fmt = "Working tree is out of date, please run 'bzr update'."
1740
2031
 
1741
 
    def __init__(self, tree, more=None):
1742
 
        if more is None:
1743
 
            more = ''
1744
 
        else:
1745
 
            more = ' ' + more
 
2032
    def __init__(self, tree):
1746
2033
        BzrError.__init__(self)
1747
2034
        self.tree = tree
1748
 
        self.more = more
1749
2035
 
1750
2036
 
1751
2037
class PublicBranchOutOfDate(BzrError):
1754
2040
        '"%(revstring)s".'
1755
2041
 
1756
2042
    def __init__(self, public_location, revstring):
1757
 
        import breezy.urlutils as urlutils
 
2043
        import bzrlib.urlutils as urlutils
1758
2044
        public_location = urlutils.unescape_for_display(public_location,
1759
2045
                                                        'ascii')
1760
2046
        BzrError.__init__(self, public_location=public_location,
1771
2057
    _fmt = "Format error in conflict listings"
1772
2058
 
1773
2059
 
 
2060
class CorruptDirstate(BzrError):
 
2061
 
 
2062
    _fmt = ("Inconsistency in dirstate file %(dirstate_path)s.\n"
 
2063
            "Error: %(description)s")
 
2064
 
 
2065
    def __init__(self, dirstate_path, description):
 
2066
        BzrError.__init__(self)
 
2067
        self.dirstate_path = dirstate_path
 
2068
        self.description = description
 
2069
 
 
2070
 
1774
2071
class CorruptRepository(BzrError):
1775
2072
 
1776
2073
    _fmt = ("An error has been detected in the repository %(repo_path)s.\n"
1777
 
            "Please run brz reconcile on this repository.")
 
2074
            "Please run bzr reconcile on this repository.")
1778
2075
 
1779
2076
    def __init__(self, repo):
1780
2077
        BzrError.__init__(self)
1781
 
        self.repo_path = repo.user_url
 
2078
        self.repo_path = repo.bzrdir.root_transport.base
1782
2079
 
1783
2080
 
1784
2081
class InconsistentDelta(BzrError):
1794
2091
        self.reason = reason
1795
2092
 
1796
2093
 
1797
 
class InconsistentDeltaDelta(InconsistentDelta):
1798
 
    """Used when we get a delta that is not valid."""
1799
 
 
1800
 
    _fmt = ("An inconsistent delta was supplied: %(delta)r"
1801
 
            "\nreason: %(reason)s")
1802
 
 
1803
 
    def __init__(self, delta, reason):
1804
 
        BzrError.__init__(self)
1805
 
        self.delta = delta
1806
 
        self.reason = reason
1807
 
 
1808
 
 
1809
2094
class UpgradeRequired(BzrError):
1810
2095
 
1811
2096
    _fmt = "To use this feature you must upgrade your branch at %(path)s."
1820
2105
    _fmt = "To use this feature you must upgrade your repository at %(path)s."
1821
2106
 
1822
2107
 
1823
 
class RichRootUpgradeRequired(UpgradeRequired):
1824
 
 
1825
 
    _fmt = ("To use this feature you must upgrade your branch at %(path)s to"
1826
 
           " a format which supports rich roots.")
1827
 
 
1828
 
 
1829
2108
class LocalRequiresBoundBranch(BzrError):
1830
2109
 
1831
2110
    _fmt = "Cannot perform local-only commits on unbound branches."
1832
2111
 
1833
2112
 
 
2113
class MissingProgressBarFinish(BzrError):
 
2114
 
 
2115
    _fmt = "A nested progress bar was not 'finished' correctly."
 
2116
 
 
2117
 
 
2118
class InvalidProgressBarType(BzrError):
 
2119
 
 
2120
    _fmt = ("Environment variable BZR_PROGRESS_BAR='%(bar_type)s"
 
2121
            " is not a supported type Select one of: %(valid_types)s")
 
2122
 
 
2123
    def __init__(self, bar_type, valid_types):
 
2124
        BzrError.__init__(self, bar_type=bar_type, valid_types=valid_types)
 
2125
 
 
2126
 
1834
2127
class UnsupportedOperation(BzrError):
1835
2128
 
1836
2129
    _fmt = ("The method %(mname)s is not supported on"
1842
2135
        self.tname = type(method_self).__name__
1843
2136
 
1844
2137
 
1845
 
class FetchLimitUnsupported(UnsupportedOperation):
1846
 
 
1847
 
    fmt = ("InterBranch %(interbranch)r does not support fetching limits.")
1848
 
 
1849
 
    def __init__(self, interbranch):
1850
 
        BzrError.__init__(self, interbranch=interbranch)
 
2138
class CannotSetRevisionId(UnsupportedOperation):
 
2139
    """Raised when a commit is attempting to set a revision id but cant."""
1851
2140
 
1852
2141
 
1853
2142
class NonAsciiRevisionId(UnsupportedOperation):
1856
2145
    """
1857
2146
 
1858
2147
 
1859
 
class GhostTagsNotSupported(BzrError):
1860
 
 
1861
 
    _fmt = "Ghost tags not supported by format %(format)r."
1862
 
 
1863
 
    def __init__(self, format):
1864
 
        self.format = format
1865
 
 
1866
 
 
1867
2148
class BinaryFile(BzrError):
1868
 
 
 
2149
    
1869
2150
    _fmt = "File is binary but should be text."
1870
2151
 
1871
2152
 
1891
2172
 
1892
2173
 
1893
2174
class NotABundle(BzrError):
1894
 
 
 
2175
    
1895
2176
    _fmt = "Not a bzr revision-bundle: %(text)r"
1896
2177
 
1897
2178
    def __init__(self, text):
1899
2180
        self.text = text
1900
2181
 
1901
2182
 
1902
 
class BadBundle(BzrError):
1903
 
 
 
2183
class BadBundle(BzrError): 
 
2184
    
1904
2185
    _fmt = "Bad bzr revision-bundle: %(text)r"
1905
2186
 
1906
2187
    def __init__(self, text):
1908
2189
        self.text = text
1909
2190
 
1910
2191
 
1911
 
class MalformedHeader(BadBundle):
1912
 
 
 
2192
class MalformedHeader(BadBundle): 
 
2193
    
1913
2194
    _fmt = "Malformed bzr revision-bundle header: %(text)r"
1914
2195
 
1915
2196
 
1916
 
class MalformedPatches(BadBundle):
1917
 
 
 
2197
class MalformedPatches(BadBundle): 
 
2198
    
1918
2199
    _fmt = "Malformed patches in bzr revision-bundle: %(text)r"
1919
2200
 
1920
2201
 
1921
 
class MalformedFooter(BadBundle):
1922
 
 
 
2202
class MalformedFooter(BadBundle): 
 
2203
    
1923
2204
    _fmt = "Malformed footer in bzr revision-bundle: %(text)r"
1924
2205
 
1925
2206
 
1926
2207
class UnsupportedEOLMarker(BadBundle):
1927
 
 
1928
 
    _fmt = "End of line marker was not \\n in bzr revision-bundle"
 
2208
    
 
2209
    _fmt = "End of line marker was not \\n in bzr revision-bundle"    
1929
2210
 
1930
2211
    def __init__(self):
1931
 
        # XXX: BadBundle's constructor assumes there's explanatory text,
 
2212
        # XXX: BadBundle's constructor assumes there's explanatory text, 
1932
2213
        # but for this there is not
1933
2214
        BzrError.__init__(self)
1934
2215
 
1935
2216
 
1936
2217
class IncompatibleBundleFormat(BzrError):
1937
 
 
 
2218
    
1938
2219
    _fmt = "Bundle format %(bundle_format)s is incompatible with %(other)s"
1939
2220
 
1940
2221
    def __init__(self, bundle_format, other):
1944
2225
 
1945
2226
 
1946
2227
class BadInventoryFormat(BzrError):
1947
 
 
 
2228
    
1948
2229
    _fmt = "Root class for inventory serialization errors"
1949
2230
 
1950
2231
 
1969
2250
        self.transport = transport
1970
2251
 
1971
2252
 
 
2253
class NoSmartServer(NotBranchError):
 
2254
 
 
2255
    _fmt = "No smart server available at %(url)s"
 
2256
 
 
2257
    @symbol_versioning.deprecated_method(symbol_versioning.one_four)
 
2258
    def __init__(self, url):
 
2259
        self.url = url
 
2260
 
 
2261
 
1972
2262
class UnknownSSH(BzrError):
1973
2263
 
1974
 
    _fmt = "Unrecognised value for BRZ_SSH environment variable: %(vendor)s"
 
2264
    _fmt = "Unrecognised value for BZR_SSH environment variable: %(vendor)s"
1975
2265
 
1976
2266
    def __init__(self, vendor):
1977
2267
        BzrError.__init__(self)
1981
2271
class SSHVendorNotFound(BzrError):
1982
2272
 
1983
2273
    _fmt = ("Don't know how to handle SSH connections."
1984
 
            " Please set BRZ_SSH environment variable.")
 
2274
            " Please set BZR_SSH environment variable.")
1985
2275
 
1986
2276
 
1987
2277
class GhostRevisionsHaveNoRevno(BzrError):
1994
2284
        self.revision_id = revision_id
1995
2285
        self.ghost_revision_id = ghost_revision_id
1996
2286
 
1997
 
 
 
2287
        
1998
2288
class GhostRevisionUnusableHere(BzrError):
1999
2289
 
2000
2290
    _fmt = "Ghost revision {%(revision_id)s} cannot be used here."
2078
2368
        self.patch_type = patch_type
2079
2369
 
2080
2370
 
2081
 
class TargetNotBranch(BzrError):
2082
 
    """A merge directive's target branch is required, but isn't a branch"""
2083
 
 
2084
 
    _fmt = ("Your branch does not have all of the revisions required in "
2085
 
            "order to merge this merge directive and the target "
2086
 
            "location specified in the merge directive is not a branch: "
2087
 
            "%(location)s.")
2088
 
 
2089
 
    def __init__(self, location):
2090
 
        BzrError.__init__(self)
2091
 
        self.location = location
2092
 
 
2093
 
 
2094
2371
class UnsupportedInventoryKind(BzrError):
2095
 
 
 
2372
    
2096
2373
    _fmt = """Unsupported entry kind %(kind)s"""
2097
2374
 
2098
2375
    def __init__(self, kind):
2110
2387
 
2111
2388
 
2112
2389
class SubsumeTargetNeedsUpgrade(BzrError):
2113
 
 
 
2390
    
2114
2391
    _fmt = """Subsume target %(other_tree)s needs to be upgraded."""
2115
2392
 
2116
2393
    def __init__(self, other_tree):
2117
2394
        self.other_tree = other_tree
2118
2395
 
2119
2396
 
 
2397
class BadReferenceTarget(InternalBzrError):
 
2398
 
 
2399
    _fmt = "Can't add reference to %(other_tree)s into %(tree)s." \
 
2400
           "%(reason)s"
 
2401
 
 
2402
    def __init__(self, tree, other_tree, reason):
 
2403
        self.tree = tree
 
2404
        self.other_tree = other_tree
 
2405
        self.reason = reason
 
2406
 
 
2407
 
2120
2408
class NoSuchTag(BzrError):
2121
2409
 
2122
2410
    _fmt = "No such tag: %(tag_name)s"
2128
2416
class TagsNotSupported(BzrError):
2129
2417
 
2130
2418
    _fmt = ("Tags not supported by %(branch)s;"
2131
 
            " you may be able to use brz upgrade.")
 
2419
            " you may be able to use bzr upgrade --dirstate-tags.")
2132
2420
 
2133
2421
    def __init__(self, branch):
2134
2422
        self.branch = branch
2135
2423
 
2136
 
 
 
2424
        
2137
2425
class TagAlreadyExists(BzrError):
2138
2426
 
2139
2427
    _fmt = "Tag %(tag_name)s already exists."
2142
2430
        self.tag_name = tag_name
2143
2431
 
2144
2432
 
 
2433
class MalformedBugIdentifier(BzrError):
 
2434
 
 
2435
    _fmt = "Did not understand bug identifier %(bug_id)s: %(reason)s"
 
2436
 
 
2437
    def __init__(self, bug_id, reason):
 
2438
        self.bug_id = bug_id
 
2439
        self.reason = reason
 
2440
 
 
2441
 
 
2442
class InvalidBugTrackerURL(BzrError):
 
2443
 
 
2444
    _fmt = ("The URL for bug tracker \"%(abbreviation)s\" doesn't "
 
2445
            "contain {id}: %(url)s")
 
2446
 
 
2447
    def __init__(self, abbreviation, url):
 
2448
        self.abbreviation = abbreviation
 
2449
        self.url = url
 
2450
 
 
2451
 
 
2452
class UnknownBugTrackerAbbreviation(BzrError):
 
2453
 
 
2454
    _fmt = ("Cannot find registered bug tracker called %(abbreviation)s "
 
2455
            "on %(branch)s")
 
2456
 
 
2457
    def __init__(self, abbreviation, branch):
 
2458
        self.abbreviation = abbreviation
 
2459
        self.branch = branch
 
2460
 
 
2461
 
2145
2462
class UnexpectedSmartServerResponse(BzrError):
2146
2463
 
2147
2464
    _fmt = "Could not understand response from smart server: %(response_tuple)r"
2151
2468
 
2152
2469
 
2153
2470
class ErrorFromSmartServer(BzrError):
2154
 
    """An error was received from a smart server.
2155
 
 
2156
 
    :seealso: UnknownErrorFromSmartServer
2157
 
    """
2158
2471
 
2159
2472
    _fmt = "Error received from smart server: %(error_tuple)r"
2160
2473
 
2169
2482
        self.error_args = error_tuple[1:]
2170
2483
 
2171
2484
 
2172
 
class UnknownErrorFromSmartServer(BzrError):
2173
 
    """An ErrorFromSmartServer could not be translated into a typical breezy
2174
 
    error.
2175
 
 
2176
 
    This is distinct from ErrorFromSmartServer so that it is possible to
2177
 
    distinguish between the following two cases:
2178
 
 
2179
 
    - ErrorFromSmartServer was uncaught.  This is logic error in the client
2180
 
      and so should provoke a traceback to the user.
2181
 
    - ErrorFromSmartServer was caught but its error_tuple could not be
2182
 
      translated.  This is probably because the server sent us garbage, and
2183
 
      should not provoke a traceback.
2184
 
    """
2185
 
 
2186
 
    _fmt = "Server sent an unexpected error: %(error_tuple)r"
2187
 
 
2188
 
    internal_error = False
2189
 
 
2190
 
    def __init__(self, error_from_smart_server):
2191
 
        """Constructor.
2192
 
 
2193
 
        :param error_from_smart_server: An ErrorFromSmartServer instance.
2194
 
        """
2195
 
        self.error_from_smart_server = error_from_smart_server
2196
 
        self.error_tuple = error_from_smart_server.error_tuple
2197
 
 
2198
 
 
2199
2485
class ContainerError(BzrError):
2200
2486
    """Base class of container errors."""
2201
2487
 
2203
2489
class UnknownContainerFormatError(ContainerError):
2204
2490
 
2205
2491
    _fmt = "Unrecognised container format: %(container_format)r"
2206
 
 
 
2492
    
2207
2493
    def __init__(self, container_format):
2208
2494
        self.container_format = container_format
2209
2495
 
2242
2528
    _fmt = "Container has multiple records with the same name: %(name)s"
2243
2529
 
2244
2530
    def __init__(self, name):
2245
 
        self.name = name.decode("utf-8")
 
2531
        self.name = name
 
2532
 
 
2533
 
 
2534
class NoDestinationAddress(InternalBzrError):
 
2535
 
 
2536
    _fmt = "Message does not have a destination address."
2246
2537
 
2247
2538
 
2248
2539
class RepositoryDataStreamError(BzrError):
2253
2544
        self.reason = reason
2254
2545
 
2255
2546
 
 
2547
class SMTPError(BzrError):
 
2548
 
 
2549
    _fmt = "SMTP error: %(error)s"
 
2550
 
 
2551
    def __init__(self, error):
 
2552
        self.error = error
 
2553
 
 
2554
 
 
2555
class NoMessageSupplied(BzrError):
 
2556
 
 
2557
    _fmt = "No message supplied."
 
2558
 
 
2559
 
 
2560
class NoMailAddressSpecified(BzrError):
 
2561
 
 
2562
    _fmt = "No mail-to address specified."
 
2563
 
 
2564
 
 
2565
class UnknownMailClient(BzrError):
 
2566
 
 
2567
    _fmt = "Unknown mail client: %(mail_client)s"
 
2568
 
 
2569
    def __init__(self, mail_client):
 
2570
        BzrError.__init__(self, mail_client=mail_client)
 
2571
 
 
2572
 
 
2573
class MailClientNotFound(BzrError):
 
2574
 
 
2575
    _fmt = "Unable to find mail client with the following names:"\
 
2576
        " %(mail_command_list_string)s"
 
2577
 
 
2578
    def __init__(self, mail_command_list):
 
2579
        mail_command_list_string = ', '.join(mail_command_list)
 
2580
        BzrError.__init__(self, mail_command_list=mail_command_list,
 
2581
                          mail_command_list_string=mail_command_list_string)
 
2582
 
 
2583
class SMTPConnectionRefused(SMTPError):
 
2584
 
 
2585
    _fmt = "SMTP connection to %(host)s refused"
 
2586
 
 
2587
    def __init__(self, error, host):
 
2588
        self.error = error
 
2589
        self.host = host
 
2590
 
 
2591
 
 
2592
class DefaultSMTPConnectionRefused(SMTPConnectionRefused):
 
2593
 
 
2594
    _fmt = "Please specify smtp_server.  No server at default %(host)s."
 
2595
 
 
2596
 
 
2597
class BzrDirError(BzrError):
 
2598
 
 
2599
    def __init__(self, bzrdir):
 
2600
        import bzrlib.urlutils as urlutils
 
2601
        display_url = urlutils.unescape_for_display(bzrdir.root_transport.base,
 
2602
                                                    'ascii')
 
2603
        BzrError.__init__(self, bzrdir=bzrdir, display_url=display_url)
 
2604
 
 
2605
 
 
2606
class UnsyncedBranches(BzrDirError):
 
2607
 
 
2608
    _fmt = ("'%(display_url)s' is not in sync with %(target_url)s.  See"
 
2609
            " bzr help sync-for-reconfigure.")
 
2610
 
 
2611
    def __init__(self, bzrdir, target_branch):
 
2612
        BzrDirError.__init__(self, bzrdir)
 
2613
        import bzrlib.urlutils as urlutils
 
2614
        self.target_url = urlutils.unescape_for_display(target_branch.base,
 
2615
                                                        'ascii')
 
2616
 
 
2617
 
 
2618
class AlreadyBranch(BzrDirError):
 
2619
 
 
2620
    _fmt = "'%(display_url)s' is already a branch."
 
2621
 
 
2622
 
 
2623
class AlreadyTree(BzrDirError):
 
2624
 
 
2625
    _fmt = "'%(display_url)s' is already a tree."
 
2626
 
 
2627
 
 
2628
class AlreadyCheckout(BzrDirError):
 
2629
 
 
2630
    _fmt = "'%(display_url)s' is already a checkout."
 
2631
 
 
2632
 
 
2633
class AlreadyLightweightCheckout(BzrDirError):
 
2634
 
 
2635
    _fmt = "'%(display_url)s' is already a lightweight checkout."
 
2636
 
 
2637
 
 
2638
class AlreadyUsingShared(BzrDirError):
 
2639
 
 
2640
    _fmt = "'%(display_url)s' is already using a shared repository."
 
2641
 
 
2642
 
 
2643
class AlreadyStandalone(BzrDirError):
 
2644
 
 
2645
    _fmt = "'%(display_url)s' is already standalone."
 
2646
 
 
2647
 
 
2648
class ReconfigurationNotSupported(BzrDirError):
 
2649
 
 
2650
    _fmt = "Requested reconfiguration of '%(display_url)s' is not supported."
 
2651
 
 
2652
 
 
2653
class NoBindLocation(BzrDirError):
 
2654
 
 
2655
    _fmt = "No location could be found to bind to at %(display_url)s."
 
2656
 
 
2657
 
2256
2658
class UncommittedChanges(BzrError):
2257
2659
 
2258
 
    _fmt = ('Working tree "%(display_url)s" has uncommitted changes'
2259
 
            ' (See brz status).%(more)s')
2260
 
 
2261
 
    def __init__(self, tree, more=None):
2262
 
        if more is None:
2263
 
            more = ''
2264
 
        else:
2265
 
            more = ' ' + more
2266
 
        import breezy.urlutils as urlutils
2267
 
        user_url = getattr(tree, "user_url", None)
2268
 
        if user_url is None:
2269
 
            display_url = str(tree)
2270
 
        else:
2271
 
            display_url = urlutils.unescape_for_display(user_url, 'ascii')
2272
 
        BzrError.__init__(self, tree=tree, display_url=display_url, more=more)
2273
 
 
2274
 
 
2275
 
class StoringUncommittedNotSupported(BzrError):
2276
 
 
2277
 
    _fmt = ('Branch "%(display_url)s" does not support storing uncommitted'
2278
 
            ' changes.')
2279
 
 
2280
 
    def __init__(self, branch):
2281
 
        import breezy.urlutils as urlutils
2282
 
        user_url = getattr(branch, "user_url", None)
2283
 
        if user_url is None:
2284
 
            display_url = str(branch)
2285
 
        else:
2286
 
            display_url = urlutils.unescape_for_display(user_url, 'ascii')
2287
 
        BzrError.__init__(self, branch=branch, display_url=display_url)
2288
 
 
2289
 
 
2290
 
class ShelvedChanges(UncommittedChanges):
2291
 
 
2292
 
    _fmt = ('Working tree "%(display_url)s" has shelved changes'
2293
 
            ' (See brz shelve --list).%(more)s')
 
2660
    _fmt = 'Working tree "%(display_url)s" has uncommitted changes.'
 
2661
 
 
2662
    def __init__(self, tree):
 
2663
        import bzrlib.urlutils as urlutils
 
2664
        display_url = urlutils.unescape_for_display(
 
2665
            tree.bzrdir.root_transport.base, 'ascii')
 
2666
        BzrError.__init__(self, tree=tree, display_url=display_url)
 
2667
 
 
2668
 
 
2669
class MissingTemplateVariable(BzrError):
 
2670
 
 
2671
    _fmt = 'Variable {%(name)s} is not available.'
 
2672
 
 
2673
    def __init__(self, name):
 
2674
        self.name = name
 
2675
 
 
2676
 
 
2677
class NoTemplate(BzrError):
 
2678
 
 
2679
    _fmt = 'No template specified.'
2294
2680
 
2295
2681
 
2296
2682
class UnableCreateSymlink(BzrError):
2308
2694
        self.path_str = path_str
2309
2695
 
2310
2696
 
 
2697
class UnsupportedTimezoneFormat(BzrError):
 
2698
 
 
2699
    _fmt = ('Unsupported timezone format "%(timezone)s", '
 
2700
            'options are "utc", "original", "local".')
 
2701
 
 
2702
    def __init__(self, timezone):
 
2703
        self.timezone = timezone
 
2704
 
 
2705
 
 
2706
class CommandAvailableInPlugin(StandardError):
 
2707
    
 
2708
    internal_error = False
 
2709
 
 
2710
    def __init__(self, cmd_name, plugin_metadata, provider):
 
2711
        
 
2712
        self.plugin_metadata = plugin_metadata
 
2713
        self.cmd_name = cmd_name
 
2714
        self.provider = provider
 
2715
 
 
2716
    def __str__(self):
 
2717
 
 
2718
        _fmt = ('"%s" is not a standard bzr command. \n' 
 
2719
                'However, the following official plugin provides this command: %s\n'
 
2720
                'You can install it by going to: %s'
 
2721
                % (self.cmd_name, self.plugin_metadata['name'], 
 
2722
                    self.plugin_metadata['url']))
 
2723
 
 
2724
        return _fmt
 
2725
 
 
2726
 
 
2727
class NoPluginAvailable(BzrError):
 
2728
    pass    
 
2729
 
 
2730
 
 
2731
class NotATerminal(BzrError):
 
2732
 
 
2733
    _fmt = 'Unable to ask for a password without real terminal.'
 
2734
 
 
2735
 
2311
2736
class UnableEncodePath(BzrError):
2312
2737
 
2313
2738
    _fmt = ('Unable to encode %(kind)s path %(path)r in '
2314
2739
            'user encoding %(user_encoding)s')
2315
2740
 
2316
2741
    def __init__(self, path, kind):
2317
 
        from breezy.osutils import get_user_encoding
2318
2742
        self.path = path
2319
2743
        self.kind = kind
2320
 
        self.user_encoding = get_user_encoding()
 
2744
        self.user_encoding = osutils.get_user_encoding()
2321
2745
 
2322
2746
 
2323
2747
class NoSuchAlias(BzrError):
2328
2752
        BzrError.__init__(self, alias_name=alias_name)
2329
2753
 
2330
2754
 
 
2755
class DirectoryLookupFailure(BzrError):
 
2756
    """Base type for lookup errors."""
 
2757
 
 
2758
    pass
 
2759
 
 
2760
 
 
2761
class InvalidLocationAlias(DirectoryLookupFailure):
 
2762
 
 
2763
    _fmt = '"%(alias_name)s" is not a valid location alias.'
 
2764
 
 
2765
    def __init__(self, alias_name):
 
2766
        DirectoryLookupFailure.__init__(self, alias_name=alias_name)
 
2767
 
 
2768
 
 
2769
class UnsetLocationAlias(DirectoryLookupFailure):
 
2770
 
 
2771
    _fmt = 'No %(alias_name)s location assigned.'
 
2772
 
 
2773
    def __init__(self, alias_name):
 
2774
        DirectoryLookupFailure.__init__(self, alias_name=alias_name[1:])
 
2775
 
 
2776
 
2331
2777
class CannotBindAddress(BzrError):
2332
2778
 
2333
2779
    _fmt = 'Cannot bind address "%(host)s:%(port)i": %(orig_error)s.'
2334
2780
 
2335
2781
    def __init__(self, host, port, orig_error):
2336
 
        # nb: in python2.4 socket.error doesn't have a useful repr
2337
2782
        BzrError.__init__(self, host=host, port=port,
2338
 
            orig_error=repr(orig_error.args))
2339
 
 
2340
 
 
2341
 
class TipChangeRejected(BzrError):
2342
 
    """A pre_change_branch_tip hook function may raise this to cleanly and
2343
 
    explicitly abort a change to a branch tip.
2344
 
    """
2345
 
 
2346
 
    _fmt = u"Tip change rejected: %(msg)s"
2347
 
 
2348
 
    def __init__(self, msg):
2349
 
        self.msg = msg
2350
 
 
2351
 
 
2352
 
class JailBreak(BzrError):
2353
 
 
2354
 
    _fmt = "An attempt to access a url outside the server jail was made: '%(url)s'."
2355
 
 
2356
 
    def __init__(self, url):
2357
 
        BzrError.__init__(self, url=url)
2358
 
 
2359
 
 
2360
 
class UserAbort(BzrError):
2361
 
 
2362
 
    _fmt = 'The user aborted the operation.'
2363
 
 
2364
 
 
2365
 
class UnresumableWriteGroup(BzrError):
2366
 
 
2367
 
    _fmt = ("Repository %(repository)s cannot resume write group "
2368
 
            "%(write_groups)r: %(reason)s")
2369
 
 
2370
 
    internal_error = True
2371
 
 
2372
 
    def __init__(self, repository, write_groups, reason):
2373
 
        self.repository = repository
2374
 
        self.write_groups = write_groups
2375
 
        self.reason = reason
2376
 
 
2377
 
 
2378
 
class UnsuspendableWriteGroup(BzrError):
2379
 
 
2380
 
    _fmt = ("Repository %(repository)s cannot suspend a write group.")
2381
 
 
2382
 
    internal_error = True
2383
 
 
2384
 
    def __init__(self, repository):
2385
 
        self.repository = repository
2386
 
 
2387
 
 
2388
 
class LossyPushToSameVCS(BzrError):
2389
 
 
2390
 
    _fmt = ("Lossy push not possible between %(source_branch)r and "
2391
 
            "%(target_branch)r that are in the same VCS.")
2392
 
 
2393
 
    internal_error = True
2394
 
 
2395
 
    def __init__(self, source_branch, target_branch):
2396
 
        self.source_branch = source_branch
2397
 
        self.target_branch = target_branch
2398
 
 
2399
 
 
2400
 
class NoRoundtrippingSupport(BzrError):
2401
 
 
2402
 
    _fmt = ("Roundtripping is not supported between %(source_branch)r and "
2403
 
            "%(target_branch)r.")
2404
 
 
2405
 
    internal_error = True
2406
 
 
2407
 
    def __init__(self, source_branch, target_branch):
2408
 
        self.source_branch = source_branch
2409
 
        self.target_branch = target_branch
2410
 
 
2411
 
 
2412
 
class NoColocatedBranchSupport(BzrError):
2413
 
 
2414
 
    _fmt = ("%(controldir)r does not support co-located branches.")
2415
 
 
2416
 
    def __init__(self, controldir):
2417
 
        self.controldir = controldir
2418
 
 
2419
 
 
2420
 
class RecursiveBind(BzrError):
2421
 
 
2422
 
    _fmt = ('Branch "%(branch_url)s" appears to be bound to itself. '
2423
 
        'Please use `brz unbind` to fix.')
2424
 
 
2425
 
    def __init__(self, branch_url):
2426
 
        self.branch_url = branch_url
2427
 
 
2428
 
 
2429
 
class UnsupportedKindChange(BzrError):
2430
 
 
2431
 
    _fmt = ("Kind change from %(from_kind)s to %(to_kind)s for "
2432
 
            "%(path)s not supported by format %(format)r")
2433
 
 
2434
 
    def __init__(self, path, from_kind, to_kind, format):
2435
 
        self.path = path
2436
 
        self.from_kind = from_kind
2437
 
        self.to_kind = to_kind
2438
 
        self.format = format
2439
 
 
2440
 
 
2441
 
class ChangesAlreadyStored(BzrCommandError):
2442
 
 
2443
 
    _fmt = ('Cannot store uncommitted changes because this branch already'
2444
 
            ' stores uncommitted changes.')
 
2783
            orig_error=orig_error[1])
 
2784
 
 
2785
 
 
2786
class UnknownRules(BzrError):
 
2787
 
 
2788
    _fmt = ('Unknown rules detected: %(unknowns_str)s.')
 
2789
 
 
2790
    def __init__(self, unknowns):
 
2791
        BzrError.__init__(self, unknowns_str=", ".join(unknowns))