/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: John Arbash Meinel
  • Author(s): Mark Hammond
  • Date: 2008-09-09 17:02:21 UTC
  • mto: This revision was merged to the branch mainline in revision 3697.
  • Revision ID: john@arbash-meinel.com-20080909170221-svim3jw2mrz0amp3
An updated transparent icon for bzr.

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.
91
98
        if s is not None:
92
99
            # contains a preformatted message
93
100
            return s
94
 
        err = None
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.
102
111
                return s
103
 
        except Exception as e:
104
 
            err = e
105
 
        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 _get_format_string(self):
 
140
        """Return format string for this exception or None"""
 
141
        fmt = getattr(self, '_fmt', None)
 
142
        if fmt is not None:
 
143
            return fmt
 
144
        fmt = getattr(self, '__doc__', None)
 
145
        if fmt is not None:
 
146
            symbol_versioning.warn("%s uses its docstring as a format, "
 
147
                    "it should use _fmt instead" % self.__class__.__name__,
 
148
                    DeprecationWarning)
 
149
            return fmt
 
150
        return 'Unprintable exception %s: dict=%r, fmt=%r' \
106
151
            % (self.__class__.__name__,
107
152
               self.__dict__,
108
153
               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
 
154
               )
128
155
 
129
156
    def __eq__(self, other):
130
 
        if self.__class__ is not other.__class__:
 
157
        if self.__class__ != other.__class__:
131
158
            return NotImplemented
132
159
        return self.__dict__ == other.__dict__
133
160
 
134
 
    def __hash__(self):
135
 
        return id(self)
136
 
 
137
161
 
138
162
class InternalBzrError(BzrError):
139
163
    """Base class for errors that are internal in nature.
146
170
    internal_error = True
147
171
 
148
172
 
 
173
class BzrNewError(BzrError):
 
174
    """Deprecated error base class."""
 
175
    # base classes should override the docstring with their human-
 
176
    # readable explanation
 
177
 
 
178
    def __init__(self, *args, **kwds):
 
179
        # XXX: Use the underlying BzrError to always generate the args
 
180
        # attribute if it doesn't exist.  We can't use super here, because
 
181
        # exceptions are old-style classes in python2.4 (but new in 2.5).
 
182
        # --bmc, 20060426
 
183
        symbol_versioning.warn('BzrNewError was deprecated in bzr 0.13; '
 
184
             'please convert %s to use BzrError instead'
 
185
             % self.__class__.__name__,
 
186
             DeprecationWarning,
 
187
             stacklevel=2)
 
188
        BzrError.__init__(self, *args)
 
189
        for key, value in kwds.items():
 
190
            setattr(self, key, value)
 
191
 
 
192
    def __str__(self):
 
193
        try:
 
194
            # __str__() should always return a 'str' object
 
195
            # never a 'unicode' object.
 
196
            s = self.__doc__ % self.__dict__
 
197
            if isinstance(s, unicode):
 
198
                return s.encode('utf8')
 
199
            return s
 
200
        except (TypeError, NameError, ValueError, KeyError), e:
 
201
            return 'Unprintable exception %s(%r): %r' \
 
202
                % (self.__class__.__name__,
 
203
                   self.__dict__, e)
 
204
 
 
205
 
 
206
class AlreadyBuilding(BzrError):
 
207
    
 
208
    _fmt = "The tree builder is already building a tree."
 
209
 
 
210
 
149
211
class BranchError(BzrError):
150
212
    """Base class for concrete 'errors about a branch'."""
151
213
 
154
216
 
155
217
 
156
218
class BzrCheckError(InternalBzrError):
157
 
 
158
 
    _fmt = "Internal check failed: %(msg)s"
159
 
 
160
 
    def __init__(self, msg):
161
 
        BzrError.__init__(self)
 
219
    
 
220
    _fmt = "Internal check failed: %(message)s"
 
221
 
 
222
    def __init__(self, message):
 
223
        BzrError.__init__(self)
 
224
        self.message = message
 
225
 
 
226
 
 
227
class DirstateCorrupt(BzrError):
 
228
 
 
229
    _fmt = "The dirstate file (%(state)s) appears to be corrupt: %(msg)s"
 
230
 
 
231
    def __init__(self, state, msg):
 
232
        BzrError.__init__(self)
 
233
        self.state = state
162
234
        self.msg = msg
163
235
 
164
236
 
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):
 
237
class DisabledMethod(InternalBzrError):
 
238
 
 
239
    _fmt = "The smart server method '%(class_name)s' is disabled."
 
240
 
 
241
    def __init__(self, class_name):
 
242
        BzrError.__init__(self)
 
243
        self.class_name = class_name
 
244
 
 
245
 
 
246
class IncompatibleAPI(BzrError):
 
247
 
 
248
    _fmt = 'The API for "%(api)s" is not compatible with "%(wanted)s". '\
 
249
        'It supports versions "%(minimum)s" to "%(current)s".'
 
250
 
 
251
    def __init__(self, api, wanted, minimum, current):
171
252
        self.api = api
172
253
        self.wanted = wanted
 
254
        self.minimum = minimum
173
255
        self.current = current
174
256
 
175
257
 
183
265
 
184
266
 
185
267
class InvalidEntryName(InternalBzrError):
186
 
 
 
268
    
187
269
    _fmt = "Invalid entry name: %(name)s"
188
270
 
189
271
    def __init__(self, name):
192
274
 
193
275
 
194
276
class InvalidRevisionNumber(BzrError):
195
 
 
 
277
    
196
278
    _fmt = "Invalid revision number %(revno)s"
197
279
 
198
280
    def __init__(self, revno):
222
304
class RootMissing(InternalBzrError):
223
305
 
224
306
    _fmt = ("The root entry of a tree must be the first entry supplied to "
225
 
        "the commit builder.")
 
307
        "record_entry_contents.")
226
308
 
227
309
 
228
310
class NoPublicBranch(BzrError):
230
312
    _fmt = 'There is no public branch set for "%(branch_url)s".'
231
313
 
232
314
    def __init__(self, branch):
233
 
        from . import urlutils
 
315
        import bzrlib.urlutils as urlutils
234
316
        public_location = urlutils.unescape_for_display(branch.base, 'ascii')
235
317
        BzrError.__init__(self, branch_url=public_location)
236
318
 
237
319
 
 
320
class NoHelpTopic(BzrError):
 
321
 
 
322
    _fmt = ("No help could be found for '%(topic)s'. "
 
323
        "Please use 'bzr help topics' to obtain a list of topics.")
 
324
 
 
325
    def __init__(self, topic):
 
326
        self.topic = topic
 
327
 
 
328
 
238
329
class NoSuchId(BzrError):
239
330
 
240
331
    _fmt = 'The file id "%(file_id)s" is not present in the tree %(tree)s.'
241
 
 
 
332
    
242
333
    def __init__(self, tree, file_id):
243
334
        BzrError.__init__(self)
244
335
        self.file_id = file_id
245
336
        self.tree = tree
246
337
 
247
338
 
 
339
class NoSuchIdInRepository(NoSuchId):
 
340
 
 
341
    _fmt = ('The file id "%(file_id)s" is not present in the repository'
 
342
            ' %(repository)r')
 
343
 
 
344
    def __init__(self, repository, file_id):
 
345
        BzrError.__init__(self, repository=repository, file_id=file_id)
 
346
 
 
347
 
248
348
class NotStacked(BranchError):
249
349
 
250
350
    _fmt = "The branch '%(branch)s' is not stacked."
262
362
class NoWorkingTree(BzrError):
263
363
 
264
364
    _fmt = 'No WorkingTree exists for "%(base)s".'
265
 
 
 
365
    
266
366
    def __init__(self, base):
267
367
        BzrError.__init__(self)
268
368
        self.base = base
269
369
 
270
370
 
 
371
class NotBuilding(BzrError):
 
372
 
 
373
    _fmt = "Not currently building a tree."
 
374
 
 
375
 
271
376
class NotLocalUrl(BzrError):
272
377
 
273
378
    _fmt = "%(url)s is not a local path."
304
409
        self.not_locked = not_locked
305
410
 
306
411
 
 
412
class BzrOptionError(BzrCommandError):
 
413
 
 
414
    _fmt = "Error in command line options"
 
415
 
 
416
 
 
417
class BadIndexFormatSignature(BzrError):
 
418
 
 
419
    _fmt = "%(value)s is not an index of type %(_type)s."
 
420
 
 
421
    def __init__(self, value, _type):
 
422
        BzrError.__init__(self)
 
423
        self.value = value
 
424
        self._type = _type
 
425
 
 
426
 
 
427
class BadIndexData(BzrError):
 
428
 
 
429
    _fmt = "Error in data for index %(value)s."
 
430
 
 
431
    def __init__(self, value):
 
432
        BzrError.__init__(self)
 
433
        self.value = value
 
434
 
 
435
 
 
436
class BadIndexDuplicateKey(BzrError):
 
437
 
 
438
    _fmt = "The key '%(key)s' is already in index '%(index)s'."
 
439
 
 
440
    def __init__(self, key, index):
 
441
        BzrError.__init__(self)
 
442
        self.key = key
 
443
        self.index = index
 
444
 
 
445
 
 
446
class BadIndexKey(BzrError):
 
447
 
 
448
    _fmt = "The key '%(key)s' is not a valid key."
 
449
 
 
450
    def __init__(self, key):
 
451
        BzrError.__init__(self)
 
452
        self.key = key
 
453
 
 
454
 
 
455
class BadIndexOptions(BzrError):
 
456
 
 
457
    _fmt = "Could not parse options for index %(value)s."
 
458
 
 
459
    def __init__(self, value):
 
460
        BzrError.__init__(self)
 
461
        self.value = value
 
462
 
 
463
 
 
464
class BadIndexValue(BzrError):
 
465
 
 
466
    _fmt = "The value '%(value)s' is not a valid value."
 
467
 
 
468
    def __init__(self, value):
 
469
        BzrError.__init__(self)
 
470
        self.value = value
 
471
 
 
472
 
 
473
class BadOptionValue(BzrError):
 
474
 
 
475
    _fmt = """Bad value "%(value)s" for option "%(name)s"."""
 
476
 
 
477
    def __init__(self, name, value):
 
478
        BzrError.__init__(self, name=name, value=value)
 
479
 
 
480
    
307
481
class StrictCommitFailed(BzrError):
308
482
 
309
483
    _fmt = "Commit refused because there are unknown files in the tree"
312
486
# XXX: Should be unified with TransportError; they seem to represent the
313
487
# same thing
314
488
# 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
 
489
# - this is finer than a TransportError - and more useful as such. It 
316
490
# differentiates between 'transport has failed' and 'operation on a transport
317
491
# has failed.'
318
492
class PathError(BzrError):
319
 
 
 
493
    
320
494
    _fmt = "Generic path error: %(path)r%(extra)s)"
321
495
 
322
496
    def __init__(self, path, extra=None):
342
516
    """Used when renaming and both source and dest exist."""
343
517
 
344
518
    _fmt = ("Could not rename %(source)s => %(dest)s because both files exist."
345
 
            " (Use --after to tell brz about a rename that has already"
 
519
            " (Use --after to tell bzr about a rename that has already"
346
520
            " happened)%(extra)s")
347
521
 
348
522
    def __init__(self, source, dest, extra=None):
376
550
 
377
551
 
378
552
class ReadingCompleted(InternalBzrError):
379
 
 
 
553
    
380
554
    _fmt = ("The MediumRequest '%(request)s' has already had finish_reading "
381
555
            "called upon it - the request has been completed and no more "
382
556
            "data may be read.")
395
569
    _fmt = 'Permission denied: "%(path)s"%(extra)s'
396
570
 
397
571
 
 
572
class InvalidURL(PathError):
 
573
 
 
574
    _fmt = 'Invalid url supplied to transport: "%(path)s"%(extra)s'
 
575
 
 
576
 
 
577
class InvalidURLJoin(PathError):
 
578
 
 
579
    _fmt = "Invalid URL join request: %(reason)s: %(base)r + %(join_args)r"
 
580
 
 
581
    def __init__(self, reason, base, join_args):
 
582
        self.reason = reason
 
583
        self.base = base
 
584
        self.join_args = join_args
 
585
        PathError.__init__(self, base, reason)
 
586
 
 
587
 
 
588
class InvalidRebaseURLs(PathError):
 
589
 
 
590
    _fmt = "URLs differ by more than path: %(from_)r and %(to)r"
 
591
 
 
592
    def __init__(self, from_, to):
 
593
        self.from_ = from_
 
594
        self.to = to
 
595
        PathError.__init__(self, from_, 'URLs differ by more than path.')
 
596
 
 
597
 
398
598
class UnavailableRepresentation(InternalBzrError):
399
599
 
400
600
    _fmt = ("The encoding '%(wanted)s' is not available for key %(key)s which "
407
607
        self.key = key
408
608
 
409
609
 
 
610
class UnknownHook(BzrError):
 
611
 
 
612
    _fmt = "The %(type)s hook '%(hook)s' is unknown in this version of bzrlib."
 
613
 
 
614
    def __init__(self, hook_type, hook_name):
 
615
        BzrError.__init__(self)
 
616
        self.type = hook_type
 
617
        self.hook = hook_name
 
618
 
 
619
 
410
620
class UnsupportedProtocol(PathError):
411
621
 
412
622
    _fmt = 'Unsupported protocol for url "%(path)s"%(extra)s'
413
623
 
414
 
    def __init__(self, url, extra=""):
 
624
    def __init__(self, url, extra):
415
625
        PathError.__init__(self, url, extra=extra)
416
626
 
417
627
 
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):
 
628
class UnstackableBranchFormat(BzrError):
 
629
 
 
630
    _fmt = ("The branch '%(url)s'(%(format)s) is not a stackable format. "
 
631
        "You will need to upgrade the branch to permit branch stacking.")
 
632
 
 
633
    def __init__(self, format, url):
423
634
        BzrError.__init__(self)
424
 
        self.branch_url = branch_url
425
 
        self.target_url = target_url
 
635
        self.format = format
 
636
        self.url = url
426
637
 
427
638
 
428
639
class UnstackableRepositoryFormat(BzrError):
437
648
 
438
649
 
439
650
class ReadError(PathError):
440
 
 
 
651
    
441
652
    _fmt = """Error reading from %(path)r."""
442
653
 
443
654
 
459
670
 
460
671
    _fmt = 'Path "%(path)s" is not a child of path "%(base)s"%(extra)s'
461
672
 
462
 
    internal_error = False
 
673
    internal_error = True
463
674
 
464
675
    def __init__(self, path, base, extra=None):
465
676
        BzrError.__init__(self)
478
689
 
479
690
# TODO: This is given a URL; we try to unescape it but doing that from inside
480
691
# the exception object is a bit undesirable.
481
 
# TODO: Probably this behavior of should be a common superclass
 
692
# TODO: Probably this behavior of should be a common superclass 
482
693
class NotBranchError(PathError):
483
694
 
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 ''
 
695
    _fmt = 'Not a branch: "%(path)s".'
 
696
 
 
697
    def __init__(self, path):
 
698
       import bzrlib.urlutils as urlutils
 
699
       self.path = urlutils.unescape_for_display(path, 'ascii')
522
700
 
523
701
 
524
702
class NoSubmitBranch(PathError):
526
704
    _fmt = 'No submit branch available for branch "%(path)s"'
527
705
 
528
706
    def __init__(self, branch):
529
 
       from . import urlutils
 
707
       import bzrlib.urlutils as urlutils
530
708
       self.path = urlutils.unescape_for_display(branch.base, 'ascii')
531
709
 
532
710
 
533
 
class AlreadyControlDirError(PathError):
534
 
 
535
 
    _fmt = 'A control directory already exists: "%(path)s".'
536
 
 
537
 
 
538
711
class AlreadyBranchError(PathError):
539
712
 
540
713
    _fmt = 'Already a branch: "%(path)s".'
541
714
 
542
715
 
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
716
class BranchExistsWithoutWorkingTree(PathError):
558
717
 
559
718
    _fmt = 'Directory contains a branch, but no working tree \
560
 
(use brz checkout if you wish to build a working tree): "%(path)s"'
 
719
(use bzr checkout if you wish to build a working tree): "%(path)s"'
561
720
 
562
721
 
563
722
class AtomicFileAlreadyClosed(PathError):
583
742
class NoRepositoryPresent(BzrError):
584
743
 
585
744
    _fmt = 'No repository present: "%(path)s"'
586
 
    def __init__(self, controldir):
587
 
        BzrError.__init__(self)
588
 
        self.path = controldir.transport.clone('..').base
 
745
    def __init__(self, bzrdir):
 
746
        BzrError.__init__(self)
 
747
        self.path = bzrdir.transport.clone('..').base
 
748
 
 
749
 
 
750
class FileInWrongBranch(BzrError):
 
751
 
 
752
    _fmt = 'File "%(path)s" is not in branch %(branch_base)s.'
 
753
 
 
754
    def __init__(self, branch, path):
 
755
        BzrError.__init__(self)
 
756
        self.branch = branch
 
757
        self.branch_base = branch.base
 
758
        self.path = path
589
759
 
590
760
 
591
761
class UnsupportedFormatError(BzrError):
592
762
 
593
 
    _fmt = "Unsupported branch format: %(format)s\nPlease run 'brz upgrade'"
 
763
    _fmt = "Unsupported branch format: %(format)s\nPlease run 'bzr upgrade'"
594
764
 
595
765
 
596
766
class UnknownFormatError(BzrError):
597
 
 
 
767
    
598
768
    _fmt = "Unknown %(kind)s format: %(format)r"
599
769
 
600
770
    def __init__(self, format, kind='branch'):
603
773
 
604
774
 
605
775
class IncompatibleFormat(BzrError):
606
 
 
607
 
    _fmt = "Format %(format)s is not compatible with .bzr version %(controldir)s."
608
 
 
609
 
    def __init__(self, format, controldir_format):
610
 
        BzrError.__init__(self)
611
 
        self.format = format
612
 
        self.controldir = controldir_format
613
 
 
614
 
 
615
 
class ParseFormatError(BzrError):
616
 
 
617
 
    _fmt = "Parse error on line %(lineno)d of %(format)s format: %(line)s"
618
 
 
619
 
    def __init__(self, format, lineno, line, text):
620
 
        BzrError.__init__(self)
621
 
        self.format = format
622
 
        self.lineno = lineno
623
 
        self.line = line
624
 
        self.text = text
 
776
    
 
777
    _fmt = "Format %(format)s is not compatible with .bzr version %(bzrdir)s."
 
778
 
 
779
    def __init__(self, format, bzrdir_format):
 
780
        BzrError.__init__(self)
 
781
        self.format = format
 
782
        self.bzrdir = bzrdir_format
625
783
 
626
784
 
627
785
class IncompatibleRepositories(BzrError):
628
 
    """Report an error that two repositories are not compatible.
