/brz/remove-bazaar

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

« back to all changes in this revision

Viewing changes to bzrlib/errors.py

  • Committer: Vincent Ladeuil
  • Date: 2007-11-24 14:20:59 UTC
  • mto: (3928.1.1 bzr.integration)
  • mto: This revision was merged to the branch mainline in revision 3929.
  • Revision ID: v.ladeuil+lp@free.fr-20071124142059-2114qtsgfdv8g9p1
Ssl files needed for the test https server.

* bzrlib/tests/ssl_certs/create_ssls.py: 
Script to create the ssl keys and certificates.

* bzrlib/tests/ssl_certs/server.crt: 
Server certificate signed by the certificate authority.

* bzrlib/tests/ssl_certs/server.csr: 
Server certificate signing request.

* bzrlib/tests/ssl_certs/server_without_pass.key: 
Server key usable without password.

* bzrlib/tests/ssl_certs/server_with_pass.key: 
Server key.

* bzrlib/tests/ssl_certs/ca.key: 
Certificate authority private key.

* bzrlib/tests/ssl_certs/ca.crt: 
Certificate authority certificate.

* bzrlib/tests/ssl_certs/__init__.py: 
Provide access to ssl files (keys and certificates). 

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 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
import sys
 
21
 
 
22
 
 
23
from bzrlib import (
 
24
    osutils,
 
25
    symbol_versioning,
 
26
    )
 
27
from bzrlib.patches import (
 
28
    MalformedHunkHeader,
 
29
    MalformedLine,
 
30
    MalformedPatchHeader,
 
31
    PatchConflict,
 
32
    PatchSyntax,
 
33
    )
 
34
 
25
35
 
26
36
# 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
 
37
# python exceptions?   A list of values with no names seems less useful 
28
38
# to me.
29
39
 
30
 
# TODO: Perhaps convert the exception to a string at the moment it's
 
40
# TODO: Perhaps convert the exception to a string at the moment it's 
31
41
# constructed to make sure it will succeed.  But that says nothing about
32
42
# exceptions that are never raised.
33
43
 
36
46
# 'unprintable'.
37
47
 
38
48
 
39
 
# return codes from the brz program
 
49
# return codes from the bzr program
40
50
EXIT_OK = 0
41
51
EXIT_ERROR = 3
42
52
EXIT_INTERNAL_ERROR = 4
43
53
 
44
54
 
45
 
class BzrError(Exception):
 
55
class BzrError(StandardError):
46
56
    """
47
 
    Base class for errors raised by breezy.
 
57
    Base class for errors raised by bzrlib.
48
58
 
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.)
 
59
    :cvar internal_error: if True this was probably caused by a bzr bug and
 
60
    should be displayed with a traceback; if False (or absent) this was
 
61
    probably a user or environment error and they don't need the gory details.
 
62
    (That can be overridden by -Derror on the command line.)
53
63
 
54
64
    :cvar _fmt: Format string to display the error; this is expanded
55
 
        by the instance's dict.
 
65
    by the instance's dict.
56
66
    """
57
 
 
 
67
    
58
68
    internal_error = False
59
69
 
60
70
    def __init__(self, msg=None, **kwds):
65
75
        arguments can be given.  The first is for generic "user" errors which
66
76
        are not intended to be caught and so do not need a specific subclass.
67
77
        The second case is for use with subclasses that provide a _fmt format
68
 
        string to print the arguments.
 
78
        string to print the arguments.  
69
79
 
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
 
80
        Keyword arguments are taken as parameters to the error, which can 
 
81
        be inserted into the format string template.  It's recommended 
 
82
        that subclasses override the __init__ method to require specific 
73
83
        parameters.
74
84
 
75
85
        :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'.
 
86
        not subject to expansion.
78
87
        """
79
 
        Exception.__init__(self)
 
88
        StandardError.__init__(self)
80
89
        if msg is not None:
81
90
            # I was going to deprecate this, but it actually turns out to be
82
91
            # quite handy - mbp 20061103.
86
95
            for key, value in kwds.items():
87
96
                setattr(self, key, value)
88
97
 
89
 
    def _format(self):
 
98
    def __str__(self):
90
99
        s = getattr(self, '_preformatted_string', None)
91
100
        if s is not None:
92
 
            # contains a preformatted message
93
 
            return s
94
 
        err = None
 
101
            # contains a preformatted message; must be cast to plain str
 
102
            return str(s)
95
103
        try:
96
104
            fmt = self._get_format_string()
97
105
            if fmt:
99
107
                s = fmt % d
100
108
                # __str__() should always return a 'str' object
101
109
                # never a 'unicode' object.
 
110
                if isinstance(s, unicode):
 
111
                    return s.encode('utf8')
102
112
                return s
103
 
        except Exception as e:
104
 
            err = e
105
 
        return 'Unprintable exception %s: dict=%r, fmt=%r, error=%r' \
 
113
        except (AttributeError, TypeError, NameError, ValueError, KeyError), e:
 
114
            return 'Unprintable exception %s: dict=%r, fmt=%r, error=%r' \
 
115
                % (self.__class__.__name__,
 
116
                   self.__dict__,
 
117
                   getattr(self, '_fmt', None),
 
118
                   e)
 
119
 
 
120
    def _get_format_string(self):
 
121
        """Return format string for this exception or None"""
 
122
        fmt = getattr(self, '_fmt', None)
 
123
        if fmt is not None:
 
124
            return fmt
 
125
        fmt = getattr(self, '__doc__', None)
 
126
        if fmt is not None:
 
127
            symbol_versioning.warn("%s uses its docstring as a format, "
 
128
                    "it should use _fmt instead" % self.__class__.__name__,
 
129
                    DeprecationWarning)
 
130
            return fmt
 
131
        return 'Unprintable exception %s: dict=%r, fmt=%r' \
106
132
            % (self.__class__.__name__,
107
133
               self.__dict__,
108
134
               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)
 
135
               )
136
136
 
137
137
 
138
138
class InternalBzrError(BzrError):
146
146
    internal_error = True
147
147
 
148
148
 
149
 
class BranchError(BzrError):
150
 
    """Base class for concrete 'errors about a branch'."""
151
 
 
152
 
    def __init__(self, branch):
153
 
        BzrError.__init__(self, branch=branch)
 
149
class BzrNewError(BzrError):
 
150
    """Deprecated error base class."""
 
151
    # base classes should override the docstring with their human-
 
152
    # readable explanation
 
153
 
 
154
    def __init__(self, *args, **kwds):
 
155
        # XXX: Use the underlying BzrError to always generate the args
 
156
        # attribute if it doesn't exist.  We can't use super here, because
 
157
        # exceptions are old-style classes in python2.4 (but new in 2.5).
 
158
        # --bmc, 20060426
 
159
        symbol_versioning.warn('BzrNewError was deprecated in bzr 0.13; '
 
160
             'please convert %s to use BzrError instead'
 
161
             % self.__class__.__name__,
 
162
             DeprecationWarning,
 
163
             stacklevel=2)
 
164
        BzrError.__init__(self, *args)
 
165
        for key, value in kwds.items():
 
166
            setattr(self, key, value)
 
167
 
 
168
    def __str__(self):
 
169
        try:
 
170
            # __str__() should always return a 'str' object
 
171
            # never a 'unicode' object.
 
172
            s = self.__doc__ % self.__dict__
 
173
            if isinstance(s, unicode):
 
174
                return s.encode('utf8')
 
175
            return s
 
176
        except (TypeError, NameError, ValueError, KeyError), e:
 
177
            return 'Unprintable exception %s(%r): %r' \
 
178
                % (self.__class__.__name__,
 
179
                   self.__dict__, e)
 
180
 
 
181
 
 
182
class AlreadyBuilding(BzrError):
 
183
 
 
184
    _fmt = "The tree builder is already building a tree."
154
185
 
155
186
 
156
187
class BzrCheckError(InternalBzrError):
162
193
        self.msg = msg
163
194
 
164
195
 
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
class DisabledMethod(InternalBzrError):
 
197
 
 
198
    _fmt = "The smart server method '%(class_name)s' is disabled."
 
199
 
 
200
    def __init__(self, class_name):
 
201
        BzrError.__init__(self)
 
202
        self.class_name = class_name
 
203
 
 
204
 
 
205
class IncompatibleAPI(BzrError):
 
206
 
 
207
    _fmt = 'The API for "%(api)s" is not compatible with "%(wanted)s". '\
 
208
        'It supports versions "%(minimum)s" to "%(current)s".'
 
209
 
 
210
    def __init__(self, api, wanted, minimum, current):
171
211
        self.api = api
172
212
        self.wanted = wanted
 
213
        self.minimum = minimum
173
214
        self.current = current
174
215
 
175
216
 
183
224
 
184
225
 
185
226
class InvalidEntryName(InternalBzrError):
186
 
 
 
227
    
187
228
    _fmt = "Invalid entry name: %(name)s"
188
229
 
189
230
    def __init__(self, name):
192
233
 
193
234
 
194
235
class InvalidRevisionNumber(BzrError):
195
 
 
 
236
    
196
237
    _fmt = "Invalid revision number %(revno)s"
197
238
 
198
239
    def __init__(self, revno):
210
251
        self.revision_id = revision_id
211
252
        self.branch = branch
212
253
 
213
 
 
214
254
class ReservedId(BzrError):
215
255
 
216
256
    _fmt = "Reserved revision-id {%(revision_id)s}"
222
262
class RootMissing(InternalBzrError):
223
263
 
224
264
    _fmt = ("The root entry of a tree must be the first entry supplied to "
225
 
        "the commit builder.")
226
 
 
227
 
 
228
 
class NoPublicBranch(BzrError):
229
 
 
230
 
    _fmt = 'There is no public branch set for "%(branch_url)s".'
231
 
 
232
 
    def __init__(self, branch):
233
 
        from . import urlutils
234
 
        public_location = urlutils.unescape_for_display(branch.base, 'ascii')
235
 
        BzrError.__init__(self, branch_url=public_location)
 
265
        "record_entry_contents.")
 
266
 
 
267
 
 
268
class NoHelpTopic(BzrError):
 
269
 
 
270
    _fmt = ("No help could be found for '%(topic)s'. "
 
271
        "Please use 'bzr help topics' to obtain a list of topics.")
 
272
 
 
273
    def __init__(self, topic):
 
274
        self.topic = topic
236
275
 
237
276
 
238
277
class NoSuchId(BzrError):
239
278
 
240
279
    _fmt = 'The file id "%(file_id)s" is not present in the tree %(tree)s.'
241
 
 
 
280
    
242
281
    def __init__(self, tree, file_id):
243
282
        BzrError.__init__(self)
244
283
        self.file_id = file_id
245
284
        self.tree = tree
246
285
 
247
286
 
248
 
class NotStacked(BranchError):
249
 
 
250
 
    _fmt = "The branch '%(branch)s' is not stacked."
 
287
class NoSuchIdInRepository(NoSuchId):
 
288
 
 
289
    _fmt = ('The file id "%(file_id)s" is not present in the repository'
 
290
            ' %(repository)r')
 
291
 
 
292
    def __init__(self, repository, file_id):
 
293
        BzrError.__init__(self, repository=repository, file_id=file_id)
251
294
 
252
295
 
253
296
class InventoryModified(InternalBzrError):
262
305
class NoWorkingTree(BzrError):
263
306
 
264
307
    _fmt = 'No WorkingTree exists for "%(base)s".'
265
 
 
 
308
    
266
309
    def __init__(self, base):
267
310
        BzrError.__init__(self)
268
311
        self.base = base
269
312
 
270
313
 
 
314
class NotBuilding(BzrError):
 
315
 
 
316
    _fmt = "Not currently building a tree."
 
317
 
 
318
 
271
319
class NotLocalUrl(BzrError):
272
320
 
273
321
    _fmt = "%(url)s is not a local path."
294
342
    # are not intended to be caught anyway.  UI code need not subclass
295
343
    # BzrCommandError, and non-UI code should not throw a subclass of
296
344
    # BzrCommandError.  ADHB 20051211
 
345
    def __init__(self, msg):
 
346
        # Object.__str__() must return a real string
 
347
        # returning a Unicode string is a python error.
 
348
        if isinstance(msg, unicode):
 
349
            self.msg = msg.encode('utf8')
 
350
        else:
 
351
            self.msg = msg
 
352
 
 
353
    def __str__(self):
 
354
        return self.msg
297
355
 
298
356
 
299
357
class NotWriteLocked(BzrError):
304
362
        self.not_locked = not_locked
305
363
 
306
364
 
 
365
class BzrOptionError(BzrCommandError):
 
366
 
 
367
    _fmt = "Error in command line options"
 
368
 
 
369
 
 
370
class BadIndexFormatSignature(BzrError):
 
371
 
 
372
    _fmt = "%(value)s is not an index of type %(_type)s."
 
373
 
 
374
    def __init__(self, value, _type):
 
375
        BzrError.__init__(self)
 
376
        self.value = value
 
377
        self._type = _type
 
378
 
 
379
 
 
380
class BadIndexData(BzrError):
 
381
 
 
382
    _fmt = "Error in data for index %(value)s."
 
383
 
 
384
    def __init__(self, value):
 
385
        BzrError.__init__(self)
 
386
        self.value = value
 
387
 
 
388
 
 
389
class BadIndexDuplicateKey(BzrError):
 
390
 
 
391
    _fmt = "The key '%(key)s' is already in index '%(index)s'."
 
392
 
 
393
    def __init__(self, key, index):
 
394
        BzrError.__init__(self)
 
395
        self.key = key
 
396
        self.index = index
 
397
 
 
398
 
 
399
class BadIndexKey(BzrError):
 
400
 
 
401
    _fmt = "The key '%(key)s' is not a valid key."
 
402
 
 
403
    def __init__(self, key):
 
404
        BzrError.__init__(self)
 
405
        self.key = key
 
406
 
 
407
 
 
408
class BadIndexOptions(BzrError):
 
409
 
 
410
    _fmt = "Could not parse options for index %(value)s."
 
411
 
 
412
    def __init__(self, value):
 
413
        BzrError.__init__(self)
 
414
        self.value = value
 
415
 
 
416
 
 
417
class BadIndexValue(BzrError):
 
418
 
 
419
    _fmt = "The value '%(value)s' is not a valid value."
 
420
 
 
421
    def __init__(self, value):
 
422
        BzrError.__init__(self)
 
423
        self.value = value
 
424
 
 
425
 
 
426
class BadOptionValue(BzrError):
 
427
 
 
428
    _fmt = """Bad value "%(value)s" for option "%(name)s"."""
 
429
 
 
430
    def __init__(self, name, value):
 
431
        BzrError.__init__(self, name=name, value=value)
 
432
 
 
433
    
307
434
class StrictCommitFailed(BzrError):
308
435
 
309
436
    _fmt = "Commit refused because there are unknown files in the tree"
312
439
# XXX: Should be unified with TransportError; they seem to represent the
313
440
# same thing
314
441
# 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
 
442
# - this is finer than a TransportError - and more useful as such. It 
316
443
# differentiates between 'transport has failed' and 'operation on a transport
317
444
# has failed.'
318
445
class PathError(BzrError):
319
 
 
 
446
    
320
447
    _fmt = "Generic path error: %(path)r%(extra)s)"
321
448
 
322
449
    def __init__(self, path, extra=None):
342
469
    """Used when renaming and both source and dest exist."""
343
470
 
344
471
    _fmt = ("Could not rename %(source)s => %(dest)s because both files exist."
345
 
            " (Use --after to tell brz about a rename that has already"
 
472
            " (Use --after to tell bzr about a rename that has already"
346
473
            " happened)%(extra)s")
347
474
 
348
475
    def __init__(self, source, dest, extra=None):
370
497
    _fmt = 'Directory not empty: "%(path)s"%(extra)s'
371
498
 
372
499
 
373
 
class HardLinkNotSupported(PathError):
374
 
 
375
 
    _fmt = 'Hard-linking "%(path)s" is not supported'
376
 
 
377
 
 
378
500
class ReadingCompleted(InternalBzrError):
379
 
 
 
501
    
380
502
    _fmt = ("The MediumRequest '%(request)s' has already had finish_reading "
381
503
            "called upon it - the request has been completed and no more "
382
504
            "data may be read.")
395
517
    _fmt = 'Permission denied: "%(path)s"%(extra)s'
396
518
 
397
519
 
398
 
class UnavailableRepresentation(InternalBzrError):
399
 
 
400
 
    _fmt = ("The encoding '%(wanted)s' is not available for key %(key)s which "
401
 
        "is encoded as '%(native)s'.")
402
 
 
403
 
    def __init__(self, key, wanted, native):
404
 
        InternalBzrError.__init__(self)
405
 
        self.wanted = wanted
406
 
        self.native = native
407
 
        self.key = key
 
520
class InvalidURL(PathError):
 
521
 
 
522
    _fmt = 'Invalid url supplied to transport: "%(path)s"%(extra)s'
 
523
 
 
524
 
 
525
class InvalidURLJoin(PathError):
 
526
 
 
527
    _fmt = 'Invalid URL join request: "%(args)s"%(extra)s'
 
528
 
 
529
    def __init__(self, msg, base, args):
 
530
        PathError.__init__(self, base, msg)
 
531
        self.args = [base] + list(args)
 
532
 
 
533
 
 
534
class UnknownHook(BzrError):
 
535
 
 
536
    _fmt = "The %(type)s hook '%(hook)s' is unknown in this version of bzrlib."
 
537
 
 
538
    def __init__(self, hook_type, hook_name):
 
539
        BzrError.__init__(self)
 
540
        self.type = hook_type
 
541
        self.hook = hook_name
408
542
 
409
543
 
410
544
class UnsupportedProtocol(PathError):
411
545
 
412
546
    _fmt = 'Unsupported protocol for url "%(path)s"%(extra)s'
413
547
 
414
 
    def __init__(self, url, extra=""):
 
548
    def __init__(self, url, extra):
415
549
        PathError.__init__(self, url, extra=extra)
416
550
 
417
551
 
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):
423
 
        BzrError.__init__(self)
424
 
        self.branch_url = branch_url
425
 
        self.target_url = target_url
426
 
 
427
 
 
428
 
class UnstackableRepositoryFormat(BzrError):
429
 
 
430
 
    _fmt = ("The repository '%(url)s'(%(format)s) is not a stackable format. "
431
 
        "You will need to upgrade the repository to permit branch stacking.")
432
 
 
433
 
    def __init__(self, format, url):
434
 
        BzrError.__init__(self)
435
 
        self.format = format
436
 
        self.url = url
437
 
 
438
 
 
439
552
class ReadError(PathError):
440
 
 
 
553
    
441
554
    _fmt = """Error reading from %(path)r."""
442
555
 
443
556
 
459
572
 
460
573
    _fmt = 'Path "%(path)s" is not a child of path "%(base)s"%(extra)s'
461
574
 
462
 
    internal_error = False
 
575
    internal_error = True
463
576
 
464
577
    def __init__(self, path, base, extra=None):
465
578
        BzrError.__init__(self)
478
591
 
479
592
# TODO: This is given a URL; we try to unescape it but doing that from inside
480
593
# the exception object is a bit undesirable.
481
 
# TODO: Probably this behavior of should be a common superclass
 
594
# TODO: Probably this behavior of should be a common superclass 
482
595
class NotBranchError(PathError):
483
596
 
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 ''
 
597
    _fmt = 'Not a branch: "%(path)s".'
 
598
 
 
599
    def __init__(self, path):
 
600
       import bzrlib.urlutils as urlutils
 
601
       self.path = urlutils.unescape_for_display(path, 'ascii')
522
602
 
523
603
 
524
604
class NoSubmitBranch(PathError):
526
606
    _fmt = 'No submit branch available for branch "%(path)s"'
527
607
 
528
608
    def __init__(self, branch):
529
 
       from . import urlutils
 
609
       import bzrlib.urlutils as urlutils
530
610
       self.path = urlutils.unescape_for_display(branch.base, 'ascii')
531
611
 
532
612
 
533
 
class AlreadyControlDirError(PathError):
534
 
 
535
 
    _fmt = 'A control directory already exists: "%(path)s".'
536
 
 
537
 
 
538
613
class AlreadyBranchError(PathError):
539
614
 
540
615
    _fmt = 'Already a branch: "%(path)s".'
541
616
 
542
617
 
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
618
class BranchExistsWithoutWorkingTree(PathError):
558
619
 
559
620
    _fmt = 'Directory contains a branch, but no working tree \
560
 
(use brz checkout if you wish to build a working tree): "%(path)s"'
 
621
(use bzr checkout if you wish to build a working tree): "%(path)s"'
561
622
 
562
623
 
563
624
class AtomicFileAlreadyClosed(PathError):
583
644
class NoRepositoryPresent(BzrError):
584
645
 
585
646
    _fmt = 'No repository present: "%(path)s"'
586
 
    def __init__(self, controldir):
587
 
        BzrError.__init__(self)
588
 
        self.path = controldir.transport.clone('..').base
 
647
    def __init__(self, bzrdir):
 
648
        BzrError.__init__(self)
 
649
        self.path = bzrdir.transport.clone('..').base
 
650
 
 
651
 
 
652
class FileInWrongBranch(BzrError):
 
653
 
 
654
    _fmt = 'File "%(path)s" in not in branch %(branch_base)s.'
 
655
 
 
656
    def __init__(self, branch, path):
 
657
        BzrError.__init__(self)
 
658
        self.branch = branch
 
659
        self.branch_base = branch.base
 
660
        self.path = path
589
661
 
590
662
 
591
663
class UnsupportedFormatError(BzrError):
592
664
 
593
 
    _fmt = "Unsupported branch format: %(format)s\nPlease run 'brz upgrade'"
 
665
    _fmt = "Unsupported branch format: %(format)s\nPlease run 'bzr upgrade'"
594
666
 
595
667
 
596
668
class UnknownFormatError(BzrError):
597
 
 
598
 
    _fmt = "Unknown %(kind)s format: %(format)r"
599
 
 
600
 
    def __init__(self, format, kind='branch'):
601
 
        self.kind = kind
602
 
        self.format = format
 
669
    
 
670
    _fmt = "Unknown branch format: %(format)r"
603
671
 
604
672
 
605
673
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
 
674
    
 
675
    _fmt = "Format %(format)s is not compatible with .bzr version %(bzrdir)s."
 
676
 
 
677
    def __init__(self, format, bzrdir_format):
 
678
        BzrError.__init__(self)
 
679
        self.format = format
 
680
        self.bzrdir = bzrdir_format
625
681
 
626
682
 
627
683
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
 
 
635
 
    _fmt = "%(target)s\n" \
636
 
            "is not compatible with\n" \
637
 
            "%(source)s\n" \
638
 
            "%(details)s"
639
 
 
640
 
    def __init__(self, source, target, details=None):
641
 
        if details is None:
642
 
            details = "(no details)"
643
 
        BzrError.__init__(self, target=target, source=source, details=details)
 
684
 
 
685
    _fmt = "Repository %(target)s is not compatible with repository"\
 
686
        " %(source)s"
 
687
 
 
688
    def __init__(self, source, target):
 
689
        BzrError.__init__(self, target=target, source=source)
644
690
 
645
691
 
646
692
class IncompatibleRevision(BzrError):
647
 
 
 
693
    
648
694
    _fmt = "Revision is not compatible with %(repo_format)s"
649
695
 
650
696
    def __init__(self, repo_format):
661
707
        """Construct a new AlreadyVersionedError.