629
 
 
630
 
    Note that the source and target repositories are permitted to be strings:
631
 
    this exception is thrown from the smart server and may refer to a
632
 
    repository the client hasn't opened.
633
 
    """
634
786
 
635
787
    _fmt = "%(target)s\n" \
636
788
            "is not compatible with\n" \
644
796
 
645
797
 
646
798
class IncompatibleRevision(BzrError):
647
 
 
 
799
    
648
800
    _fmt = "Revision is not compatible with %(repo_format)s"
649
801
 
650
802
    def __init__(self, repo_format):
661
813
        """Construct a new AlreadyVersionedError.
662
814
 
663
815
        :param path: This is the path which is versioned,
664
 
            which should be in a user friendly form.
 
816
        which should be in a user friendly form.
665
817
        :param context_info: If given, this is information about the context,
666
 
            which could explain why this is expected to not be versioned.
 
818
        which could explain why this is expected to not be versioned.
667
819
        """
668
820
        BzrError.__init__(self)
669
821
        self.path = path
682
834
        """Construct a new NotVersionedError.
683
835
 
684
836
        :param path: This is the path which is not versioned,
685
 
            which should be in a user friendly form.
 
837
        which should be in a user friendly form.
686
838
        :param context_info: If given, this is information about the context,
687
 
            which could explain why this is expected to be versioned.
 
839
        which could explain why this is expected to be versioned.
688
840
        """
689
841
        BzrError.__init__(self)
690
842
        self.path = path
700
852
    _fmt = "Path(s) are not versioned: %(paths_as_string)s"
701
853
 
702
854
    def __init__(self, paths):
703
 
        from breezy.osutils import quotefn
 
855
        from bzrlib.osutils import quotefn
704
856
        BzrError.__init__(self)
705
857
        self.paths = paths
706
858
        self.paths_as_string = ' '.join([quotefn(p) for p in paths])
715
867
 
716
868
    def __init__(self, paths, extra=None):
717
869
        # circular import
718
 
        from breezy.osutils import quotefn
 
870
        from bzrlib.osutils import quotefn
719
871
        BzrError.__init__(self)
720
872
        self.paths = paths
721
873
        self.paths_as_string = ' '.join([quotefn(p) for p in paths])
758
910
    # original exception is available as e.original_error
759
911
    #
760
912
    # New code should prefer to raise specific subclasses
761
 
    def __init__(self, msg):
762
 
        self.msg = msg
 
913
    def __init__(self, message):
 
914
        # Python 2.5 uses a slot for StandardError.message,
 
915
        # so use a different variable name.  We now work around this in
 
916
        # BzrError.__str__, but this member name is kept for compatability.
 
917
        self.msg = message
763
918
 
764
919
 
765
920
class LockActive(LockError):
848
1003
 
849
1004
class LockContention(LockError):
850
1005
 
851
 
    _fmt = 'Could not acquire lock "%(lock)s": %(msg)s'
 
1006
    _fmt = 'Could not acquire lock "%(lock)s"'
 
1007
    # TODO: show full url for lock, combining the transport and relative
 
1008
    # bits?
852
1009
 
853
1010
    internal_error = False
854
1011
 
855
 
    def __init__(self, lock, msg=''):
 
1012
    def __init__(self, lock):
856
1013
        self.lock = lock
857
 
        self.msg = msg
858
1014
 
859
1015
 
860
1016
class LockBroken(LockError):
881
1037
        self.target = target
882
1038
 
883
1039
 
884
 
class LockCorrupt(LockError):
885
 
 
886
 
    _fmt = ("Lock is apparently held, but corrupted: %(corruption_info)s\n"
887
 
            "Use 'brz break-lock' to clear it")
888
 
 
889
 
    internal_error = False
890
 
 
891
 
    def __init__(self, corruption_info, file_data=None):
892
 
        self.corruption_info = corruption_info
893
 
        self.file_data = file_data
894
 
 
895
 
 
896
1040
class LockNotHeld(LockError):
897
1041
 
898
1042
    _fmt = "Lock not held: %(lock)s"
922
1066
        self.lock_token = lock_token
923
1067
 
924
1068
 
 
1069
class PointlessCommit(BzrError):
 
1070
 
 
1071
    _fmt = "No changes to commit"
 
1072
 
 
1073
 
 
1074
class CannotCommitSelectedFileMerge(BzrError):
 
1075
 
 
1076
    _fmt = 'Selected-file commit of merges is not supported yet:'\
 
1077
        ' files %(files_str)s'
 
1078
 
 
1079
    def __init__(self, files):
 
1080
        files_str = ', '.join(files)
 
1081
        BzrError.__init__(self, files=files, files_str=files_str)
 
1082
 
 
1083
 
 
1084
class BadCommitMessageEncoding(BzrError):
 
1085
 
 
1086
    _fmt = 'The specified commit message contains characters unsupported by '\
 
1087
        'the current encoding.'
 
1088
 
 
1089
 
925
1090
class UpgradeReadonly(BzrError):
926
1091
 
927
1092
    _fmt = "Upgrade URL cannot work with readonly URLs."
936
1101
        self.format = format
937
1102
 
938
1103
 
 
1104
class StrictCommitFailed(Exception):
 
1105
 
 
1106
    _fmt = "Commit refused because there are unknowns in the tree."
 
1107
 
 
1108
 
939
1109
class NoSuchRevision(InternalBzrError):
940
1110
 
941
1111
    _fmt = "%(branch)s has no revision %(revision)s"
960
1130
 
961
1131
class NoSuchRevisionInTree(NoSuchRevision):
962
1132
    """When using Tree.revision_tree, and the revision is not accessible."""
963
 
 
 
1133
    
964
1134
    _fmt = "The revision id {%(revision_id)s} is not present in the tree %(tree)s."
965
1135
 
966
1136
    def __init__(self, tree, revision_id):
971
1141
 
972
1142
class InvalidRevisionSpec(BzrError):
973
1143
 
974
 
    _fmt = ("Requested revision: '%(spec)s' does not exist in branch:"
975
 
            " %(branch_url)s%(extra)s")
 
1144
    _fmt = ("Requested revision: %(spec)r does not exist in branch:"
 
1145
            " %(branch)s%(extra)s")
976
1146
 
977
1147
    def __init__(self, spec, branch, extra=None):
978
1148
        BzrError.__init__(self, branch=branch, spec=spec)
979
 
        self.branch_url = getattr(branch, 'user_url', str(branch))
980
1149
        if extra:
981
1150
            self.extra = '\n' + str(extra)
982
1151
        else:
983
1152
            self.extra = ''
984
1153
 
985
1154
 
 
1155
class HistoryMissing(BzrError):
 
1156
 
 
1157
    _fmt = "%(branch)s is missing %(object_type)s {%(object_id)s}"
 
1158
 
 
1159
 
986
1160
class AppendRevisionsOnlyViolation(BzrError):
987
1161
 
988
1162
    _fmt = ('Operation denied because it would change the main history,'
990
1164
           ' branch "%(location)s".')
991
1165
 
992
1166
    def __init__(self, location):
993
 
       import breezy.urlutils as urlutils
 
1167
       import bzrlib.urlutils as urlutils
994
1168
       location = urlutils.unescape_for_display(location, 'ascii')
995
1169
       BzrError.__init__(self, location=location)
996
1170
 
998
1172
class DivergedBranches(BzrError):
999
1173
 
1000
1174
    _fmt = ("These branches have diverged."
1001
 
            " Use the missing command to see how.\n"
1002
 
            "Use the merge command to reconcile them.")
 
1175
            " Use the merge command to reconcile them.")
1003
1176
 
1004
1177
    def __init__(self, branch1, branch2):
1005
1178
        self.branch1 = branch1
1027
1200
 
1028
1201
 
1029
1202
class NoCommonAncestor(BzrError):
1030
 
 
 
1203
    
1031
1204
    _fmt = "Revisions have no common ancestor: %(revision_a)s %(revision_b)s"
1032
1205
 
1033
1206
    def __init__(self, revision_a, revision_b):
1053
1226
            not_ancestor_id=not_ancestor_id)
1054
1227
 
1055
1228
 
 
1229
class InstallFailed(BzrError):
 
1230
 
 
1231
    def __init__(self, revisions):
 
1232
        revision_str = ", ".join(str(r) for r in revisions)
 
1233
        msg = "Could not install revisions:\n%s" % revision_str
 
1234
        BzrError.__init__(self, msg)
 
1235
        self.revisions = revisions
 
1236
 
 
1237
 
 
1238
class AmbiguousBase(BzrError):
 
1239
 
 
1240
    def __init__(self, bases):
 
1241
        warn("BzrError AmbiguousBase has been deprecated as of bzrlib 0.8.",
 
1242
                DeprecationWarning)
 
1243
        msg = ("The correct base is unclear, because %s are all equally close"
 
1244
                % ", ".join(bases))
 
1245
        BzrError.__init__(self, msg)
 
1246
        self.bases = bases
 
1247
 
 
1248
 
1056
1249
class NoCommits(BranchError):
1057
1250
 
1058
1251
    _fmt = "Branch %(branch)s has no commits."
1074
1267
class BoundBranchOutOfDate(BzrError):
1075
1268
 
1076
1269
    _fmt = ("Bound branch %(branch)s is out of date with master branch"
1077
 
            " %(master)s.%(extra_help)s")
 
1270
            " %(master)s.")
1078
1271
 
1079
1272
    def __init__(self, branch, master):
1080
1273
        BzrError.__init__(self)
1081
1274
        self.branch = branch
1082
1275
        self.master = master
1083
 
        self.extra_help = ''
1084
 
 
1085
 
 
 
1276
 
 
1277
        
1086
1278
class CommitToDoubleBoundBranch(BzrError):
1087
1279
 
1088
1280
    _fmt = ("Cannot commit to branch %(branch)s."
1116
1308
        self.error = error
1117
1309
 
1118
1310
 
 
1311
class WeaveError(BzrError):
 
1312
 
 
1313
    _fmt = "Error in processing weave: %(message)s"
 
1314
 
 
1315
    def __init__(self, message=None):
 
1316
        BzrError.__init__(self)
 
1317
        self.message = message
 
1318
 
 
1319
 
 
1320
class WeaveRevisionAlreadyPresent(WeaveError):
 
1321
 
 
1322
    _fmt = "Revision {%(revision_id)s} already present in %(weave)s"
 
1323
 
 
1324
    def __init__(self, revision_id, weave):
 
1325
 
 
1326
        WeaveError.__init__(self)
 
1327
        self.revision_id = revision_id
 
1328
        self.weave = weave
 
1329
 
 
1330
 
 
1331
class WeaveRevisionNotPresent(WeaveError):
 
1332
 
 
1333
    _fmt = "Revision {%(revision_id)s} not present in %(weave)s"
 
1334
 
 
1335
    def __init__(self, revision_id, weave):
 
1336
        WeaveError.__init__(self)
 
1337
        self.revision_id = revision_id
 
1338
        self.weave = weave
 
1339
 
 
1340
 
 
1341
class WeaveFormatError(WeaveError):
 
1342
 
 
1343
    _fmt = "Weave invariant violated: %(what)s"
 
1344
 
 
1345
    def __init__(self, what):
 
1346
        WeaveError.__init__(self)
 
1347
        self.what = what
 
1348
 
 
1349
 
 
1350
class WeaveParentMismatch(WeaveError):
 
1351
 
 
1352
    _fmt = "Parents are mismatched between two revisions. %(message)s"
 
1353
    
 
1354
 
 
1355
class WeaveInvalidChecksum(WeaveError):
 
1356
 
 
1357
    _fmt = "Text did not match it's checksum: %(message)s"
 
1358
 
 
1359
 
 
1360
class WeaveTextDiffers(WeaveError):
 
1361
 
 
1362
    _fmt = ("Weaves differ on text content. Revision:"
 
1363
            " {%(revision_id)s}, %(weave_a)s, %(weave_b)s")
 
1364
 
 
1365
    def __init__(self, revision_id, weave_a, weave_b):
 
1366
        WeaveError.__init__(self)
 
1367
        self.revision_id = revision_id
 
1368
        self.weave_a = weave_a
 
1369
        self.weave_b = weave_b
 
1370
 
 
1371
 
 
1372
class WeaveTextDiffers(WeaveError):
 
1373
 
 
1374
    _fmt = ("Weaves differ on text content. Revision:"
 
1375
            " {%(revision_id)s}, %(weave_a)s, %(weave_b)s")
 
1376
 
 
1377
    def __init__(self, revision_id, weave_a, weave_b):
 
1378
        WeaveError.__init__(self)
 
1379
        self.revision_id = revision_id
 
1380
        self.weave_a = weave_a
 
1381
        self.weave_b = weave_b
 
1382
 
 
1383
 
1119
1384
class VersionedFileError(BzrError):
1120
 
 
 
1385
    
1121
1386
    _fmt = "Versioned file error"
1122
1387
 
1123
1388
 
1124
1389
class RevisionNotPresent(VersionedFileError):
1125
 
 
 
1390
    
1126
1391
    _fmt = 'Revision {%(revision_id)s} not present in "%(file_id)s".'
1127
1392
 
1128
1393
    def __init__(self, revision_id, file_id):
1132
1397
 
1133
1398
 
1134
1399
class RevisionAlreadyPresent(VersionedFileError):
1135
 
 
 
1400
    
1136
1401
    _fmt = 'Revision {%(revision_id)s} already present in "%(file_id)s".'
1137
1402
 
1138
1403
    def __init__(self, revision_id, file_id):
1143
1408
 
1144
1409
class VersionedFileInvalidChecksum(VersionedFileError):
1145
1410
 
1146
 
    _fmt = "Text did not match its checksum: %(msg)s"
1147
 
 
1148
 
 
1149
 
class RetryWithNewPacks(BzrError):
1150
 
    """Raised when we realize that the packs on disk have changed.