662
708
 
663
709
        :param path: This is the path which is versioned,
664
 
            which should be in a user friendly form.
 
710
        which should be in a user friendly form.
665
711
        :param context_info: If given, this is information about the context,
666
 
            which could explain why this is expected to not be versioned.
 
712
        which could explain why this is expected to not be versioned.
667
713
        """
668
714
        BzrError.__init__(self)
669
715
        self.path = path
682
728
        """Construct a new NotVersionedError.
683
729
 
684
730
        :param path: This is the path which is not versioned,
685
 
            which should be in a user friendly form.
 
731
        which should be in a user friendly form.
686
732
        :param context_info: If given, this is information about the context,
687
 
            which could explain why this is expected to be versioned.
 
733
        which could explain why this is expected to be versioned.
688
734
        """
689
735
        BzrError.__init__(self)
690
736
        self.path = path
700
746
    _fmt = "Path(s) are not versioned: %(paths_as_string)s"
701
747
 
702
748
    def __init__(self, paths):
703
 
        from breezy.osutils import quotefn
 
749
        from bzrlib.osutils import quotefn
704
750
        BzrError.__init__(self)
705
751
        self.paths = paths
706
752
        self.paths_as_string = ' '.join([quotefn(p) for p in paths])
715
761
 
716
762
    def __init__(self, paths, extra=None):
717
763
        # circular import
718
 
        from breezy.osutils import quotefn
 
764
        from bzrlib.osutils import quotefn
719
765
        BzrError.__init__(self)
720
766
        self.paths = paths
721
767
        self.paths_as_string = ' '.join([quotefn(p) for p in paths])
733
779
        BzrError.__init__(self, filename=filename, kind=kind)
734
780
 
735
781
 
736
 
class BadFilenameEncoding(BzrError):
737
 
 
738
 
    _fmt = ('Filename %(filename)r is not valid in your current filesystem'
739
 
            ' encoding %(fs_encoding)s')
740
 
 
741
 
    def __init__(self, filename, fs_encoding):
742
 
        BzrError.__init__(self)
743
 
        self.filename = filename
744
 
        self.fs_encoding = fs_encoding
745
 
 
746
 
 
747
782
class ForbiddenControlFileError(BzrError):
748
783
 
749
784
    _fmt = 'Cannot operate on "%(filename)s" because it is a control file'
758
793
    # original exception is available as e.original_error
759
794
    #
760
795
    # New code should prefer to raise specific subclasses
761
 
    def __init__(self, msg):
762
 
        self.msg = msg
 
796
    def __init__(self, message):
 
797
        # Python 2.5 uses a slot for StandardError.message,
 
798
        # so use a different variable name.  We now work around this in
 
799
        # BzrError.__str__, but this member name is kept for compatability.
 
800
        self.msg = message
763
801
 
764
802
 
765
803
class LockActive(LockError):
799
837
        self.obj = obj
800
838
 
801
839
 
 
840
class ReadOnlyLockError(LockError):
 
841
 
 
842
    _fmt = "Cannot acquire write lock on %(fname)s. %(msg)s"
 
843
 
 
844
    @symbol_versioning.deprecated_method(symbol_versioning.zero_ninetytwo)
 
845
    def __init__(self, fname, msg):
 
846
        LockError.__init__(self, '')
 
847
        self.fname = fname
 
848
        self.msg = msg
 
849
 
 
850
 
802
851
class LockFailed(LockError):
803
852
 
804
853
    internal_error = False
848
897
 
849
898
class LockContention(LockError):
850
899
 
851
 
    _fmt = 'Could not acquire lock "%(lock)s": %(msg)s'
 
900
    _fmt = 'Could not acquire lock "%(lock)s"'
 
901
    # TODO: show full url for lock, combining the transport and relative
 
902
    # bits?
852
903
 
853
904
    internal_error = False
854
905
 
855
 
    def __init__(self, lock, msg=''):
 
906
    def __init__(self, lock):
856
907
        self.lock = lock
857
 
        self.msg = msg
858
908
 
859
909
 
860
910
class LockBroken(LockError):
881
931
        self.target = target
882
932
 
883
933
 
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
934
class LockNotHeld(LockError):
897
935
 
898
936
    _fmt = "Lock not held: %(lock)s"
922
960
        self.lock_token = lock_token
923
961
 
924
962
 
 
963
class PointlessCommit(BzrError):
 
964
 
 
965
    _fmt = "No changes to commit"
 
966
 
 
967
 
 
968
class CannotCommitSelectedFileMerge(BzrError):
 
969
 
 
970
    _fmt = 'Selected-file commit of merges is not supported yet:'\
 
971
        ' files %(files_str)s'
 
972
 
 
973
    def __init__(self, files):
 
974
        files_str = ', '.join(files)
 
975
        BzrError.__init__(self, files=files, files_str=files_str)
 
976
 
 
977
 
 
978
class BadCommitMessageEncoding(BzrError):
 
979
 
 
980
    _fmt = 'The specified commit message contains characters unsupported by '\
 
981
        'the current encoding.'
 
982
 
 
983
 
925
984
class UpgradeReadonly(BzrError):
926
985
 
927
986
    _fmt = "Upgrade URL cannot work with readonly URLs."
936
995
        self.format = format
937
996
 
938
997
 
 
998
class StrictCommitFailed(Exception):
 
999
 
 
1000
    _fmt = "Commit refused because there are unknowns in the tree."
 
1001
 
 
1002
 
939
1003
class NoSuchRevision(InternalBzrError):
940
1004
 
941
1005
    _fmt = "%(branch)s has no revision %(revision)s"
945
1009
        BzrError.__init__(self, branch=branch, revision=revision)
946
1010
 
947
1011
 
 
1012
# zero_ninetyone: this exception is no longer raised and should be removed
 
1013
class NotLeftParentDescendant(InternalBzrError):
 
1014
 
 
1015
    _fmt = ("Revision %(old_revision)s is not the left parent of"
 
1016
            " %(new_revision)s, but branch %(branch_location)s expects this")
 
1017
 
 
1018
    def __init__(self, branch, old_revision, new_revision):
 
1019
        BzrError.__init__(self, branch_location=branch.base,
 
1020
                          old_revision=old_revision,
 
1021
                          new_revision=new_revision)
 
1022
 
 
1023
 
948
1024
class RangeInChangeOption(BzrError):
949
1025
 
950
1026
    _fmt = "Option --change does not accept revision ranges"
960
1036
 
961
1037
class NoSuchRevisionInTree(NoSuchRevision):
962
1038
    """When using Tree.revision_tree, and the revision is not accessible."""
963
 
 
 
1039
    
964
1040
    _fmt = "The revision id {%(revision_id)s} is not present in the tree %(tree)s."
965
1041
 
966
1042
    def __init__(self, tree, revision_id):
971
1047
 
972
1048
class InvalidRevisionSpec(BzrError):
973
1049
 
974
 
    _fmt = ("Requested revision: '%(spec)s' does not exist in branch:"
975
 
            " %(branch_url)s%(extra)s")
 
1050
    _fmt = ("Requested revision: %(spec)r does not exist in branch:"
 
1051
            " %(branch)s%(extra)s")
976
1052
 
977
1053
    def __init__(self, spec, branch, extra=None):
978
1054
        BzrError.__init__(self, branch=branch, spec=spec)
979
 
        self.branch_url = getattr(branch, 'user_url', str(branch))
980
1055
        if extra:
981
1056
            self.extra = '\n' + str(extra)
982
1057
        else:
983
1058
            self.extra = ''
984
1059
 
985
1060
 
 
1061
class HistoryMissing(BzrError):
 
1062
 
 
1063
    _fmt = "%(branch)s is missing %(object_type)s {%(object_id)s}"
 
1064
 
 
1065
 
986
1066
class AppendRevisionsOnlyViolation(BzrError):
987
1067
 
988
1068
    _fmt = ('Operation denied because it would change the main history,'
990
1070
           ' branch "%(location)s".')
991
1071
 
992
1072
    def __init__(self, location):
993
 
       import breezy.urlutils as urlutils
 
1073
       import bzrlib.urlutils as urlutils
994
1074
       location = urlutils.unescape_for_display(location, 'ascii')
995
1075
       BzrError.__init__(self, location=location)
996
1076
 
998
1078
class DivergedBranches(BzrError):
999
1079
 
1000
1080
    _fmt = ("These branches have diverged."
1001
 
            " Use the missing command to see how.\n"
1002
 
            "Use the merge command to reconcile them.")
 
1081
            " Use the merge command to reconcile them.")
1003
1082
 
1004
1083
    def __init__(self, branch1, branch2):
1005
1084
        self.branch1 = branch1
1020
1099
            " no merge base revision was specified.")
1021
1100
 
1022
1101
 
1023
 
class CannotReverseCherrypick(BzrError):
1024
 
 
1025
 
    _fmt = ('Selected merge cannot perform reverse cherrypicks.  Try merge3'
1026
 
            ' or diff3.')
1027
 
 
1028
 
 
1029
1102
class NoCommonAncestor(BzrError):
1030
 
 
 
1103
    
1031
1104
    _fmt = "Revisions have no common ancestor: %(revision_a)s %(revision_b)s"
1032
1105
 
1033
1106
    def __init__(self, revision_a, revision_b):
1053
1126
            not_ancestor_id=not_ancestor_id)
1054
1127
 
1055
1128
 
1056
 
class NoCommits(BranchError):
 
1129
class InstallFailed(BzrError):
 
1130
 
 
1131
    def __init__(self, revisions):
 
1132
        revision_str = ", ".join(str(r) for r in revisions)
 
1133
        msg = "Could not install revisions:\n%s" % revision_str
 
1134
        BzrError.__init__(self, msg)
 
1135
        self.revisions = revisions
 
1136
 
 
1137
 
 
1138
class AmbiguousBase(BzrError):
 
1139
 
 
1140
    def __init__(self, bases):
 
1141
        warn("BzrError AmbiguousBase has been deprecated as of bzrlib 0.8.",
 
1142
                DeprecationWarning)
 
1143
        msg = ("The correct base is unclear, because %s are all equally close"
 
1144
                % ", ".join(bases))
 
1145
        BzrError.__init__(self, msg)
 
1146
        self.bases = bases
 
1147
 
 
1148
 
 
1149
class NoCommits(BzrError):
1057
1150
 
1058
1151
    _fmt = "Branch %(branch)s has no commits."
1059
1152
 
 
1153
    def __init__(self, branch):
 
1154
        BzrError.__init__(self, branch=branch)
 
1155
 
1060
1156
 
1061
1157
class UnlistableStore(BzrError):
1062
1158
 
1074
1170
class BoundBranchOutOfDate(BzrError):
1075
1171
 
1076
1172
    _fmt = ("Bound branch %(branch)s is out of date with master branch"
1077
 
            " %(master)s.%(extra_help)s")
 
1173
            " %(master)s.")
1078
1174
 
1079
1175
    def __init__(self, branch, master):
1080
1176
        BzrError.__init__(self)
1081
1177
        self.branch = branch
1082
1178
        self.master = master
1083
 
        self.extra_help = ''
1084
 
 
1085
 
 
 
1179
 
 
1180
        
1086
1181
class CommitToDoubleBoundBranch(BzrError):
1087
1182
 
1088
1183
    _fmt = ("Cannot commit to branch %(branch)s."
1116
1211
        self.error = error
1117
1212
 
1118
1213
 
 
1214
class WeaveError(BzrError):
 
1215
 
 
1216
    _fmt = "Error in processing weave: %(msg)s"
 
1217
 
 
1218
    def __init__(self, msg=None):
 
1219
        BzrError.__init__(self)
 
1220
        self.msg = msg
 
1221
 
 
1222
 
 
1223
class WeaveRevisionAlreadyPresent(WeaveError):
 
1224
 
 
1225
    _fmt = "Revision {%(revision_id)s} already present in %(weave)s"
 
1226
 
 
1227
    def __init__(self, revision_id, weave):
 
1228
 
 
1229
        WeaveError.__init__(self)
 
1230
        self.revision_id = revision_id
 
1231
        self.weave = weave
 
1232
 
 
1233
 
 
1234
class WeaveRevisionNotPresent(WeaveError):
 
1235
 
 
1236
    _fmt = "Revision {%(revision_id)s} not present in %(weave)s"
 
1237
 
 
1238
    def __init__(self, revision_id, weave):
 
1239
        WeaveError.__init__(self)
 
1240
        self.revision_id = revision_id
 
1241
        self.weave = weave
 
1242
 
 
1243
 
 
1244
class WeaveFormatError(WeaveError):
 
1245
 
 
1246
    _fmt = "Weave invariant violated: %(what)s"
 
1247
 
 
1248
    def __init__(self, what):
 
1249
        WeaveError.__init__(self)
 
1250
        self.what = what
 
1251
 
 
1252
 
 
1253
class WeaveParentMismatch(WeaveError):
 
1254
 
 
1255
    _fmt = "Parents are mismatched between two revisions. %(message)s"
 
1256
    
 
1257
 
 
1258
class WeaveInvalidChecksum(WeaveError):
 
1259
 
 
1260
    _fmt = "Text did not match it's checksum: %(message)s"
 
1261
 
 
1262
 
 
1263
class WeaveTextDiffers(WeaveError):
 
1264
 
 
1265
    _fmt = ("Weaves differ on text content. Revision:"
 
1266
            " {%(revision_id)s}, %(weave_a)s, %(weave_b)s")
 
1267
 
 
1268
    def __init__(self, revision_id, weave_a, weave_b):
 
1269
        WeaveError.__init__(self)
 
1270
        self.revision_id = revision_id
 
1271
        self.weave_a = weave_a
 
1272
        self.weave_b = weave_b
 
1273
 
 
1274
 
 
1275
class WeaveTextDiffers(WeaveError):
 
1276
 
 
1277
    _fmt = ("Weaves differ on text content. Revision:"
 
1278
            " {%(revision_id)s}, %(weave_a)s, %(weave_b)s")
 
1279
 
 
1280
    def __init__(self, revision_id, weave_a, weave_b):
 
1281
        WeaveError.__init__(self)
 
1282
        self.revision_id = revision_id
 
1283
        self.weave_a = weave_a
 
1284
        self.weave_b = weave_b
 
1285
 
 
1286
 
1119
1287
class VersionedFileError(BzrError):
1120
 
 
 
1288
    
1121
1289
    _fmt = "Versioned file error"
1122
1290
 
1123
1291
 
1124
1292
class RevisionNotPresent(VersionedFileError):
1125
 
 
 
1293
    
1126
1294
    _fmt = 'Revision {%(revision_id)s} not present in "%(file_id)s".'
1127
1295
 
1128
1296
    def __init__(self, revision_id, file_id):
1132
1300
 
1133
1301
 
1134
1302
class RevisionAlreadyPresent(VersionedFileError):
1135
 
 
 
1303
    
1136
1304
    _fmt = 'Revision {%(revision_id)s} already present in "%(file_id)s".'
1137
1305
 
1138
1306
    def __init__(self, revision_id, file_id):
1143
1311
 
1144
1312
class VersionedFileInvalidChecksum(VersionedFileError):
1145
1313
 
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")
 
1314
    _fmt = "Text did not match its checksum: %(message)s"
 
1315
 
 
1316
 
 
1317
class KnitError(InternalBzrError):
 
1318
    
 
1319
    _fmt = "Knit error"
 
1320
 
 
1321
 
 
1322
class KnitCorrupt(KnitError):
 
1323
 
 
1324
    _fmt = "Knit %(filename)s corrupt: %(how)s"
 
1325
 
 
1326
    def __init__(self, filename, how):
 
1327
        KnitError.__init__(self)
 
1328
        self.filename = filename
 
1329
        self.how = how
 
1330
 
 
1331
 
 
1332
class KnitDataStreamIncompatible(KnitError):
 
1333
 
 
1334
    _fmt = "Cannot insert knit data stream of format \"%(stream_format)s\" into knit of format \"%(target_format)s\"."
 
1335
 
 
1336
    def __init__(self, stream_format, target_format):
 
1337
        self.stream_format = stream_format
 
1338
        self.target_format = target_format
 
1339
        
 
1340
 
 
1341
class KnitHeaderError(KnitError):
 
1342
 
 
1343
    _fmt = 'Knit header error: %(badline)r unexpected for file "%(filename)s".'
 
1344
 
 
1345
    def __init__(self, badline, filename):
 
1346
        KnitError.__init__(self)
 
1347
        self.badline = badline
 
1348
        self.filename = filename
 
1349
 
 
1350
class KnitIndexUnknownMethod(KnitError):
 
1351
    """Raised when we don't understand the storage method.
 