1151
 
 
1152
 
    This is meant as more of a signaling exception, to trap between where a
1153
 
    local error occurred and the code that can actually handle the error and
1154
 
    code that can retry appropriately.
1155
 
    """
1156
 
 
1157
 
    internal_error = True
1158
 
 
1159
 
    _fmt = ("Pack files have changed, reload and retry. context: %(context)s"
1160
 
            " %(orig_error)s")
1161
 
 
1162
 
    def __init__(self, context, reload_occurred, exc_info):
1163
 
        """create a new RetryWithNewPacks error.
1164
 
 
1165
 
        :param reload_occurred: Set to True if we know that the packs have
1166
 
            already been reloaded, and we are failing because of an in-memory
1167
 
            cache miss. If set to True then we will ignore if a reload says
1168
 
            nothing has changed, because we assume it has already reloaded. If
1169
 
            False, then a reload with nothing changed will force an error.
1170
 
        :param exc_info: The original exception traceback, so if there is a
1171
 
            problem we can raise the original error (value from sys.exc_info())
1172
 
        """
1173
 
        BzrError.__init__(self)
1174
 
        self.context = context
1175
 
        self.reload_occurred = reload_occurred
1176
 
        self.exc_info = exc_info
1177
 
        self.orig_error = exc_info[1]
1178
 
        # TODO: The global error handler should probably treat this by
1179
 
        #       raising/printing the original exception with a bit about
1180
 
        #       RetryWithNewPacks also not being caught
1181
 
 
1182
 
 
1183
 
class RetryAutopack(RetryWithNewPacks):
1184
 
    """Raised when we are autopacking and we find a missing file.
1185
 
 
1186
 
    Meant as a signaling exception, to tell the autopack code it should try
1187
 
    again.
1188
 
    """
1189
 
 
1190
 
    internal_error = True
1191
 
 
1192
 
    _fmt = ("Pack files have changed, reload and try autopack again."
1193
 
            " context: %(context)s %(orig_error)s")
 
1411
    _fmt = "Text did not match its checksum: %(message)s"
 
1412
 
 
1413
 
 
1414
class KnitError(InternalBzrError):
 
1415
    
 
1416
    _fmt = "Knit error"
 
1417
 
 
1418
 
 
1419
class KnitCorrupt(KnitError):
 
1420
 
 
1421
    _fmt = "Knit %(filename)s corrupt: %(how)s"
 
1422
 
 
1423
    def __init__(self, filename, how):
 
1424
        KnitError.__init__(self)
 
1425
        self.filename = filename
 
1426
        self.how = how
 
1427
 
 
1428
 
 
1429
class KnitDataStreamIncompatible(KnitError):
 
1430
    # Not raised anymore, as we can convert data streams.  In future we may
 
1431
    # need it again for more exotic cases, so we're keeping it around for now.
 
1432
 
 
1433
    _fmt = "Cannot insert knit data stream of format \"%(stream_format)s\" into knit of format \"%(target_format)s\"."
 
1434
 
 
1435
    def __init__(self, stream_format, target_format):
 
1436
        self.stream_format = stream_format
 
1437
        self.target_format = target_format
 
1438
        
 
1439
 
 
1440
class KnitDataStreamUnknown(KnitError):
 
1441
    # Indicates a data stream we don't know how to handle.
 
1442
 
 
1443
    _fmt = "Cannot parse knit data stream of format \"%(stream_format)s\"."
 
1444
 
 
1445
    def __init__(self, stream_format):
 
1446
        self.stream_format = stream_format
 
1447
        
 
1448
 
 
1449
class KnitHeaderError(KnitError):
 
1450
 
 
1451
    _fmt = 'Knit header error: %(badline)r unexpected for file "%(filename)s".'
 
1452
 
 
1453
    def __init__(self, badline, filename):
 
1454
        KnitError.__init__(self)
 
1455
        self.badline = badline
 
1456
        self.filename = filename
 
1457
 
 
1458
class KnitIndexUnknownMethod(KnitError):
 
1459
    """Raised when we don't understand the storage method.
 
1460
 
 
1461
    Currently only 'fulltext' and 'line-delta' are supported.
 
1462
    """
 
1463
    
 
1464
    _fmt = ("Knit index %(filename)s does not have a known method"
 
1465
            " in options: %(options)r")
 
1466
 
 
1467
    def __init__(self, filename, options):
 
1468
        KnitError.__init__(self)
 
1469
        self.filename = filename
 
1470
        self.options = options
1194
1471
 
1195
1472
 
1196
1473
class NoSuchExportFormat(BzrError):
1197
 
 
 
1474
    
1198
1475
    _fmt = "Export format %(format)r not supported"
1199
1476
 
1200
1477
    def __init__(self, format):
1203
1480
 
1204
1481
 
1205
1482
class TransportError(BzrError):
1206
 
 
 
1483
    
1207
1484
    _fmt = "Transport error: %(msg)s %(orig_error)s"
1208
1485
 
1209
1486
    def __init__(self, msg=None, orig_error=None):
1254
1531
 
1255
1532
class SmartMessageHandlerError(InternalBzrError):
1256
1533
 
1257
 
    _fmt = ("The message handler raised an exception:\n"
1258
 
            "%(traceback_text)s")
 
1534
    _fmt = "The message handler raised an exception: %(exc_value)s."
1259
1535
 
1260
1536
    def __init__(self, exc_info):
1261
 
        import traceback
1262
 
        # GZ 2010-08-10: Cycle with exc_tb/exc_info affects at least one test
1263
 
        self.exc_type, self.exc_value, self.exc_tb = exc_info
1264
 
        self.exc_info = exc_info
1265
 
        traceback_strings = traceback.format_exception(
1266
 
                self.exc_type, self.exc_value, self.exc_tb)
1267
 
        self.traceback_text = ''.join(traceback_strings)
1268
 
 
 
1537
        self.exc_type, self.exc_value, self.tb = exc_info
 
1538
        
1269
1539
 
1270
1540
# A set of semi-meaningful errors which can be thrown
1271
1541
class TransportNotPossible(TransportError):
1297
1567
            self.port = ':%s' % port
1298
1568
 
1299
1569
 
1300
 
# XXX: This is also used for unexpected end of file, which is different at the
1301
 
# TCP level from "connection reset".
1302
1570
class ConnectionReset(TransportError):
1303
1571
 
1304
1572
    _fmt = "Connection closed: %(msg)s %(orig_error)s"
1305
1573
 
1306
1574
 
1307
 
class ConnectionTimeout(ConnectionError):
1308
 
 
1309
 
    _fmt = "Connection Timeout: %(msg)s%(orig_error)s"
1310
 
 
1311
 
 
1312
1575
class InvalidRange(TransportError):
1313
1576
 
1314
1577
    _fmt = "Invalid range access in %(path)s at %(offset)s: %(msg)s"
1321
1584
 
1322
1585
class InvalidHttpResponse(TransportError):
1323
1586
 
1324
 
    _fmt = "Invalid http response for %(path)s: %(msg)s%(orig_error)s"
 
1587
    _fmt = "Invalid http response for %(path)s: %(msg)s"
1325
1588
 
1326
1589
    def __init__(self, path, msg, orig_error=None):
1327
1590
        self.path = path
1328
 
        if orig_error is None:
1329
 
            orig_error = ''
1330
 
        else:
1331
 
            # This is reached for obscure and unusual errors so we want to
1332
 
            # preserve as much info as possible to ease debug.
1333
 
            orig_error = ': %r' % (orig_error,)
1334
1591
        TransportError.__init__(self, msg, orig_error=orig_error)
1335
1592
 
1336
1593
 
1343
1600
        InvalidHttpResponse.__init__(self, path, msg)
1344
1601
 
1345
1602
 
1346
 
class HttpBoundaryMissing(InvalidHttpResponse):
1347
 
    """A multipart response ends with no boundary marker.
1348
 
 
1349
 
    This is a special case caused by buggy proxies, described in
1350
 
    <https://bugs.launchpad.net/bzr/+bug/198646>.
1351
 
    """
1352
 
 
1353
 
    _fmt = "HTTP MIME Boundary missing for %(path)s: %(msg)s"
1354
 
 
1355
 
    def __init__(self, path, msg):
1356
 
        InvalidHttpResponse.__init__(self, path, msg)
1357
 
 
1358
 
 
1359
1603
class InvalidHttpContentType(InvalidHttpResponse):
1360
1604
 
1361
1605
    _fmt = 'Invalid http Content-type "%(ctype)s" for %(path)s: %(msg)s'
1369
1613
 
1370
1614
    _fmt = '%(source)s is%(permanently)s redirected to %(target)s'
1371
1615
 
1372
 
    def __init__(self, source, target, is_permanent=False):
 
1616
    def __init__(self, source, target, is_permanent=False, qual_proto=None):
1373
1617
        self.source = source
1374
1618
        self.target = target
1375
1619
        if is_permanent:
1376
1620
            self.permanently = ' permanently'
1377
1621
        else:
1378
1622
            self.permanently = ''
 
1623
        self._qualified_proto = qual_proto
1379
1624
        TransportError.__init__(self)
1380
1625
 
 
1626
    def _requalify_url(self, url):
 
1627
        """Restore the qualified proto in front of the url"""
 
1628
        # When this exception is raised, source and target are in
 
1629
        # user readable format. But some transports may use a
 
1630
        # different proto (http+urllib:// will present http:// to
 
1631
        # the user. If a qualified proto is specified, the code
 
1632
        # trapping the exception can get the qualified urls to
 
1633
        # properly handle the redirection themself (creating a
 
1634
        # new transport object from the target url for example).
 
1635
        # But checking that the scheme of the original and
 
1636
        # redirected urls are the same can be tricky. (see the
 
1637
        # FIXME in BzrDir.open_from_transport for the unique use
 
1638
        # case so far).
 
1639
        if self._qualified_proto is None:
 
1640
            return url
 
1641
 
 
1642
        # The TODO related to NotBranchError mention that doing
 
1643
        # that kind of manipulation on the urls may not be the
 
1644
        # exception object job. On the other hand, this object is
 
1645
        # the interface between the code and the user so
 
1646
        # presenting the urls in different ways is indeed its
 
1647
        # job...
 
1648
        import urlparse
 
1649
        proto, netloc, path, query, fragment = urlparse.urlsplit(url)
 
1650
        return urlparse.urlunsplit((self._qualified_proto, netloc, path,
 
1651
                                   query, fragment))
 
1652
 
 
1653
    def get_source_url(self):
 
1654
        return self._requalify_url(self.source)
 
1655
 
 
1656
    def get_target_url(self):
 
1657
        return self._requalify_url(self.target)
 
1658
 
1381
1659
 
1382
1660
class TooManyRedirections(TransportError):
1383
1661
 
1389
1667
    _fmt = "Working tree has conflicts."
1390
1668
 
1391
1669
 
1392
 
class DependencyNotPresent(BzrError):
1393
 
 
1394
 
    _fmt = 'Unable to import library "%(library)s": %(error)s'
1395
 
 
1396
 
    def __init__(self, library, error):
1397
 
        BzrError.__init__(self, library=library, error=error)
 
1670
class ParseConfigError(BzrError):
 
1671
 
 
1672
    def __init__(self, errors, filename):
 
1673
        if filename is None:
 
1674
            filename = ""
 
1675
        message = "Error(s) parsing config file %s:\n%s" % \
 
1676
            (filename, ('\n'.join(e.message for e in errors)))
 
1677
        BzrError.__init__(self, message)
 
1678
 
 
1679
 
 
1680
class NoEmailInUsername(BzrError):
 
1681
 
 
1682
    _fmt = "%(username)r does not seem to contain a reasonable email address"
 
1683
 
 
1684
    def __init__(self, username):
 
1685
        BzrError.__init__(self)
 
1686
        self.username = username
 
1687
 
 
1688
 
 
1689
class SigningFailed(BzrError):
 
1690
 
 
1691
    _fmt = 'Failed to gpg sign data with command "%(command_line)s"'
 
1692
 
 
1693
    def __init__(self, command_line):
 
1694
        BzrError.__init__(self, command_line=command_line)
1398
1695
 
1399
1696
 
1400
1697
class WorkingTreeNotRevision(BzrError):
1401
1698
 
1402
 
    _fmt = ("The working tree for %(basedir)s has changed since"
 
1699
    _fmt = ("The working tree for %(basedir)s has changed since" 
1403
1700
            " the last commit, but weave merge requires that it be"
1404
1701
            " unchanged")
1405
1702
 
1518
1815
        self.prefix = prefix
1519
1816
 
1520
1817
 
1521
 
class MalformedTransform(InternalBzrError):
 
1818
class MalformedTransform(BzrError):
1522
1819
 
1523
1820
    _fmt = "Tree transform is malformed %(conflicts)r"
1524
1821
 
1562
1859
    _fmt = "Moving the root directory is not supported at this time"
1563
1860
 
1564
1861
 
1565
 
class TransformRenameFailed(BzrError):
1566
 
 
1567
 
    _fmt = "Failed to rename %(from_path)s to %(to_path)s: %(why)s"
1568
 
 
1569
 
    def __init__(self, from_path, to_path, why, errno):
1570
 
        self.from_path = from_path
1571
 
        self.to_path = to_path
1572
 
        self.why = why
1573
 
        self.errno = errno
1574
 
 
1575
 
 
1576
1862
class BzrMoveFailedError(BzrError):
1577
1863
 
1578
 
    _fmt = ("Could not move %(from_path)s%(operator)s %(to_path)s"
1579
 
        "%(_has_extra)s%(extra)s")
 
1864
    _fmt = "Could not move %(from_path)s%(operator)s %(to_path)s%(extra)s"
1580
1865
 
1581
1866
    def __init__(self, from_path='', to_path='', extra=None):
1582
 
        from breezy.osutils import splitpath
1583
1867
        BzrError.__init__(self)
1584
1868
        if extra:
1585
 
            self.extra, self._has_extra = extra, ': '
 
1869
            self.extra = ': ' + str(extra)
1586
1870
        else:
1587
 
            self.extra = self._has_extra = ''
 
1871
            self.extra = ''
1588
1872
 
1589
1873
        has_from = len(from_path) > 0
1590
1874
        has_to = len(to_path) > 0
1591
1875
        if has_from:
1592
 
            self.from_path = splitpath(from_path)[-1]
 
1876
            self.from_path = osutils.splitpath(from_path)[-1]
1593
1877
        else:
1594
1878
            self.from_path = ''
1595
1879
 
1596
1880
        if has_to:
1597
 
            self.to_path = splitpath(to_path)[-1]
 
1881
            self.to_path = osutils.splitpath(to_path)[-1]
1598
1882
        else:
1599
1883
            self.to_path = ''
1600
1884
 
1611
1895
 
1612
1896
class BzrRenameFailedError(BzrMoveFailedError):
1613
1897
 
1614
 
    _fmt = ("Could not rename %(from_path)s%(operator)s %(to_path)s"
1615
 
        "%(_has_extra)s%(extra)s")
 
1898
    _fmt = "Could not rename %(from_path)s%(operator)s %(to_path)s%(extra)s"
1616
1899
 
1617
1900
    def __init__(self, from_path, to_path, extra=None):
1618
1901
        BzrMoveFailedError.__init__(self, from_path, to_path, extra)
1619
1902
 
 
1903
class BzrRemoveChangedFilesError(BzrError):
 
1904
    """Used when user is trying to remove changed files."""
 
1905
 
 
1906
    _fmt = ("Can't safely remove modified or unknown files:\n"
 
1907
        "%(changes_as_text)s"
 
1908
        "Use --keep to not delete them, or --force to delete them regardless.")
 
1909
 
 
1910
    def __init__(self, tree_delta):
 
1911
        BzrError.__init__(self)
 
1912
        self.changes_as_text = tree_delta.get_changes_as_text()
 
1913
        #self.paths_as_string = '\n'.join(changed_files)
 
1914
        #self.paths_as_string = '\n'.join([quotefn(p) for p in changed_files])
 
1915
 
1620
1916
 
1621
1917
class BzrBadParameterNotString(BzrBadParameter):
1622
1918
 
1625
1921
 
1626
1922
class BzrBadParameterMissing(BzrBadParameter):
1627
1923
 
1628
 
    _fmt = "Parameter %(param)s is required but not present."
 
1924
    _fmt = "Parameter $(param)s is required but not present."
1629
1925
 
1630
1926
 
1631
1927
class BzrBadParameterUnicode(BzrBadParameter):
1639
1935
    _fmt = "Parameter %(param)s contains a newline."
1640
1936
 
1641
1937
 
 
1938
class DependencyNotPresent(BzrError):
 
1939
 
 
1940
    _fmt = 'Unable to import library "%(library)s": %(error)s'
 
1941
 
 
1942
    def __init__(self, library, error):
 
1943
        BzrError.__init__(self, library=library, error=error)
 
1944
 
 
1945
 
1642
1946
class ParamikoNotPresent(DependencyNotPresent):
1643
1947
 
1644
1948
    _fmt = "Unable to import paramiko (required for sftp support): %(error)s"
1654
1958
 
1655
1959
class UninitializableFormat(BzrError):
1656
1960
 
1657
 
    _fmt = "Format %(format)s cannot be initialised by this version of brz."
 
1961
    _fmt = "Format %(format)s cannot be initialised by this version of bzr."
1658
1962
 
1659
1963
    def __init__(self, format):
1660
1964
        BzrError.__init__(self)
1663
1967
 
1664
1968
class BadConversionTarget(BzrError):
1665
1969
 
1666
 
    _fmt = "Cannot convert from format %(from_format)s to format %(format)s." \
1667
 
            "    %(problem)s"
 
1970
    _fmt = "Cannot convert to format %(format)s.  %(problem)s"
1668
1971
 
1669
 
    def __init__(self, problem, format, from_format=None):
 
1972
    def __init__(self, problem, format):
1670
1973
        BzrError.__init__(self)
1671
1974
        self.problem = problem
1672
1975
        self.format = format
1673
 
        self.from_format = from_format or '(unspecified)'
1674
1976
 
1675
1977
 
1676
1978
class NoDiffFound(BzrError):
1703
2005
 
1704
2006
 
1705
2007
class ExistingContent(BzrError):
1706
 
    # Added in breezy 0.92, used by VersionedFile.add_lines.
 
2008
    # Added in bzrlib 0.92, used by VersionedFile.add_lines.
1707
2009
 
1708
2010
    _fmt = "The content being inserted is already present."
1709
2011
 
1713
2015
    _fmt = """This tree contains left-over files from a failed operation.
1714
2016
    Please examine %(limbo_dir)s to see if it contains any files you wish to