1352
 
 
1353
    Currently only 'fulltext' and 'line-delta' are supported.
 
1354
    """
 
1355
    
 
1356
    _fmt = ("Knit index %(filename)s does not have a known method"
 
1357
            " in options: %(options)r")
 
1358
 
 
1359
    def __init__(self, filename, options):
 
1360
        KnitError.__init__(self)
 
1361
        self.filename = filename
 
1362
        self.options = options
1194
1363
 
1195
1364
 
1196
1365
class NoSuchExportFormat(BzrError):
1197
 
 
 
1366
    
1198
1367
    _fmt = "Export format %(format)r not supported"
1199
1368
 
1200
1369
    def __init__(self, format):
1203
1372
 
1204
1373
 
1205
1374
class TransportError(BzrError):
1206
 
 
 
1375
    
1207
1376
    _fmt = "Transport error: %(msg)s %(orig_error)s"
1208
1377
 
1209
1378
    def __init__(self, msg=None, orig_error=None):
1236
1405
        self.details = details
1237
1406
 
1238
1407
 
1239
 
class UnexpectedProtocolVersionMarker(TransportError):
1240
 
 
1241
 
    _fmt = "Received bad protocol version marker: %(marker)r"
1242
 
 
1243
 
    def __init__(self, marker):
1244
 
        self.marker = marker
1245
 
 
1246
 
 
1247
 
class UnknownSmartMethod(InternalBzrError):
1248
 
 
1249
 
    _fmt = "The server does not recognise the '%(verb)s' request."
1250
 
 
1251
 
    def __init__(self, verb):
1252
 
        self.verb = verb
1253
 
 
1254
 
 
1255
 
class SmartMessageHandlerError(InternalBzrError):
1256
 
 
1257
 
    _fmt = ("The message handler raised an exception:\n"
1258
 
            "%(traceback_text)s")
1259
 
 
1260
 
    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
 
 
1269
 
 
1270
1408
# A set of semi-meaningful errors which can be thrown
1271
1409
class TransportNotPossible(TransportError):
1272
1410
 
1297
1435
            self.port = ':%s' % port
1298
1436
 
1299
1437
 
1300
 
# XXX: This is also used for unexpected end of file, which is different at the
1301
 
# TCP level from "connection reset".
1302
1438
class ConnectionReset(TransportError):
1303
1439
 
1304
1440
    _fmt = "Connection closed: %(msg)s %(orig_error)s"
1305
1441
 
1306
1442
 
1307
 
class ConnectionTimeout(ConnectionError):
1308
 
 
1309
 
    _fmt = "Connection Timeout: %(msg)s%(orig_error)s"
1310
 
 
1311
 
 
1312
1443
class InvalidRange(TransportError):
1313
1444
 
1314
 
    _fmt = "Invalid range access in %(path)s at %(offset)s: %(msg)s"
1315
 
 
1316
 
    def __init__(self, path, offset, msg=None):
1317
 
        TransportError.__init__(self, msg)
 
1445
    _fmt = "Invalid range access in %(path)s at %(offset)s."
 
1446
    
 
1447
    def __init__(self, path, offset):
 
1448
        TransportError.__init__(self, ("Invalid range access in %s at %d"
 
1449
                                       % (path, offset)))
1318
1450
        self.path = path
1319
1451
        self.offset = offset
1320
1452
 
1321
1453
 
1322
1454
class InvalidHttpResponse(TransportError):
1323
1455
 
1324
 
    _fmt = "Invalid http response for %(path)s: %(msg)s%(orig_error)s"
 
1456
    _fmt = "Invalid http response for %(path)s: %(msg)s"
1325
1457
 
1326
1458
    def __init__(self, path, msg, orig_error=None):
1327
1459
        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
1460
        TransportError.__init__(self, msg, orig_error=orig_error)
1335
1461
 
1336
1462
 
1337
1463
class InvalidHttpRange(InvalidHttpResponse):
1338
1464
 
1339
1465
    _fmt = "Invalid http range %(range)r for %(path)s: %(msg)s"
1340
 
 
 
1466
    
1341
1467
    def __init__(self, path, range, msg):
1342
1468
        self.range = range
1343
1469
        InvalidHttpResponse.__init__(self, path, msg)
1344
1470
 
1345
1471
 
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
1472
class InvalidHttpContentType(InvalidHttpResponse):
1360
1473
 
1361
1474
    _fmt = 'Invalid http Content-type "%(ctype)s" for %(path)s: %(msg)s'
1362
 
 
 
1475
    
1363
1476
    def __init__(self, path, ctype, msg):
1364
1477
        self.ctype = ctype
1365
1478
        InvalidHttpResponse.__init__(self, path, msg)
1369
1482
 
1370
1483
    _fmt = '%(source)s is%(permanently)s redirected to %(target)s'
1371
1484
 
1372
 
    def __init__(self, source, target, is_permanent=False):
 
1485
    def __init__(self, source, target, is_permanent=False, qual_proto=None):
1373
1486
        self.source = source
1374
1487
        self.target = target
1375
1488
        if is_permanent:
1376
1489
            self.permanently = ' permanently'
1377
1490
        else:
1378
1491
            self.permanently = ''
 
1492
        self._qualified_proto = qual_proto
1379
1493
        TransportError.__init__(self)
1380
1494
 
 
1495
    def _requalify_url(self, url):
 
1496
        """Restore the qualified proto in front of the url"""
 
1497
        # When this exception is raised, source and target are in
 
1498
        # user readable format. But some transports may use a
 
1499
        # different proto (http+urllib:// will present http:// to
 
1500
        # the user. If a qualified proto is specified, the code
 
1501
        # trapping the exception can get the qualified urls to
 
1502
        # properly handle the redirection themself (creating a
 
1503
        # new transport object from the target url for example).
 
1504
        # But checking that the scheme of the original and
 
1505
        # redirected urls are the same can be tricky. (see the
 
1506
        # FIXME in BzrDir.open_from_transport for the unique use
 
1507
        # case so far).
 
1508
        if self._qualified_proto is None:
 
1509
            return url
 
1510
 
 
1511
        # The TODO related to NotBranchError mention that doing
 
1512
        # that kind of manipulation on the urls may not be the
 
1513
        # exception object job. On the other hand, this object is
 
1514
        # the interface between the code and the user so
 
1515
        # presenting the urls in different ways is indeed its
 
1516
        # job...
 
1517
        import urlparse
 
1518
        proto, netloc, path, query, fragment = urlparse.urlsplit(url)
 
1519
        return urlparse.urlunsplit((self._qualified_proto, netloc, path,
 
1520
                                   query, fragment))
 
1521
 
 
1522
    def get_source_url(self):
 
1523
        return self._requalify_url(self.source)
 
1524
 
 
1525
    def get_target_url(self):
 
1526
        return self._requalify_url(self.target)
 
1527
 
1381
1528
 
1382
1529
class TooManyRedirections(TransportError):
1383
1530
 
1389
1536
    _fmt = "Working tree has conflicts."
1390
1537
 
1391
1538
 
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)
 
1539
class ParseConfigError(BzrError):
 
1540
 
 
1541
    def __init__(self, errors, filename):
 
1542
        if filename is None:
 
1543
            filename = ""
 
1544
        message = "Error(s) parsing config file %s:\n%s" % \
 
1545
            (filename, ('\n'.join(e.msg for e in errors)))
 
1546
        BzrError.__init__(self, message)
 
1547
 
 
1548
 
 
1549
class NoEmailInUsername(BzrError):
 
1550
 
 
1551
    _fmt = "%(username)r does not seem to contain a reasonable email address"
 
1552
 
 
1553
    def __init__(self, username):
 
1554
        BzrError.__init__(self)
 
1555
        self.username = username
 
1556
 
 
1557
 
 
1558
class SigningFailed(BzrError):
 
1559
 
 
1560
    _fmt = 'Failed to gpg sign data with command "%(command_line)s"'
 
1561
 
 
1562
    def __init__(self, command_line):
 
1563
        BzrError.__init__(self, command_line=command_line)
1398
1564
 
1399
1565
 
1400
1566
class WorkingTreeNotRevision(BzrError):
1401
1567
 
1402
 
    _fmt = ("The working tree for %(basedir)s has changed since"
 
1568
    _fmt = ("The working tree for %(basedir)s has changed since" 
1403
1569
            " the last commit, but weave merge requires that it be"
1404
1570
            " unchanged")
1405
1571
 
1518
1684
        self.prefix = prefix
1519
1685
 
1520
1686
 
1521
 
class MalformedTransform(InternalBzrError):
 
1687
class MalformedTransform(BzrError):
1522
1688
 
1523
1689
    _fmt = "Tree transform is malformed %(conflicts)r"
1524
1690
 
1562
1728
    _fmt = "Moving the root directory is not supported at this time"
1563
1729
 
1564
1730
 
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
1731
class BzrMoveFailedError(BzrError):
1577
1732
 
1578
 
    _fmt = ("Could not move %(from_path)s%(operator)s %(to_path)s"
1579
 
        "%(_has_extra)s%(extra)s")
 
1733
    _fmt = "Could not move %(from_path)s%(operator)s %(to_path)s%(extra)s"
1580
1734
 
1581
1735
    def __init__(self, from_path='', to_path='', extra=None):
1582
 
        from breezy.osutils import splitpath
1583
1736
        BzrError.__init__(self)
1584
1737
        if extra:
1585
 
            self.extra, self._has_extra = extra, ': '
 
1738
            self.extra = ': ' + str(extra)
1586
1739
        else:
1587
 
            self.extra = self._has_extra = ''
 
1740
            self.extra = ''
1588
1741
 
1589
1742
        has_from = len(from_path) > 0
1590
1743
        has_to = len(to_path) > 0
1591
1744
        if has_from:
1592
 
            self.from_path = splitpath(from_path)[-1]
 
1745
            self.from_path = osutils.splitpath(from_path)[-1]
1593
1746
        else:
1594
1747
            self.from_path = ''
1595
1748
 
1596
1749
        if has_to:
1597
 
            self.to_path = splitpath(to_path)[-1]
 
1750
            self.to_path = osutils.splitpath(to_path)[-1]
1598
1751
        else:
1599
1752
            self.to_path = ''
1600
1753
 
1611
1764
 
1612
1765
class BzrRenameFailedError(BzrMoveFailedError):
1613
1766
 
1614
 
    _fmt = ("Could not rename %(from_path)s%(operator)s %(to_path)s"
1615
 
        "%(_has_extra)s%(extra)s")
 
1767
    _fmt = "Could not rename %(from_path)s%(operator)s %(to_path)s%(extra)s"
1616
1768
 
1617
1769
    def __init__(self, from_path, to_path, extra=None):
1618
1770
        BzrMoveFailedError.__init__(self, from_path, to_path, extra)
1619
1771
 
 
1772
class BzrRemoveChangedFilesError(BzrError):
 
1773
    """Used when user is trying to remove changed files."""
 
1774
 
 
1775
    _fmt = ("Can't safely remove modified or unknown files:\n"
 
1776
        "%(changes_as_text)s"
 
1777
        "Use --keep to not delete them, or --force to delete them regardless.")
 
1778
 
 
1779
    def __init__(self, tree_delta):
 
1780
        BzrError.__init__(self)
 
1781
        self.changes_as_text = tree_delta.get_changes_as_text()
 
1782
        #self.paths_as_string = '\n'.join(changed_files)
 
1783
        #self.paths_as_string = '\n'.join([quotefn(p) for p in changed_files])
 
1784
 
1620
1785
 
1621
1786
class BzrBadParameterNotString(BzrBadParameter):
1622
1787
 
1625
1790
 
1626
1791
class BzrBadParameterMissing(BzrBadParameter):
1627
1792
 
1628
 
    _fmt = "Parameter %(param)s is required but not present."
 
1793
    _fmt = "Parameter $(param)s is required but not present."
1629
1794
 
1630
1795
 
1631
1796
class BzrBadParameterUnicode(BzrBadParameter):
1639
1804
    _fmt = "Parameter %(param)s contains a newline."
1640
1805
 
1641
1806
 
 
1807
class DependencyNotPresent(BzrError):
 
1808
 
 
1809
    _fmt = 'Unable to import library "%(library)s": %(error)s'
 
1810
 
 
1811
    def __init__(self, library, error):
 
1812
        BzrError.__init__(self, library=library, error=error)
 
1813
 
 
1814
 
1642
1815
class ParamikoNotPresent(DependencyNotPresent):
1643
1816
 
1644
1817
    _fmt = "Unable to import paramiko (required for sftp support): %(error)s"
1654
1827
 
1655
1828
class UninitializableFormat(BzrError):
1656
1829
 
1657
 
    _fmt = "Format %(format)s cannot be initialised by this version of brz."
 
1830
    _fmt = "Format %(format)s cannot be initialised by this version of bzr."
1658
1831
 
1659
1832
    def __init__(self, format):
1660
1833
        BzrError.__init__(self)
1663
1836
 
1664
1837
class BadConversionTarget(BzrError):
1665
1838
 
1666
 
    _fmt = "Cannot convert from format %(from_format)s to format %(format)s." \
1667
 
            "    %(problem)s"
 
1839
    _fmt = "Cannot convert to format %(format)s.  %(problem)s"
1668
1840
 
1669
 
    def __init__(self, problem, format, from_format=None):
 
1841
    def __init__(self, problem, format):
1670
1842
        BzrError.__init__(self)
1671
1843
        self.problem = problem
1672
1844
        self.format = format
1673
 
        self.from_format = from_format or '(unspecified)'
1674
 
 
1675
 
 
1676
 
class NoDiffFound(BzrError):
1677
 
 
1678
 
    _fmt = 'Could not find an appropriate Differ for file "%(path)s"'
1679
 
 
1680
 
    def __init__(self, path):
1681
 
        BzrError.__init__(self, path)
1682
 
 
1683
 
 
1684
 
class ExecutableMissing(BzrError):
1685
 
 
1686
 
    _fmt = "%(exe_name)s could not be found on this machine"
1687
 
 
1688
 
    def __init__(self, exe_name):
1689
 
        BzrError.__init__(self, exe_name=exe_name)
1690
1845
 
1691
1846
 
1692
1847
class NoDiff(BzrError):
1703
1858
 
1704
1859
 
1705
1860
class ExistingContent(BzrError):
1706
 
    # Added in breezy 0.92, used by VersionedFile.add_lines.
 
1861
    # Added in bzrlib 0.92, used by VersionedFile.add_lines.
1707
1862
 
1708
1863
    _fmt = "The content being inserted is already present."
1709
1864
 
1713
1868
    _fmt = """This tree contains left-over files from a failed operation.