1715
2017
    keep, and delete it when you are done."""
1716
 
 
 
2018
    
1717
2019
    def __init__(self, limbo_dir):
1718
2020
       BzrError.__init__(self)
1719
2021
       self.limbo_dir = limbo_dir
1752
2054
 
1753
2055
class OutOfDateTree(BzrError):
1754
2056
 
1755
 
    _fmt = "Working tree is out of date, please run 'brz update'.%(more)s"
 
2057
    _fmt = "Working tree is out of date, please run 'bzr update'."
1756
2058
 
1757
 
    def __init__(self, tree, more=None):
1758
 
        if more is None:
1759
 
            more = ''
1760
 
        else:
1761
 
            more = ' ' + more
 
2059
    def __init__(self, tree):
1762
2060
        BzrError.__init__(self)
1763
2061
        self.tree = tree
1764
 
        self.more = more
1765
2062
 
1766
2063
 
1767
2064
class PublicBranchOutOfDate(BzrError):
1770
2067
        '"%(revstring)s".'
1771
2068
 
1772
2069
    def __init__(self, public_location, revstring):
1773
 
        import breezy.urlutils as urlutils
 
2070
        import bzrlib.urlutils as urlutils
1774
2071
        public_location = urlutils.unescape_for_display(public_location,
1775
2072
                                                        'ascii')
1776
2073
        BzrError.__init__(self, public_location=public_location,
1787
2084
    _fmt = "Format error in conflict listings"
1788
2085
 
1789
2086
 
 
2087
class CorruptDirstate(BzrError):
 
2088
 
 
2089
    _fmt = ("Inconsistency in dirstate file %(dirstate_path)s.\n"
 
2090
            "Error: %(description)s")
 
2091
 
 
2092
    def __init__(self, dirstate_path, description):
 
2093
        BzrError.__init__(self)
 
2094
        self.dirstate_path = dirstate_path
 
2095
        self.description = description
 
2096
 
 
2097
 
1790
2098
class CorruptRepository(BzrError):
1791
2099
 
1792
2100
    _fmt = ("An error has been detected in the repository %(repo_path)s.\n"
1793
 
            "Please run brz reconcile on this repository.")
 
2101
            "Please run bzr reconcile on this repository.")
1794
2102
 
1795
2103
    def __init__(self, repo):
1796
2104
        BzrError.__init__(self)
1797
 
        self.repo_path = repo.user_url
 
2105
        self.repo_path = repo.bzrdir.root_transport.base
1798
2106
 
1799
2107
 
1800
2108
class InconsistentDelta(BzrError):
1810
2118
        self.reason = reason
1811
2119
 
1812
2120
 
1813
 
class InconsistentDeltaDelta(InconsistentDelta):
1814
 
    """Used when we get a delta that is not valid."""
1815
 
 
1816
 
    _fmt = ("An inconsistent delta was supplied: %(delta)r"
1817
 
            "\nreason: %(reason)s")
1818
 
 
1819
 
    def __init__(self, delta, reason):
1820
 
        BzrError.__init__(self)
1821
 
        self.delta = delta
1822
 
        self.reason = reason
1823
 
 
1824
 
 
1825
2121
class UpgradeRequired(BzrError):
1826
2122
 
1827
2123
    _fmt = "To use this feature you must upgrade your branch at %(path)s."
1836
2132
    _fmt = "To use this feature you must upgrade your repository at %(path)s."
1837
2133
 
1838
2134
 
1839
 
class RichRootUpgradeRequired(UpgradeRequired):
1840
 
 
1841
 
    _fmt = ("To use this feature you must upgrade your branch at %(path)s to"
1842
 
           " a format which supports rich roots.")
1843
 
 
1844
 
 
1845
2135
class LocalRequiresBoundBranch(BzrError):
1846
2136
 
1847
2137
    _fmt = "Cannot perform local-only commits on unbound branches."
1848
2138
 
1849
2139
 
 
2140
class MissingProgressBarFinish(BzrError):
 
2141
 
 
2142
    _fmt = "A nested progress bar was not 'finished' correctly."
 
2143
 
 
2144
 
 
2145
class InvalidProgressBarType(BzrError):
 
2146
 
 
2147
    _fmt = ("Environment variable BZR_PROGRESS_BAR='%(bar_type)s"
 
2148
            " is not a supported type Select one of: %(valid_types)s")
 
2149
 
 
2150
    def __init__(self, bar_type, valid_types):
 
2151
        BzrError.__init__(self, bar_type=bar_type, valid_types=valid_types)
 
2152
 
 
2153
 
1850
2154
class UnsupportedOperation(BzrError):
1851
2155
 
1852
2156
    _fmt = ("The method %(mname)s is not supported on"
1858
2162
        self.tname = type(method_self).__name__
1859
2163
 
1860
2164
 
1861
 
class FetchLimitUnsupported(UnsupportedOperation):
1862
 
 
1863
 
    fmt = ("InterBranch %(interbranch)r does not support fetching limits.")
1864
 
 
1865
 
    def __init__(self, interbranch):
1866
 
        BzrError.__init__(self, interbranch=interbranch)
 
2165
class CannotSetRevisionId(UnsupportedOperation):
 
2166
    """Raised when a commit is attempting to set a revision id but cant."""
1867
2167
 
1868
2168
 
1869
2169
class NonAsciiRevisionId(UnsupportedOperation):
1872
2172
    """
1873
2173
 
1874
2174
 
1875
 
class GhostTagsNotSupported(BzrError):
1876
 
 
1877
 
    _fmt = "Ghost tags not supported by format %(format)r."
1878
 
 
1879
 
    def __init__(self, format):
1880
 
        self.format = format
1881
 
 
1882
 
 
1883
2175
class BinaryFile(BzrError):
1884
 
 
 
2176
    
1885
2177
    _fmt = "File is binary but should be text."
1886
2178
 
1887
2179
 
1907
2199
 
1908
2200
 
1909
2201
class NotABundle(BzrError):
1910
 
 
 
2202
    
1911
2203
    _fmt = "Not a bzr revision-bundle: %(text)r"
1912
2204
 
1913
2205
    def __init__(self, text):
1915
2207
        self.text = text
1916
2208
 
1917
2209
 
1918
 
class BadBundle(BzrError):
1919
 
 
 
2210
class BadBundle(BzrError): 
 
2211
    
1920
2212
    _fmt = "Bad bzr revision-bundle: %(text)r"
1921
2213
 
1922
2214
    def __init__(self, text):
1924
2216
        self.text = text
1925
2217
 
1926
2218
 
1927
 
class MalformedHeader(BadBundle):
1928
 
 
 
2219
class MalformedHeader(BadBundle): 
 
2220
    
1929
2221
    _fmt = "Malformed bzr revision-bundle header: %(text)r"
1930
2222
 
1931
2223
 
1932
 
class MalformedPatches(BadBundle):
1933
 
 
 
2224
class MalformedPatches(BadBundle): 
 
2225
    
1934
2226
    _fmt = "Malformed patches in bzr revision-bundle: %(text)r"
1935
2227
 
1936
2228
 
1937
 
class MalformedFooter(BadBundle):
1938
 
 
 
2229
class MalformedFooter(BadBundle): 
 
2230
    
1939
2231
    _fmt = "Malformed footer in bzr revision-bundle: %(text)r"
1940
2232
 
1941
2233
 
1942
2234
class UnsupportedEOLMarker(BadBundle):
1943
 
 
1944
 
    _fmt = "End of line marker was not \\n in bzr revision-bundle"
 
2235
    
 
2236
    _fmt = "End of line marker was not \\n in bzr revision-bundle"    
1945
2237
 
1946
2238
    def __init__(self):
1947
 
        # XXX: BadBundle's constructor assumes there's explanatory text,
 
2239
        # XXX: BadBundle's constructor assumes there's explanatory text, 
1948
2240
        # but for this there is not
1949
2241
        BzrError.__init__(self)
1950
2242
 
1951
2243
 
1952
2244
class IncompatibleBundleFormat(BzrError):
1953
 
 
 
2245
    
1954
2246
    _fmt = "Bundle format %(bundle_format)s is incompatible with %(other)s"
1955
2247
 
1956
2248
    def __init__(self, bundle_format, other):
1960
2252
 
1961
2253
 
1962
2254
class BadInventoryFormat(BzrError):
1963
 
 
 
2255
    
1964
2256
    _fmt = "Root class for inventory serialization errors"
1965
2257
 
1966
2258
 
1985
2277
        self.transport = transport
1986
2278
 
1987
2279
 
 
2280
class NoSmartServer(NotBranchError):
 
2281
 
 
2282
    _fmt = "No smart server available at %(url)s"
 
2283
 
 
2284
    @symbol_versioning.deprecated_method(symbol_versioning.one_four)
 
2285
    def __init__(self, url):
 
2286
        self.url = url
 
2287
 
 
2288
 
1988
2289
class UnknownSSH(BzrError):
1989
2290
 
1990
 
    _fmt = "Unrecognised value for BRZ_SSH environment variable: %(vendor)s"
 
2291
    _fmt = "Unrecognised value for BZR_SSH environment variable: %(vendor)s"
1991
2292
 
1992
2293
    def __init__(self, vendor):
1993
2294
        BzrError.__init__(self)
1997
2298
class SSHVendorNotFound(BzrError):
1998
2299
 
1999
2300
    _fmt = ("Don't know how to handle SSH connections."
2000
 
            " Please set BRZ_SSH environment variable.")
 
2301
            " Please set BZR_SSH environment variable.")
2001
2302
 
2002
2303
 
2003
2304
class GhostRevisionsHaveNoRevno(BzrError):
2010
2311
        self.revision_id = revision_id
2011
2312
        self.ghost_revision_id = ghost_revision_id
2012
2313
 
2013
 
 
 
2314
        
2014
2315
class GhostRevisionUnusableHere(BzrError):
2015
2316
 
2016
2317
    _fmt = "Ghost revision {%(revision_id)s} cannot be used here."
2108
2409
 
2109
2410
 
2110
2411
class UnsupportedInventoryKind(BzrError):
2111
 
 
 
2412
    
2112
2413
    _fmt = """Unsupported entry kind %(kind)s"""
2113
2414
 
2114
2415
    def __init__(self, kind):
2126
2427
 
2127
2428
 
2128
2429
class SubsumeTargetNeedsUpgrade(BzrError):
2129
 
 
 
2430
    
2130
2431
    _fmt = """Subsume target %(other_tree)s needs to be upgraded."""
2131
2432
 
2132
2433
    def __init__(self, other_tree):
2133
2434
        self.other_tree = other_tree
2134
2435
 
2135
2436
 
 
2437
class BadReferenceTarget(InternalBzrError):
 
2438
 
 
2439
    _fmt = "Can't add reference to %(other_tree)s into %(tree)s." \
 
2440
           "%(reason)s"
 
2441
 
 
2442
    def __init__(self, tree, other_tree, reason):
 
2443
        self.tree = tree
 
2444
        self.other_tree = other_tree
 
2445
        self.reason = reason
 
2446
 
 
2447
 
2136
2448
class NoSuchTag(BzrError):
2137
2449
 
2138
2450
    _fmt = "No such tag: %(tag_name)s"
2144
2456
class TagsNotSupported(BzrError):
2145
2457
 
2146
2458
    _fmt = ("Tags not supported by %(branch)s;"
2147
 
            " you may be able to use brz upgrade.")
 
2459
            " you may be able to use bzr upgrade.")
2148
2460
 
2149
2461
    def __init__(self, branch):
2150
2462
        self.branch = branch
2151
2463
 
2152
 
 
 
2464
        
2153
2465
class TagAlreadyExists(BzrError):
2154
2466
 
2155
2467
    _fmt = "Tag %(tag_name)s already exists."
2158
2470
        self.tag_name = tag_name
2159
2471
 
2160
2472
 
 
2473
class MalformedBugIdentifier(BzrError):
 
2474
 
 
2475
    _fmt = "Did not understand bug identifier %(bug_id)s: %(reason)s"
 
2476
 
 
2477
    def __init__(self, bug_id, reason):
 
2478
        self.bug_id = bug_id
 
2479
        self.reason = reason
 
2480
 
 
2481
 
 
2482
class InvalidBugTrackerURL(BzrError):
 
2483
 
 
2484
    _fmt = ("The URL for bug tracker \"%(abbreviation)s\" doesn't "
 
2485
            "contain {id}: %(url)s")
 
2486
 
 
2487
    def __init__(self, abbreviation, url):
 
2488
        self.abbreviation = abbreviation
 
2489
        self.url = url
 
2490
 
 
2491
 
 
2492
class UnknownBugTrackerAbbreviation(BzrError):
 
2493
 
 
2494
    _fmt = ("Cannot find registered bug tracker called %(abbreviation)s "
 
2495
            "on %(branch)s")
 
2496
 
 
2497
    def __init__(self, abbreviation, branch):
 
2498
        self.abbreviation = abbreviation
 
2499
        self.branch = branch
 
2500
 
 
2501
 
2161
2502
class UnexpectedSmartServerResponse(BzrError):
2162
2503
 
2163
2504
    _fmt = "Could not understand response from smart server: %(response_tuple)r"
2167
2508
 
2168
2509
 
2169
2510
class ErrorFromSmartServer(BzrError):
2170
 
    """An error was received from a smart server.
2171
 
 
2172
 
    :seealso: UnknownErrorFromSmartServer
2173
 
    """
2174
2511
 
2175
2512
    _fmt = "Error received from smart server: %(error_tuple)r"
2176
2513
 
2185
2522
        self.error_args = error_tuple[1:]
2186
2523
 
2187
2524
 
2188
 
class UnknownErrorFromSmartServer(BzrError):
2189
 
    """An ErrorFromSmartServer could not be translated into a typical breezy
2190
 
    error.
2191
 
 
2192
 
    This is distinct from ErrorFromSmartServer so that it is possible to
2193
 
    distinguish between the following two cases:
2194
 
 
2195
 
    - ErrorFromSmartServer was uncaught.  This is logic error in the client
2196
 
      and so should provoke a traceback to the user.
2197
 
    - ErrorFromSmartServer was caught but its error_tuple could not be
2198
 
      translated.  This is probably because the server sent us garbage, and
2199
 
      should not provoke a traceback.
2200
 
    """
2201
 
 
2202
 
    _fmt = "Server sent an unexpected error: %(error_tuple)r"
2203
 
 
2204
 
    internal_error = False
2205
 
 
2206
 
    def __init__(self, error_from_smart_server):
2207
 
        """Constructor.
2208
 
 
2209
 
        :param error_from_smart_server: An ErrorFromSmartServer instance.
2210
 
        """
2211
 
        self.error_from_smart_server = error_from_smart_server
2212
 
        self.error_tuple = error_from_smart_server.error_tuple
2213
 
 
2214
 
 
2215
2525
class ContainerError(BzrError):
2216
2526
    """Base class of container errors."""
2217
2527
 
2219
2529
class UnknownContainerFormatError(ContainerError):
2220
2530
 
2221
2531
    _fmt = "Unrecognised container format: %(container_format)r"
2222
 
 
 
2532
    
2223
2533
    def __init__(self, container_format):
2224
2534
        self.container_format = container_format
2225
2535
 
2258
2568
    _fmt = "Container has multiple records with the same name: %(name)s"
2259
2569
 
2260
2570
    def __init__(self, name):
2261
 
        self.name = name.decode("utf-8")
 
2571
        self.name = name
 
2572
 
 
2573
 
 
2574
class NoDestinationAddress(InternalBzrError):
 
2575
 
 
2576
    _fmt = "Message does not have a destination address."
2262
2577
 
2263
2578
 
2264
2579
class RepositoryDataStreamError(BzrError):
2269
2584
        self.reason = reason
2270
2585
 
2271
2586
 
 
2587
class SMTPError(BzrError):
 
2588
 
 
2589
    _fmt = "SMTP error: %(error)s"
 
2590
 
 
2591
    def __init__(self, error):
 
2592
        self.error = error
 
2593
 
 
2594
 
 
2595
class NoMessageSupplied(BzrError):
 
2596
 
 
2597
    _fmt = "No message supplied."
 
2598
 
 
2599
 
 
2600
class NoMailAddressSpecified(BzrError):
 
2601
 
 
2602
    _fmt = "No mail-to address specified."
 
2603
 
 
2604
 
 
2605
class UnknownMailClient(BzrError):
 
2606
 
 
2607
    _fmt = "Unknown mail client: %(mail_client)s"
 
2608
 
 
2609
    def __init__(self, mail_client):
 
2610
        BzrError.__init__(self, mail_client=mail_client)
 
2611
 
 
2612
 
 
2613
class MailClientNotFound(BzrError):
 
2614
 
 
2615
    _fmt = "Unable to find mail client with the following names:"\
 
2616
        " %(mail_command_list_string)s"
 
2617
 
 
2618
    def __init__(self, mail_command_list):
 
2619
        mail_command_list_string = ', '.join(mail_command_list)
 
2620
        BzrError.__init__(self, mail_command_list=mail_command_list,
 
2621
                          mail_command_list_string=mail_command_list_string)
 
2622
 
 
2623
class SMTPConnectionRefused(SMTPError):
 
2624
 
 
2625
    _fmt = "SMTP connection to %(host)s refused"
 
2626
 
 
2627
    def __init__(self, error, host):
 
2628
        self.error = error
 
2629
        self.host = host
 
2630
 
 
2631
 
 
2632
class DefaultSMTPConnectionRefused(SMTPConnectionRefused):
 
2633
 
 
2634
    _fmt = "Please specify smtp_server.  No server at default %(host)s."
 
2635
 
 
2636
 
 
2637
class BzrDirError(BzrError):
 
2638
 
 
2639
    def __init__(self, bzrdir):
 
2640
        import bzrlib.urlutils as urlutils
 
2641
        display_url = urlutils.unescape_for_display(bzrdir.root_transport.base,
 
2642
                                                    'ascii')
 
2643
        BzrError.__init__(self, bzrdir=bzrdir, display_url=display_url)
 
2644
 
 
2645
 
 
2646
class UnsyncedBranches(BzrDirError):
 
2647
 
 
2648
    _fmt = ("'%(display_url)s' is not in sync with %(target_url)s.  See"
 
2649
            " bzr help sync-for-reconfigure.")
 
2650
 
 
2651
    def __init__(self, bzrdir, target_branch):
 
2652
        BzrDirError.__init__(self, bzrdir)
 
2653
        import bzrlib.urlutils as urlutils
 
2654
        self.target_url = urlutils.unescape_for_display(target_branch.base,
 
2655
                                                        'ascii')
 
2656
 
 
2657
 
 
2658
class AlreadyBranch(BzrDirError):
 
2659
 
 
2660
    _fmt = "'%(display_url)s' is already a branch."
 
2661
 
 
2662
 
 
2663
class AlreadyTree(BzrDirError):
 
2664
 
 
2665
    _fmt = "'%(display_url)s' is already a tree."
 
2666
 
 
2667
 
 
2668
class AlreadyCheckout(BzrDirError):
 
2669
 
 
2670
    _fmt = "'%(display_url)s' is already a checkout."
 
2671
 
 
2672
 
 
2673
class AlreadyLightweightCheckout(BzrDirError):
 
2674
 
 
2675
    _fmt = "'%(display_url)s' is already a lightweight checkout."
 
2676
 
 
2677
 
 
2678
class AlreadyUsingShared(BzrDirError):
 
2679
 
 
2680
    _fmt = "'%(display_url)s' is already using a shared repository."
 
2681
 
 
2682
 
 
2683
class AlreadyStandalone(BzrDirError):
 
2684
 
 
2685
    _fmt = "'%(display_url)s' is already standalone."
 
2686
 
 
2687
 
 
2688
class ReconfigurationNotSupported(BzrDirError):
 
2689
 
 
2690
    _fmt = "Requested reconfiguration of '%(display_url)s' is not supported."
 
2691
 
 
2692
 
 
2693
class NoBindLocation(BzrDirError):
 
2694
 
 
2695
    _fmt = "No location could be found to bind to at %(display_url)s."
 
2696
 
 
2697
 
2272
2698
class UncommittedChanges(BzrError):
2273
2699
 
2274
 
    _fmt = ('Working tree "%(display_url)s" has uncommitted changes'
2275
 
            ' (See brz status).%(more)s')
2276
 
 
2277
 
    def __init__(self, tree, more=None):
2278
 
        if more is None:
2279
 
            more = ''
2280
 
        else:
2281
 
            more = ' ' + more
2282
 
        import breezy.urlutils as urlutils
2283
 
        user_url = getattr(tree, "user_url", None)
2284
 
        if user_url is None:
2285
 
            display_url = str(tree)
2286
 
        else:
2287
 
            display_url = urlutils.unescape_for_display(user_url, 'ascii')
2288
 
        BzrError.__init__(self, tree=tree, display_url=display_url, more=more)
2289
 
 
2290
 
 
2291
 
class StoringUncommittedNotSupported(BzrError):
2292
 
 
2293
 
    _fmt = ('Branch "%(display_url)s" does not support storing uncommitted'
2294
 
            ' changes.')
2295
 
 
2296
 
    def __init__(self, branch):
2297
 
        import breezy.urlutils as urlutils
2298
 
        user_url = getattr(branch, "user_url", None)