1714
1869
    Please examine %(limbo_dir)s to see if it contains any files you wish to
1715
1870
    keep, and delete it when you are done."""
1716
 
 
 
1871
    
1717
1872
    def __init__(self, limbo_dir):
1718
1873
       BzrError.__init__(self)
1719
1874
       self.limbo_dir = limbo_dir
1752
1907
 
1753
1908
class OutOfDateTree(BzrError):
1754
1909
 
1755
 
    _fmt = "Working tree is out of date, please run 'brz update'.%(more)s"
 
1910
    _fmt = "Working tree is out of date, please run 'bzr update'."
1756
1911
 
1757
 
    def __init__(self, tree, more=None):
1758
 
        if more is None:
1759
 
            more = ''
1760
 
        else:
1761
 
            more = ' ' + more
 
1912
    def __init__(self, tree):
1762
1913
        BzrError.__init__(self)
1763
1914
        self.tree = tree
1764
 
        self.more = more
1765
1915
 
1766
1916
 
1767
1917
class PublicBranchOutOfDate(BzrError):
1770
1920
        '"%(revstring)s".'
1771
1921
 
1772
1922
    def __init__(self, public_location, revstring):
1773
 
        import breezy.urlutils as urlutils
 
1923
        import bzrlib.urlutils as urlutils
1774
1924
        public_location = urlutils.unescape_for_display(public_location,
1775
1925
                                                        'ascii')
1776
1926
        BzrError.__init__(self, public_location=public_location,
1790
1940
class CorruptRepository(BzrError):
1791
1941
 
1792
1942
    _fmt = ("An error has been detected in the repository %(repo_path)s.\n"
1793
 
            "Please run brz reconcile on this repository.")
 
1943
            "Please run bzr reconcile on this repository.")
1794
1944
 
1795
1945
    def __init__(self, repo):
1796
1946
        BzrError.__init__(self)
1797
 
        self.repo_path = repo.user_url
1798
 
 
1799
 
 
1800
 
class InconsistentDelta(BzrError):
1801
 
    """Used when we get a delta that is not valid."""
1802
 
 
1803
 
    _fmt = ("An inconsistent delta was supplied involving %(path)r,"
1804
 
            " %(file_id)r\nreason: %(reason)s")
1805
 
 
1806
 
    def __init__(self, path, file_id, reason):
1807
 
        BzrError.__init__(self)
1808
 
        self.path = path
1809
 
        self.file_id = file_id
1810
 
        self.reason = reason
1811
 
 
1812
 
 
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
 
1947
        self.repo_path = repo.bzrdir.root_transport.base
1823
1948
 
1824
1949
 
1825
1950
class UpgradeRequired(BzrError):
1831
1956
        self.path = path
1832
1957
 
1833
1958
 
1834
 
class RepositoryUpgradeRequired(UpgradeRequired):
1835
 
 
1836
 
    _fmt = "To use this feature you must upgrade your repository at %(path)s."
1837
 
 
1838
 
 
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
1959
class LocalRequiresBoundBranch(BzrError):
1846
1960
 
1847
1961
    _fmt = "Cannot perform local-only commits on unbound branches."
1848
1962
 
1849
1963
 
 
1964
class MissingProgressBarFinish(BzrError):
 
1965
 
 
1966
    _fmt = "A nested progress bar was not 'finished' correctly."
 
1967
 
 
1968
 
 
1969
class InvalidProgressBarType(BzrError):
 
1970
 
 
1971
    _fmt = ("Environment variable BZR_PROGRESS_BAR='%(bar_type)s"
 
1972
            " is not a supported type Select one of: %(valid_types)s")
 
1973
 
 
1974
    def __init__(self, bar_type, valid_types):
 
1975
        BzrError.__init__(self, bar_type=bar_type, valid_types=valid_types)
 
1976
 
 
1977
 
1850
1978
class UnsupportedOperation(BzrError):
1851
1979
 
1852
1980
    _fmt = ("The method %(mname)s is not supported on"
1858
1986
        self.tname = type(method_self).__name__
1859
1987
 
1860
1988
 
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)
 
1989
class CannotSetRevisionId(UnsupportedOperation):
 
1990
    """Raised when a commit is attempting to set a revision id but cant."""
1867
1991
 
1868
1992
 
1869
1993
class NonAsciiRevisionId(UnsupportedOperation):
1872
1996
    """
1873
1997
 
1874
1998
 
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
1999
class BinaryFile(BzrError):
1884
 
 
 
2000
    
1885
2001
    _fmt = "File is binary but should be text."
1886
2002
 
1887
2003
 
1907
2023
 
1908
2024
 
1909
2025
class NotABundle(BzrError):
1910
 
 
 
2026
    
1911
2027
    _fmt = "Not a bzr revision-bundle: %(text)r"
1912
2028
 
1913
2029
    def __init__(self, text):
1915
2031
        self.text = text
1916
2032
 
1917
2033
 
1918
 
class BadBundle(BzrError):
1919
 
 
 
2034
class BadBundle(BzrError): 
 
2035
    
1920
2036
    _fmt = "Bad bzr revision-bundle: %(text)r"
1921
2037
 
1922
2038
    def __init__(self, text):
1924
2040
        self.text = text
1925
2041
 
1926
2042
 
1927
 
class MalformedHeader(BadBundle):
1928
 
 
 
2043
class MalformedHeader(BadBundle): 
 
2044
    
1929
2045
    _fmt = "Malformed bzr revision-bundle header: %(text)r"
1930
2046
 
1931
2047
 
1932
 
class MalformedPatches(BadBundle):
1933
 
 
 
2048
class MalformedPatches(BadBundle): 
 