2299
 
        if user_url is None:
2300
 
            display_url = str(branch)
2301
 
        else:
2302
 
            display_url = urlutils.unescape_for_display(user_url, 'ascii')
2303
 
        BzrError.__init__(self, branch=branch, display_url=display_url)
2304
 
 
2305
 
 
2306
 
class ShelvedChanges(UncommittedChanges):
2307
 
 
2308
 
    _fmt = ('Working tree "%(display_url)s" has shelved changes'
2309
 
            ' (See brz shelve --list).%(more)s')
 
2700
    _fmt = 'Working tree "%(display_url)s" has uncommitted changes.'
 
2701
 
 
2702
    def __init__(self, tree):
 
2703
        import bzrlib.urlutils as urlutils
 
2704
        display_url = urlutils.unescape_for_display(
 
2705
            tree.bzrdir.root_transport.base, 'ascii')
 
2706
        BzrError.__init__(self, tree=tree, display_url=display_url)
 
2707
 
 
2708
 
 
2709
class MissingTemplateVariable(BzrError):
 
2710
 
 
2711
    _fmt = 'Variable {%(name)s} is not available.'
 
2712
 
 
2713
    def __init__(self, name):
 
2714
        self.name = name
 
2715
 
 
2716
 
 
2717
class NoTemplate(BzrError):
 
2718
 
 
2719
    _fmt = 'No template specified.'
2310
2720
 
2311
2721
 
2312
2722
class UnableCreateSymlink(BzrError):
2324
2734
        self.path_str = path_str
2325
2735
 
2326
2736
 
 
2737
class UnsupportedTimezoneFormat(BzrError):
 
2738
 
 
2739
    _fmt = ('Unsupported timezone format "%(timezone)s", '
 
2740
            'options are "utc", "original", "local".')
 
2741
 
 
2742
    def __init__(self, timezone):
 
2743
        self.timezone = timezone
 
2744
 
 
2745
 
 
2746
class CommandAvailableInPlugin(StandardError):
 
2747
    
 
2748
    internal_error = False
 
2749
 
 
2750
    def __init__(self, cmd_name, plugin_metadata, provider):
 
2751
        
 
2752
        self.plugin_metadata = plugin_metadata
 
2753
        self.cmd_name = cmd_name
 
2754
        self.provider = provider
 
2755
 
 
2756
    def __str__(self):
 
2757
 
 
2758
        _fmt = ('"%s" is not a standard bzr command. \n' 
 
2759
                'However, the following official plugin provides this command: %s\n'
 
2760
                'You can install it by going to: %s'
 
2761
                % (self.cmd_name, self.plugin_metadata['name'], 
 
2762
                    self.plugin_metadata['url']))
 
2763
 
 
2764
        return _fmt
 
2765
 
 
2766
 
 
2767
class NoPluginAvailable(BzrError):
 
2768
    pass    
 
2769
 
 
2770
 
 
2771
class NotATerminal(BzrError):
 
2772
 
 
2773
    _fmt = 'Unable to ask for a password without real terminal.'
 
2774
 
 
2775
 
2327
2776
class UnableEncodePath(BzrError):
2328
2777
 
2329
2778
    _fmt = ('Unable to encode %(kind)s path %(path)r in '
2330
2779
            'user encoding %(user_encoding)s')
2331
2780
 
2332
2781
    def __init__(self, path, kind):
2333
 
        from breezy.osutils import get_user_encoding
2334
2782
        self.path = path
2335
2783
        self.kind = kind
2336
 
        self.user_encoding = get_user_encoding()
 
2784
        self.user_encoding = osutils.get_user_encoding()
2337
2785
 
2338
2786
 
2339
2787
class NoSuchAlias(BzrError):
2344
2792
        BzrError.__init__(self, alias_name=alias_name)
2345
2793
 
2346
2794
 
 
2795
class DirectoryLookupFailure(BzrError):
 
2796
    """Base type for lookup errors."""
 
2797
 
 
2798
    pass
 
2799
 
 
2800
 
 
2801
class InvalidLocationAlias(DirectoryLookupFailure):
 
2802
 
 
2803
    _fmt = '"%(alias_name)s" is not a valid location alias.'
 
2804
 
 
2805
    def __init__(self, alias_name):
 
2806
        DirectoryLookupFailure.__init__(self, alias_name=alias_name)
 
2807
 
 
2808
 
 
2809
class UnsetLocationAlias(DirectoryLookupFailure):
 
2810
 
 
2811
    _fmt = 'No %(alias_name)s location assigned.'
 
2812
 
 
2813
    def __init__(self, alias_name):
 
2814
        DirectoryLookupFailure.__init__(self, alias_name=alias_name[1:])
 
2815
 
 
2816
 
2347
2817
class CannotBindAddress(BzrError):
2348
2818
 
2349
2819
    _fmt = 'Cannot bind address "%(host)s:%(port)i": %(orig_error)s.'
2350
2820
 
2351
2821
    def __init__(self, host, port, orig_error):
2352
 
        # nb: in python2.4 socket.error doesn't have a useful repr
2353
2822
        BzrError.__init__(self, host=host, port=port,
2354
 
            orig_error=repr(orig_error.args))
 
2823
            orig_error=orig_error[1])
 
2824
 
 
2825
 
 
2826
class UnknownRules(BzrError):
 
2827
 
 
2828
    _fmt = ('Unknown rules detected: %(unknowns_str)s.')
 
2829
 
 
2830
    def __init__(self, unknowns):
 
2831
        BzrError.__init__(self, unknowns_str=", ".join(unknowns))
 
2832
 
 
2833
 
 
2834
class HookFailed(BzrError):
 
2835
    """Raised when a pre_change_branch_tip hook function fails anything other
 
2836
    than TipChangeRejected.
 
2837
    """
 
2838
 
 
2839
    _fmt = ("Hook '%(hook_name)s' during %(hook_stage)s failed:\n"
 
2840
            "%(traceback_text)s%(exc_value)s")
 
2841
 
 
2842
    def __init__(self, hook_stage, hook_name, exc_info):
 
2843
        import traceback
 
2844
        self.hook_stage = hook_stage
 
2845
        self.hook_name = hook_name
 
2846
        self.exc_info = exc_info
 
2847
        self.exc_type = exc_info[0]
 
2848
        self.exc_value = exc_info[1]
 
2849
        self.exc_tb = exc_info[2]
 
2850
        self.traceback_text = ''.join(traceback.format_tb(self.exc_tb))
2355
2851
 
2356
2852
 
2357
2853
class TipChangeRejected(BzrError):
2358
2854
    """A pre_change_branch_tip hook function may raise this to cleanly and
2359
2855
    explicitly abort a change to a branch tip.
2360
2856
    """
2361
 
 
 
2857
    
2362
2858
    _fmt = u"Tip change rejected: %(msg)s"
2363
2859
 
2364
2860
    def __init__(self, msg):
2365
2861
        self.msg = msg
2366
2862
 
2367
 
 
2368
 
class JailBreak(BzrError):
2369
 
 
2370
 
    _fmt = "An attempt to access a url outside the server jail was made: '%(url)s'."
2371
 
 
2372
 
    def __init__(self, url):
2373
 
        BzrError.__init__(self, url=url)
2374
 
 
2375
 
 
2376
 
class UserAbort(BzrError):
2377
 
 
2378
 
    _fmt = 'The user aborted the operation.'
2379
 
 
2380
 
 
2381
 
class UnresumableWriteGroup(BzrError):
2382
 
 
2383
 
    _fmt = ("Repository %(repository)s cannot resume write group "
2384
 
            "%(write_groups)r: %(reason)s")
2385
 
 
2386
 
    internal_error = True
2387
 
 
2388
 
    def __init__(self, repository, write_groups, reason):
2389
 
        self.repository = repository
2390
 
        self.write_groups = write_groups
2391
 
        self.reason = reason
2392
 
 
2393
 
 
2394
 
class UnsuspendableWriteGroup(BzrError):
2395
 
 
2396
 
    _fmt = ("Repository %(repository)s cannot suspend a write group.")
2397
 
 
2398
 
    internal_error = True
2399
 
 
2400
 
    def __init__(self, repository):
2401
 
        self.repository = repository
2402
 
 
2403
 
 
2404
 
class LossyPushToSameVCS(BzrError):
2405
 
 
2406
 
    _fmt = ("Lossy push not possible between %(source_branch)r and "
2407
 
            "%(target_branch)r that are in the same VCS.")
2408
 
 
2409
 
    internal_error = True
2410
 
 
2411
 
    def __init__(self, source_branch, target_branch):
2412
 
        self.source_branch = source_branch
2413
 
        self.target_branch = target_branch
2414
 
 
2415
 
 
2416
 
class NoRoundtrippingSupport(BzrError):
2417
 
 
2418
 
    _fmt = ("Roundtripping is not supported between %(source_branch)r and "
2419
 
            "%(target_branch)r.")
2420
 
 
2421
 
    internal_error = True
2422
 
 
2423
 
    def __init__(self, source_branch, target_branch):
2424
 
        self.source_branch = source_branch
2425
 
        self.target_branch = target_branch
2426
 
 
2427
 
 
2428
 
class NoColocatedBranchSupport(BzrError):
2429
 
 
2430
 
    _fmt = ("%(controldir)r does not support co-located branches.")
2431
 
 
2432
 
    def __init__(self, controldir):
2433
 
        self.controldir = controldir
2434
 
 
2435
 
 
2436
 
class RecursiveBind(BzrError):
2437
 
 
2438
 
    _fmt = ('Branch "%(branch_url)s" appears to be bound to itself. '
2439
 
        'Please use `brz unbind` to fix.')
2440
 
 
2441
 
    def __init__(self, branch_url):
2442
 
        self.branch_url = branch_url
2443
 
 
2444
 
 
2445
 
class UnsupportedKindChange(BzrError):
2446
 
 
2447
 
    _fmt = ("Kind change from %(from_kind)s to %(to_kind)s for "
2448
 
            "%(path)s not supported by format %(format)r")
2449
 
 
2450
 
    def __init__(self, path, from_kind, to_kind, format):
2451
 
        self.path = path
2452
 
        self.from_kind = from_kind
2453
 
        self.to_kind = to_kind
2454
 
        self.format = format
2455
 
 
2456
 
 
2457
 
class ChangesAlreadyStored(BzrCommandError):
2458
 
 
2459
 
    _fmt = ('Cannot store uncommitted changes because this branch already'
2460
 
            ' stores uncommitted changes.')