2049
    
1934
2050
    _fmt = "Malformed patches in bzr revision-bundle: %(text)r"
1935
2051
 
1936
2052
 
1937
 
class MalformedFooter(BadBundle):
1938
 
 
 
2053
class MalformedFooter(BadBundle): 
 
2054
    
1939
2055
    _fmt = "Malformed footer in bzr revision-bundle: %(text)r"
1940
2056
 
1941
2057
 
1942
2058
class UnsupportedEOLMarker(BadBundle):
1943
 
 
1944
 
    _fmt = "End of line marker was not \\n in bzr revision-bundle"
 
2059
    
 
2060
    _fmt = "End of line marker was not \\n in bzr revision-bundle"    
1945
2061
 
1946
2062
    def __init__(self):
1947
 
        # XXX: BadBundle's constructor assumes there's explanatory text,
 
2063
        # XXX: BadBundle's constructor assumes there's explanatory text, 
1948
2064
        # but for this there is not
1949
2065
        BzrError.__init__(self)
1950
2066
 
1951
2067
 
1952
2068
class IncompatibleBundleFormat(BzrError):
1953
 
 
 
2069
    
1954
2070
    _fmt = "Bundle format %(bundle_format)s is incompatible with %(other)s"
1955
2071
 
1956
2072
    def __init__(self, bundle_format, other):
1960
2076
 
1961
2077
 
1962
2078
class BadInventoryFormat(BzrError):
1963
 
 
 
2079
    
1964
2080
    _fmt = "Root class for inventory serialization errors"
1965
2081
 
1966
2082
 
1985
2101
        self.transport = transport
1986
2102
 
1987
2103
 
 
2104
class NoSmartServer(NotBranchError):
 
2105
 
 
2106
    _fmt = "No smart server available at %(url)s"
 
2107
 
 
2108
    def __init__(self, url):
 
2109
        self.url = url
 
2110
 
 
2111
 
1988
2112
class UnknownSSH(BzrError):
1989
2113
 
1990
 
    _fmt = "Unrecognised value for BRZ_SSH environment variable: %(vendor)s"
 
2114
    _fmt = "Unrecognised value for BZR_SSH environment variable: %(vendor)s"
1991
2115
 
1992
2116
    def __init__(self, vendor):
1993
2117
        BzrError.__init__(self)
1997
2121
class SSHVendorNotFound(BzrError):
1998
2122
 
1999
2123
    _fmt = ("Don't know how to handle SSH connections."
2000
 
            " Please set BRZ_SSH environment variable.")
2001
 
 
2002
 
 
2003
 
class GhostRevisionsHaveNoRevno(BzrError):
2004
 
    """When searching for revnos, if we encounter a ghost, we are stuck"""
2005
 
 
2006
 
    _fmt = ("Could not determine revno for {%(revision_id)s} because"
2007
 
            " its ancestry shows a ghost at {%(ghost_revision_id)s}")
2008
 
 
2009
 
    def __init__(self, revision_id, ghost_revision_id):
2010
 
        self.revision_id = revision_id
2011
 
        self.ghost_revision_id = ghost_revision_id
 
2124
            " Please set BZR_SSH environment variable.")
2012
2125
 
2013
2126
 
2014
2127
class GhostRevisionUnusableHere(BzrError):
2094
2207
        self.patch_type = patch_type
2095
2208
 
2096
2209
 
2097
 
class TargetNotBranch(BzrError):
2098
 
    """A merge directive's target branch is required, but isn't a branch"""
2099
 
 
2100
 
    _fmt = ("Your branch does not have all of the revisions required in "
2101
 
            "order to merge this merge directive and the target "
2102
 
            "location specified in the merge directive is not a branch: "
2103
 
            "%(location)s.")
2104
 
 
2105
 
    def __init__(self, location):
2106
 
        BzrError.__init__(self)
2107
 
        self.location = location
2108
 
 
2109
 
 
2110
2210
class UnsupportedInventoryKind(BzrError):
2111
 
 
 
2211
    
2112
2212
    _fmt = """Unsupported entry kind %(kind)s"""
2113
2213
 
2114
2214
    def __init__(self, kind):
2126
2226
 
2127
2227
 
2128
2228
class SubsumeTargetNeedsUpgrade(BzrError):
2129
 
 
 
2229
    
2130
2230
    _fmt = """Subsume target %(other_tree)s needs to be upgraded."""
2131
2231
 
2132
2232
    def __init__(self, other_tree):
2133
2233
        self.other_tree = other_tree
2134
2234
 
2135
2235
 
 
2236
class BadReferenceTarget(InternalBzrError):
 
2237
 
 
2238
    _fmt = "Can't add reference to %(other_tree)s into %(tree)s." \
 
2239
           "%(reason)s"
 
2240
 
 
2241
    def __init__(self, tree, other_tree, reason):
 
2242
        self.tree = tree
 
2243
        self.other_tree = other_tree
 
2244
        self.reason = reason
 
2245
 
 
2246
 
2136
2247
class NoSuchTag(BzrError):
2137
2248
 
2138
2249
    _fmt = "No such tag: %(tag_name)s"
2144
2255
class TagsNotSupported(BzrError):
2145
2256
 
2146
2257
    _fmt = ("Tags not supported by %(branch)s;"
2147
 
            " you may be able to use brz upgrade.")
 
2258
            " you may be able to use bzr upgrade --dirstate-tags.")
2148
2259
 
2149
2260
    def __init__(self, branch):
2150
2261
        self.branch = branch
2151
2262
 
2152
 
 
 
2263
        
2153
2264
class TagAlreadyExists(BzrError):
2154
2265
 
2155
2266
    _fmt = "Tag %(tag_name)s already exists."
2158
2269
        self.tag_name = tag_name
2159
2270
 
2160
2271
 
 
2272
class MalformedBugIdentifier(BzrError):
 
2273
 
 
2274
    _fmt = "Did not understand bug identifier %(bug_id)s: %(reason)s"
 
2275
 
 
2276
    def __init__(self, bug_id, reason):
 
2277
        self.bug_id = bug_id
 
2278
        self.reason = reason
 
2279
 
 
2280
 
 
2281
class UnknownBugTrackerAbbreviation(BzrError):
 
2282
 
 
2283
    _fmt = ("Cannot find registered bug tracker called %(abbreviation)s "
 
2284
            "on %(branch)s")
 
2285
 
 
2286
    def __init__(self, abbreviation, branch):
 
2287
        self.abbreviation = abbreviation
 
2288
        self.branch = branch
 
2289
 
 
2290
 
2161
2291
class UnexpectedSmartServerResponse(BzrError):
2162
2292
 
2163
2293
    _fmt = "Could not understand response from smart server: %(response_tuple)r"
2166
2296
        self.response_tuple = response_tuple
2167
2297
 
2168
2298
 
2169
 
class ErrorFromSmartServer(BzrError):
2170
 
    """An error was received from a smart server.
2171
 
 
2172
 
    :seealso: UnknownErrorFromSmartServer
2173
 
    """
2174
 
 
2175
 
    _fmt = "Error received from smart server: %(error_tuple)r"
2176
 
 
2177
 
    internal_error = True
2178
 
 
2179
 
    def __init__(self, error_tuple):
2180
 
        self.error_tuple = error_tuple
2181
 
        try:
2182
 
            self.error_verb = error_tuple[0]
2183
 
        except IndexError:
2184
 
            self.error_verb = None
2185
 
        self.error_args = error_tuple[1:]
2186
 
 
2187
 
 
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
2299
class ContainerError(BzrError):
2216
2300
    """Base class of container errors."""
2217
2301
 
2219
2303
class UnknownContainerFormatError(ContainerError):
2220
2304
 
2221
2305
    _fmt = "Unrecognised container format: %(container_format)r"
2222
 
 
 
2306
    
2223
2307
    def __init__(self, container_format):
2224
2308
        self.container_format = container_format
2225
2309
 
2258
2342
    _fmt = "Container has multiple records with the same name: %(name)s"
2259
2343
 
2260
2344
    def __init__(self, name):
2261
 
        self.name = name.decode("utf-8")
 
2345
        self.name = name
 
2346
 
 
2347
 
 
2348
class NoDestinationAddress(InternalBzrError):
 
2349
 
 
2350
    _fmt = "Message does not have a destination address."
2262
2351
 
2263
2352
 
2264
2353
class RepositoryDataStreamError(BzrError):
2269
2358
        self.reason = reason
2270
2359
 
2271
2360
 
 
2361
class SMTPError(BzrError):
 
2362
 
 
2363
    _fmt = "SMTP error: %(error)s"
 
2364
 
 
2365
    def __init__(self, error):
 
2366
        self.error = error
 
2367
 
 
2368
 
 
2369
class NoMessageSupplied(BzrError):
 
2370
 
 
2371
    _fmt = "No message supplied."
 
2372
 
 
2373
 
 
2374
class UnknownMailClient(BzrError):
 
2375
 
 
2376
    _fmt = "Unknown mail client: %(mail_client)s"
 
2377
 
 
2378
    def __init__(self, mail_client):
 
2379
        BzrError.__init__(self, mail_client=mail_client)
 
2380
 
 
2381
 
 
2382
class MailClientNotFound(BzrError):
 
2383
 
 
2384
    _fmt = "Unable to find mail client with the following names:"\
 
2385
        " %(mail_command_list_string)s"
 
2386
 
 
2387
    def __init__(self, mail_command_list):
 
2388
        mail_command_list_string = ', '.join(mail_command_list)
 
2389
        BzrError.__init__(self, mail_command_list=mail_command_list,
 
2390
                          mail_command_list_string=mail_command_list_string)
 
2391
 
 
2392
class SMTPConnectionRefused(SMTPError):
 
2393
 
 
2394
    _fmt = "SMTP connection to %(host)s refused"
 
2395
 
 
2396
    def __init__(self, error, host):
 
2397
        self.error = error
 
2398
        self.host = host
 
2399
 
 
2400
 
 
2401
class DefaultSMTPConnectionRefused(SMTPConnectionRefused):
 
2402
 
 
2403
    _fmt = "Please specify smtp_server.  No server at default %(host)s."
 
2404
 
 
2405
 
 
2406
class BzrDirError(BzrError):
 
2407
 
 
2408
    def __init__(self, bzrdir):
 
2409
        import bzrlib.urlutils as urlutils
 
2410
        display_url = urlutils.unescape_for_display(bzrdir.root_transport.base,
 
2411
                                                    'ascii')
 
2412
        BzrError.__init__(self, bzrdir=bzrdir, display_url=display_url)
 
2413
 
 
2414
 
 
2415
class AlreadyBranch(BzrDirError):
 
2416
 
 
2417
    _fmt = "'%(display_url)s' is already a branch."
 
2418
 
 
2419
 
 
2420
class AlreadyTree(BzrDirError):
 
2421
 
 
2422
    _fmt = "'%(display_url)s' is already a tree."
 
2423
 
 
2424
 
 
2425
class AlreadyCheckout(BzrDirError):
 
2426
 
 
2427
    _fmt = "'%(display_url)s' is already a checkout."
 
2428
 
 
2429
 
 
2430
class ReconfigurationNotSupported(BzrDirError):
 
2431
 
 
2432
    _fmt = "Requested reconfiguration of '%(display_url)s' is not supported."
 
2433
 
 
2434
 
 
2435
class NoBindLocation(BzrDirError):
 
2436
 
 
2437
    _fmt = "No location could be found to bind to at %(display_url)s."
 
2438
 
 
2439
 
2272
2440
class UncommittedChanges(BzrError):
2273
2441
 
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')
2310
 
 
2311
 
 
2312
 
class UnableCreateSymlink(BzrError):
2313
 
 
2314
 
    _fmt = 'Unable to create symlink %(path_str)son this platform'
2315
 
 
2316
 
    def __init__(self, path=None):
2317
 
        path_str = ''
2318
 
        if path:
2319
 
            try:
2320
 
                path_str = repr(str(path))
2321
 
            except UnicodeEncodeError:
2322
 
                path_str = repr(path)
2323
 
            path_str += ' '
2324
 
        self.path_str = path_str
2325
 
 
2326
 
 
2327
 
class UnableEncodePath(BzrError):
2328
 
 
2329
 
    _fmt = ('Unable to encode %(kind)s path %(path)r in '
2330
 
            'user encoding %(user_encoding)s')
2331
 
 
2332
 
    def __init__(self, path, kind):
2333
 
        from breezy.osutils import get_user_encoding
2334
 
        self.path = path
2335
 
        self.kind = kind
2336
 
        self.user_encoding = get_user_encoding()
2337
 
 
2338
 
 
2339
 
class NoSuchAlias(BzrError):
2340
 
 
2341
 
    _fmt = ('The alias "%(alias_name)s" does not exist.')
2342
 
 
2343
 
    def __init__(self, alias_name):
2344
 
        BzrError.__init__(self, alias_name=alias_name)
2345
 
 
2346
 
 
2347
 
class CannotBindAddress(BzrError):
2348
 
 
2349
 
    _fmt = 'Cannot bind address "%(host)s:%(port)i": %(orig_error)s.'
2350
 
 
2351
 
    def __init__(self, host, port, orig_error):
2352
 
        # nb: in python2.4 socket.error doesn't have a useful repr
2353
 
        BzrError.__init__(self, host=host, port=port,
2354
 
            orig_error=repr(orig_error.args))
2355
 
 
2356
 
 
2357
 
class TipChangeRejected(BzrError):
2358
 
    """A pre_change_branch_tip hook function may raise this to cleanly and
2359
 
    explicitly abort a change to a branch tip.
2360
 
    """
2361
 
 
2362
 
    _fmt = u"Tip change rejected: %(msg)s"
2363
 
 
2364
 
    def __init__(self, msg):
2365
 
        self.msg = msg
2366
 
 
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.')
 
2442
    _fmt = 'Working tree "%(display_url)s" has uncommitted changes.'
 
2443
 
 
2444
    def __init__(self, tree):
 
2445
        import bzrlib.urlutils as urlutils
 
2446
        display_url = urlutils.unescape_for_display(
 
2447
            tree.bzrdir.root_transport.base, 'ascii')
 
2448
        BzrError.__init__(self, tree=tree, display_url=display_url)