~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/errors.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2007-07-19 16:09:34 UTC
  • mfrom: (2520.4.135 bzr.mpbundle)
  • Revision ID: pqm@pqm.ubuntu.com-20070719160934-d51fyijw69oto88p
Add new bundle and merge-directive formats

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005-2011 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
 
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
 
21
33
 
22
34
# TODO: is there any value in providing the .args field used by standard
23
 
# 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 
24
36
# to me.
25
37
 
26
 
# 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 
27
39
# constructed to make sure it will succeed.  But that says nothing about
28
40
# exceptions that are never raised.
29
41
 
32
44
# 'unprintable'.
33
45
 
34
46
 
35
 
# return codes from the bzr program
36
 
EXIT_OK = 0
37
 
EXIT_ERROR = 3
38
 
EXIT_INTERNAL_ERROR = 4
39
 
 
40
 
 
41
47
class BzrError(StandardError):
42
48
    """
43
49
    Base class for errors raised by bzrlib.
44
50
 
45
51
    :cvar internal_error: if True this was probably caused by a bzr bug and
46
 
        should be displayed with a traceback; if False (or absent) this was
47
 
        probably a user or environment error and they don't need the gory
48
 
        details.  (That can be overridden by -Derror on the command line.)
 
52
    should be displayed with a traceback; if False (or absent) this was
 
53
    probably a user or environment error and they don't need the gory details.
 
54
    (That can be overridden by -Derror on the command line.)
49
55
 
50
56
    :cvar _fmt: Format string to display the error; this is expanded
51
 
        by the instance's dict.
 
57
    by the instance's dict.
52
58
    """
53
 
 
 
59
    
54
60
    internal_error = False
55
61
 
56
62
    def __init__(self, msg=None, **kwds):
61
67
        arguments can be given.  The first is for generic "user" errors which
62
68
        are not intended to be caught and so do not need a specific subclass.
63
69
        The second case is for use with subclasses that provide a _fmt format
64
 
        string to print the arguments.
 
70
        string to print the arguments.  
65
71
 
66
 
        Keyword arguments are taken as parameters to the error, which can
67
 
        be inserted into the format string template.  It's recommended
68
 
        that subclasses override the __init__ method to require specific
 
72
        Keyword arguments are taken as parameters to the error, which can 
 
73
        be inserted into the format string template.  It's recommended 
 
74
        that subclasses override the __init__ method to require specific 
69
75
        parameters.
70
76
 
71
77
        :param msg: If given, this is the literal complete text for the error,
72
 
           not subject to expansion. 'msg' is used instead of 'message' because
73
 
           python evolved and, in 2.6, forbids the use of 'message'.
 
78
        not subject to expansion.
74
79
        """
75
80
        StandardError.__init__(self)
76
81
        if msg is not None:
82
87
            for key, value in kwds.items():
83
88
                setattr(self, key, value)
84
89
 
85
 
    def _format(self):
 
90
    def __str__(self):
86
91
        s = getattr(self, '_preformatted_string', None)
87
92
        if s is not None:
88
 
            # contains a preformatted message
89
 
            return s
 
93
            # contains a preformatted message; must be cast to plain str
 
94
            return str(s)
90
95
        try:
91
96
            fmt = self._get_format_string()
92
97
            if fmt:
93
 
                d = dict(self.__dict__)
94
 
                s = fmt % d
 
98
                s = fmt % self.__dict__
95
99
                # __str__() should always return a 'str' object
96
100
                # never a 'unicode' object.
 
101
                if isinstance(s, unicode):
 
102
                    return s.encode('utf8')
97
103
                return s
98
 
        except Exception, e:
99
 
            pass # just bind to 'e' for formatting below
100
 
        else:
101
 
            e = None
102
 
        return 'Unprintable exception %s: dict=%r, fmt=%r, error=%r' \
 
104
        except (AttributeError, TypeError, NameError, ValueError, KeyError), e:
 
105
            return 'Unprintable exception %s: dict=%r, fmt=%r, error=%r' \
 
106
                % (self.__class__.__name__,
 
107
                   self.__dict__,
 
108
                   getattr(self, '_fmt', None),
 
109
                   e)
 
110
 
 
111
    def _get_format_string(self):
 
112
        """Return format string for this exception or None"""
 
113
        fmt = getattr(self, '_fmt', None)
 
114
        if fmt is not None:
 
115
            return fmt
 
116
        fmt = getattr(self, '__doc__', None)
 
117
        if fmt is not None:
 
118
            symbol_versioning.warn("%s uses its docstring as a format, "
 
119
                    "it should use _fmt instead" % self.__class__.__name__,
 
120
                    DeprecationWarning)
 
121
            return fmt
 
122
        return 'Unprintable exception %s: dict=%r, fmt=%r' \
103
123
            % (self.__class__.__name__,
104
124
               self.__dict__,
105
125
               getattr(self, '_fmt', None),
106
 
               e)
107
 
 
108
 
    def __unicode__(self):
109
 
        u = self._format()
110
 
        if isinstance(u, str):
111
 
            # Try decoding the str using the default encoding.
112
 
            u = unicode(u)
113
 
        elif not isinstance(u, unicode):
114
 
            # Try to make a unicode object from it, because __unicode__ must
115
 
            # return a unicode object.
116
 
            u = unicode(u)
117
 
        return u
 
126
               )
 
127
 
 
128
 
 
129
class BzrNewError(BzrError):
 
130
    """Deprecated error base class."""
 
131
    # base classes should override the docstring with their human-
 
132
    # readable explanation
 
133
 
 
134
    def __init__(self, *args, **kwds):
 
135
        # XXX: Use the underlying BzrError to always generate the args
 
136
        # attribute if it doesn't exist.  We can't use super here, because
 
137
        # exceptions are old-style classes in python2.4 (but new in 2.5).
 
138
        # --bmc, 20060426
 
139
        symbol_versioning.warn('BzrNewError was deprecated in bzr 0.13; '
 
140
             'please convert %s to use BzrError instead'
 
141
             % self.__class__.__name__,
 
142
             DeprecationWarning,
 
143
             stacklevel=2)
 
144
        BzrError.__init__(self, *args)
 
145
        for key, value in kwds.items():
 
146
            setattr(self, key, value)
118
147
 
119
148
    def __str__(self):
120
 
        s = self._format()
121
 
        if isinstance(s, unicode):
122
 
            s = s.encode('utf8')
123
 
        else:
124
 
            # __str__ must return a str.
125
 
            s = str(s)
126
 
        return s
127
 
 
128
 
    def __repr__(self):
129
 
        return '%s(%s)' % (self.__class__.__name__, str(self))
130
 
 
131
 
    def _get_format_string(self):
132
 
        """Return format string for this exception or None"""
133
 
        fmt = getattr(self, '_fmt', None)
134
 
        if fmt is not None:
135
 
            from bzrlib.i18n import gettext
136
 
            return gettext(unicode(fmt)) # _fmt strings should be ascii
137
 
 
138
 
    def __eq__(self, other):
139
 
        if self.__class__ is not other.__class__:
140
 
            return NotImplemented
141
 
        return self.__dict__ == other.__dict__
142
 
 
143
 
 
144
 
class InternalBzrError(BzrError):
145
 
    """Base class for errors that are internal in nature.
146
 
 
147
 
    This is a convenience class for errors that are internal. The
148
 
    internal_error attribute can still be altered in subclasses, if needed.
149
 
    Using this class is simply an easy way to get internal errors.
150
 
    """
151
 
 
152
 
    internal_error = True
 
149
        try:
 
150
            # __str__() should always return a 'str' object
 
151
            # never a 'unicode' object.
 
152
            s = self.__doc__ % self.__dict__
 
153
            if isinstance(s, unicode):
 
154
                return s.encode('utf8')
 
155
            return s
 
156
        except (TypeError, NameError, ValueError, KeyError), e:
 
157
            return 'Unprintable exception %s(%r): %r' \
 
158
                % (self.__class__.__name__,
 
159
                   self.__dict__, e)
153
160
 
154
161
 
155
162
class AlreadyBuilding(BzrError):
156
 
 
 
163
    
157
164
    _fmt = "The tree builder is already building a tree."
158
165
 
159
166
 
160
 
class BranchError(BzrError):
161
 
    """Base class for concrete 'errors about a branch'."""
162
 
 
163
 
    def __init__(self, branch):
164
 
        BzrError.__init__(self, branch=branch)
165
 
 
166
 
 
167
 
class BzrCheckError(InternalBzrError):
168
 
 
169
 
    _fmt = "Internal check failed: %(msg)s"
170
 
 
171
 
    def __init__(self, msg):
172
 
        BzrError.__init__(self)
173
 
        self.msg = msg
174
 
 
175
 
 
176
 
class DirstateCorrupt(BzrError):
177
 
 
178
 
    _fmt = "The dirstate file (%(state)s) appears to be corrupt: %(msg)s"
179
 
 
180
 
    def __init__(self, state, msg):
181
 
        BzrError.__init__(self)
182
 
        self.state = state
183
 
        self.msg = msg
184
 
 
185
 
 
186
 
class DisabledMethod(InternalBzrError):
 
167
class BzrCheckError(BzrError):
 
168
    
 
169
    _fmt = "Internal check failed: %(message)s"
 
170
 
 
171
    internal_error = True
 
172
 
 
173
    def __init__(self, message):
 
174
        BzrError.__init__(self)
 
175
        self.message = message
 
176
 
 
177
 
 
178
class DisabledMethod(BzrError):
187
179
 
188
180
    _fmt = "The smart server method '%(class_name)s' is disabled."
189
181
 
 
182
    internal_error = True
 
183
 
190
184
    def __init__(self, class_name):
191
185
        BzrError.__init__(self)
192
186
        self.class_name = class_name
204
198
        self.current = current
205
199
 
206
200
 
207
 
class InProcessTransport(BzrError):
208
 
 
209
 
    _fmt = "The transport '%(transport)s' is only accessible within this " \
210
 
        "process."
211
 
 
212
 
    def __init__(self, transport):
213
 
        self.transport = transport
214
 
 
215
 
 
216
 
class InvalidEntryName(InternalBzrError):
217
 
 
 
201
class InvalidEntryName(BzrError):
 
202
    
218
203
    _fmt = "Invalid entry name: %(name)s"
219
204
 
 
205
    internal_error = True
 
206
 
220
207
    def __init__(self, name):
221
208
        BzrError.__init__(self)
222
209
        self.name = name
223
210
 
224
211
 
225
212
class InvalidRevisionNumber(BzrError):
226
 
 
 
213
    
227
214
    _fmt = "Invalid revision number %(revno)s"
228
215
 
229
216
    def __init__(self, revno):
241
228
        self.revision_id = revision_id
242
229
        self.branch = branch
243
230
 
244
 
 
245
231
class ReservedId(BzrError):
246
232
 
247
233
    _fmt = "Reserved revision-id {%(revision_id)s}"
250
236
        self.revision_id = revision_id
251
237
 
252
238
 
253
 
class RootMissing(InternalBzrError):
254
 
 
255
 
    _fmt = ("The root entry of a tree must be the first entry supplied to "
256
 
        "the commit builder.")
257
 
 
258
 
 
259
 
class NoPublicBranch(BzrError):
260
 
 
261
 
    _fmt = 'There is no public branch set for "%(branch_url)s".'
262
 
 
263
 
    def __init__(self, branch):
264
 
        import bzrlib.urlutils as urlutils
265
 
        public_location = urlutils.unescape_for_display(branch.base, 'ascii')
266
 
        BzrError.__init__(self, branch_url=public_location)
267
 
 
268
 
 
269
239
class NoHelpTopic(BzrError):
270
240
 
271
241
    _fmt = ("No help could be found for '%(topic)s'. "
277
247
 
278
248
class NoSuchId(BzrError):
279
249
 
280
 
    _fmt = 'The file id "%(file_id)s" is not present in the tree %(tree)s.'
281
 
 
 
250
    _fmt = "The file id %(file_id)s is not present in the tree %(tree)s."
 
251
    
282
252
    def __init__(self, tree, file_id):
283
253
        BzrError.__init__(self)
284
254
        self.file_id = file_id
285
255
        self.tree = tree
286
256
 
287
257
 
288
 
class NoSuchIdInRepository(NoSuchId):
289
 
 
290
 
    _fmt = ('The file id "%(file_id)s" is not present in the repository'
291
 
            ' %(repository)r')
292
 
 
293
 
    def __init__(self, repository, file_id):
294
 
        BzrError.__init__(self, repository=repository, file_id=file_id)
295
 
 
296
 
 
297
 
class NotStacked(BranchError):
298
 
 
299
 
    _fmt = "The branch '%(branch)s' is not stacked."
300
 
 
301
 
 
302
 
class InventoryModified(InternalBzrError):
 
258
class InventoryModified(BzrError):
303
259
 
304
260
    _fmt = ("The current inventory for the tree %(tree)r has been modified,"
305
261
            " so a clean inventory cannot be read without data loss.")
306
262
 
 
263
    internal_error = True
 
264
 
307
265
    def __init__(self, tree):
308
266
        self.tree = tree
309
267
 
310
268
 
311
269
class NoWorkingTree(BzrError):
312
270
 
313
 
    _fmt = 'No WorkingTree exists for "%(base)s".'
314
 
 
 
271
    _fmt = "No WorkingTree exists for %(base)s."
 
272
    
315
273
    def __init__(self, base):
316
274
        BzrError.__init__(self)
317
275
        self.base = base
330
288
        self.url = url
331
289
 
332
290
 
333
 
class WorkingTreeAlreadyPopulated(InternalBzrError):
334
 
 
335
 
    _fmt = 'Working tree already populated in "%(base)s"'
 
291
class WorkingTreeAlreadyPopulated(BzrError):
 
292
 
 
293
    _fmt = """Working tree already populated in %(base)s"""
 
294
 
 
295
    internal_error = True
336
296
 
337
297
    def __init__(self, base):
338
298
        self.base = base
339
299
 
340
 
 
341
300
class BzrCommandError(BzrError):
342
301
    """Error from user command"""
343
302
 
 
303
    internal_error = False
 
304
 
344
305
    # Error from malformed user command; please avoid raising this as a
345
306
    # generic exception not caused by user input.
346
307
    #
348
309
    # are not intended to be caught anyway.  UI code need not subclass
349
310
    # BzrCommandError, and non-UI code should not throw a subclass of
350
311
    # BzrCommandError.  ADHB 20051211
 
312
    def __init__(self, msg):
 
313
        # Object.__str__() must return a real string
 
314
        # returning a Unicode string is a python error.
 
315
        if isinstance(msg, unicode):
 
316
            self.msg = msg.encode('utf8')
 
317
        else:
 
318
            self.msg = msg
 
319
 
 
320
    def __str__(self):
 
321
        return self.msg
351
322
 
352
323
 
353
324
class NotWriteLocked(BzrError):
426
397
    def __init__(self, name, value):
427
398
        BzrError.__init__(self, name=name, value=value)
428
399
 
429
 
 
 
400
    
430
401
class StrictCommitFailed(BzrError):
431
402
 
432
403
    _fmt = "Commit refused because there are unknown files in the tree"
435
406
# XXX: Should be unified with TransportError; they seem to represent the
436
407
# same thing
437
408
# RBC 20060929: I think that unifiying with TransportError would be a mistake
438
 
# - this is finer than a TransportError - and more useful as such. It
 
409
# - this is finer than a TransportError - and more useful as such. It 
439
410
# differentiates between 'transport has failed' and 'operation on a transport
440
411
# has failed.'
441
412
class PathError(BzrError):
442
 
 
 
413
    
443
414
    _fmt = "Generic path error: %(path)r%(extra)s)"
444
415
 
445
416
    def __init__(self, path, extra=None):
465
436
    """Used when renaming and both source and dest exist."""
466
437
 
467
438
    _fmt = ("Could not rename %(source)s => %(dest)s because both files exist."
468
 
            " (Use --after to tell bzr about a rename that has already"
469
 
            " happened)%(extra)s")
 
439
            "%(extra)s")
470
440
 
471
441
    def __init__(self, source, dest, extra=None):
472
442
        BzrError.__init__(self)
480
450
 
481
451
class NotADirectory(PathError):
482
452
 
483
 
    _fmt = '"%(path)s" is not a directory %(extra)s'
 
453
    _fmt = "%(path)r is not a directory %(extra)s"
484
454
 
485
455
 
486
456
class NotInWorkingDirectory(PathError):
487
457
 
488
 
    _fmt = '"%(path)s" is not in the working directory %(extra)s'
 
458
    _fmt = "%(path)r is not in the working directory %(extra)s"
489
459
 
490
460
 
491
461
class DirectoryNotEmpty(PathError):
492
462
 
493
 
    _fmt = 'Directory not empty: "%(path)s"%(extra)s'
494
 
 
495
 
 
496
 
class HardLinkNotSupported(PathError):
497
 
 
498
 
    _fmt = 'Hard-linking "%(path)s" is not supported'
499
 
 
500
 
 
501
 
class ReadingCompleted(InternalBzrError):
502
 
 
 
463
    _fmt = "Directory not empty: %(path)r%(extra)s"
 
464
 
 
465
 
 
466
class ReadingCompleted(BzrError):
 
467
    
503
468
    _fmt = ("The MediumRequest '%(request)s' has already had finish_reading "
504
469
            "called upon it - the request has been completed and no more "
505
470
            "data may be read.")
506
471
 
 
472
    internal_error = True
 
473
 
507
474
    def __init__(self, request):
508
475
        self.request = request
509
476
 
510
477
 
511
478
class ResourceBusy(PathError):
512
479
 
513
 
    _fmt = 'Device or resource busy: "%(path)s"%(extra)s'
 
480
    _fmt = "Device or resource busy: %(path)r%(extra)s"
514
481
 
515
482
 
516
483
class PermissionDenied(PathError):
517
484
 
518
 
    _fmt = 'Permission denied: "%(path)s"%(extra)s'
 
485
    _fmt = "Permission denied: %(path)r%(extra)s"
519
486
 
520
487
 
521
488
class InvalidURL(PathError):
522
489
 
523
 
    _fmt = 'Invalid url supplied to transport: "%(path)s"%(extra)s'
 
490
    _fmt = "Invalid url supplied to transport: %(path)r%(extra)s"
524
491
 
525
492
 
526
493
class InvalidURLJoin(PathError):
527
494
 
528
 
    _fmt = "Invalid URL join request: %(reason)s: %(base)r + %(join_args)r"
529
 
 
530
 
    def __init__(self, reason, base, join_args):
531
 
        self.reason = reason
532
 
        self.base = base
533
 
        self.join_args = join_args
534
 
        PathError.__init__(self, base, reason)
535
 
 
536
 
 
537
 
class InvalidRebaseURLs(PathError):
538
 
 
539
 
    _fmt = "URLs differ by more than path: %(from_)r and %(to)r"
540
 
 
541
 
    def __init__(self, from_, to):
542
 
        self.from_ = from_
543
 
        self.to = to
544
 
        PathError.__init__(self, from_, 'URLs differ by more than path.')
545
 
 
546
 
 
547
 
class UnavailableRepresentation(InternalBzrError):
548
 
 
549
 
    _fmt = ("The encoding '%(wanted)s' is not available for key %(key)s which "
550
 
        "is encoded as '%(native)s'.")
551
 
 
552
 
    def __init__(self, key, wanted, native):
553
 
        InternalBzrError.__init__(self)
554
 
        self.wanted = wanted
555
 
        self.native = native
556
 
        self.key = key
 
495
    _fmt = "Invalid URL join request: %(args)s%(extra)s"
 
496
 
 
497
    def __init__(self, msg, base, args):
 
498
        PathError.__init__(self, base, msg)
 
499
        self.args = [base] + list(args)
557
500
 
558
501
 
559
502
class UnknownHook(BzrError):
570
513
 
571
514
    _fmt = 'Unsupported protocol for url "%(path)s"%(extra)s'
572
515
 
573
 
    def __init__(self, url, extra=""):
 
516
    def __init__(self, url, extra):
574
517
        PathError.__init__(self, url, extra=extra)
575
518
 
576
519
 
577
 
class UnstackableBranchFormat(BzrError):
578
 
 
579
 
    _fmt = ("The branch '%(url)s'(%(format)s) is not a stackable format. "
580
 
        "You will need to upgrade the branch to permit branch stacking.")
581
 
 
582
 
    def __init__(self, format, url):
583
 
        BzrError.__init__(self)
584
 
        self.format = format
585
 
        self.url = url
586
 
 
587
 
 
588
 
class UnstackableLocationError(BzrError):
589
 
 
590
 
    _fmt = "The branch '%(branch_url)s' cannot be stacked on '%(target_url)s'."
591
 
 
592
 
    def __init__(self, branch_url, target_url):
593
 
        BzrError.__init__(self)
594
 
        self.branch_url = branch_url
595
 
        self.target_url = target_url
596
 
 
597
 
 
598
 
class UnstackableRepositoryFormat(BzrError):
599
 
 
600
 
    _fmt = ("The repository '%(url)s'(%(format)s) is not a stackable format. "
601
 
        "You will need to upgrade the repository to permit branch stacking.")
602
 
 
603
 
    def __init__(self, format, url):
604
 
        BzrError.__init__(self)
605
 
        self.format = format
606
 
        self.url = url
607
 
 
608
 
 
609
520
class ReadError(PathError):
610
 
 
 
521
    
611
522
    _fmt = """Error reading from %(path)r."""
612
523
 
613
524
 
614
525
class ShortReadvError(PathError):
615
526
 
616
 
    _fmt = ('readv() read %(actual)s bytes rather than %(length)s bytes'
617
 
            ' at %(offset)s for "%(path)s"%(extra)s')
 
527
    _fmt = ("readv() read %(actual)s bytes rather than %(length)s bytes"
 
528
            " at %(offset)s for %(path)s%(extra)s")
618
529
 
619
530
    internal_error = True
620
531
 
625
536
        self.actual = actual
626
537
 
627
538
 
628
 
class PathNotChild(PathError):
629
 
 
630
 
    _fmt = 'Path "%(path)s" is not a child of path "%(base)s"%(extra)s'
631
 
 
632
 
    internal_error = False
 
539
class PathNotChild(BzrError):
 
540
 
 
541
    _fmt = "Path %(path)r is not a child of path %(base)r%(extra)s"
 
542
 
 
543
    internal_error = True
633
544
 
634
545
    def __init__(self, path, base, extra=None):
635
546
        BzrError.__init__(self)
643
554
 
644
555
class InvalidNormalization(PathError):
645
556
 
646
 
    _fmt = 'Path "%(path)s" is not unicode normalized'
 
557
    _fmt = "Path %(path)r is not unicode normalized"
647
558
 
648
559
 
649
560
# TODO: This is given a URL; we try to unescape it but doing that from inside
650
561
# the exception object is a bit undesirable.
651
 
# TODO: Probably this behavior of should be a common superclass
 
562
# TODO: Probably this behavior of should be a common superclass 
652
563
class NotBranchError(PathError):
653
564
 
654
 
    _fmt = 'Not a branch: "%(path)s"%(detail)s.'
 
565
    _fmt = "Not a branch: %(path)s"
655
566
 
656
 
    def __init__(self, path, detail=None, bzrdir=None):
 
567
    def __init__(self, path):
657
568
       import bzrlib.urlutils as urlutils
658
 
       path = urlutils.unescape_for_display(path, 'ascii')
659
 
       if detail is not None:
660
 
           detail = ': ' + detail
661
 
       self.detail = detail
662
 
       self.bzrdir = bzrdir
663
 
       PathError.__init__(self, path=path)
664
 
 
665
 
    def __repr__(self):
666
 
        return '<%s %r>' % (self.__class__.__name__, self.__dict__)
667
 
 
668
 
    def _format(self):
669
 
        # XXX: Ideally self.detail would be a property, but Exceptions in
670
 
        # Python 2.4 have to be old-style classes so properties don't work.
671
 
        # Instead we override _format.
672
 
        if self.detail is None:
673
 
            if self.bzrdir is not None:
674
 
                try:
675
 
                    self.bzrdir.open_repository()
676
 
                except NoRepositoryPresent:
677
 
                    self.detail = ''
678
 
                except Exception:
679
 
                    # Just ignore unexpected errors.  Raising arbitrary errors
680
 
                    # during str(err) can provoke strange bugs.  Concretely
681
 
                    # Launchpad's codehosting managed to raise NotBranchError
682
 
                    # here, and then get stuck in an infinite loop/recursion
683
 
                    # trying to str() that error.  All this error really cares
684
 
                    # about that there's no working repository there, and if
685
 
                    # open_repository() fails, there probably isn't.
686
 
                    self.detail = ''
687
 
                else:
688
 
                    self.detail = ': location is a repository'
689
 
            else:
690
 
                self.detail = ''
691
 
        return PathError._format(self)
 
569
       self.path = urlutils.unescape_for_display(path, 'ascii')
692
570
 
693
571
 
694
572
class NoSubmitBranch(PathError):
702
580
 
703
581
class AlreadyBranchError(PathError):
704
582
 
705
 
    _fmt = 'Already a branch: "%(path)s".'
 
583
    _fmt = "Already a branch: %(path)s."
706
584
 
707
585
 
708
586
class BranchExistsWithoutWorkingTree(PathError):
709
587
 
710
 
    _fmt = 'Directory contains a branch, but no working tree \
711
 
(use bzr checkout if you wish to build a working tree): "%(path)s"'
 
588
    _fmt = "Directory contains a branch, but no working tree \
 
589
(use bzr checkout if you wish to build a working tree): %(path)s"
712
590
 
713
591
 
714
592
class AtomicFileAlreadyClosed(PathError):
715
593
 
716
 
    _fmt = ('"%(function)s" called on an AtomicFile after it was closed:'
717
 
            ' "%(path)s"')
 
594
    _fmt = ("'%(function)s' called on an AtomicFile after it was closed:"
 
595
            " %(path)s")
718
596
 
719
597
    def __init__(self, path, function):
720
598
        PathError.__init__(self, path=path, extra=None)
723
601
 
724
602
class InaccessibleParent(PathError):
725
603
 
726
 
    _fmt = ('Parent not accessible given base "%(base)s" and'
727
 
            ' relative path "%(path)s"')
 
604
    _fmt = ("Parent not accessible given base %(base)s and"
 
605
            " relative path %(path)s")
728
606
 
729
607
    def __init__(self, path, base):
730
608
        PathError.__init__(self, path)
733
611
 
734
612
class NoRepositoryPresent(BzrError):
735
613
 
736
 
    _fmt = 'No repository present: "%(path)s"'
 
614
    _fmt = "No repository present: %(path)r"
737
615
    def __init__(self, bzrdir):
738
616
        BzrError.__init__(self)
739
617
        self.path = bzrdir.transport.clone('..').base
740
618
 
741
619
 
 
620
class FileInWrongBranch(BzrError):
 
621
 
 
622
    _fmt = "File %(path)s in not in branch %(branch_base)s."
 
623
 
 
624
    def __init__(self, branch, path):
 
625
        BzrError.__init__(self)
 
626
        self.branch = branch
 
627
        self.branch_base = branch.base
 
628
        self.path = path
 
629
 
 
630
 
742
631
class UnsupportedFormatError(BzrError):
743
632
 
744
633
    _fmt = "Unsupported branch format: %(format)s\nPlease run 'bzr upgrade'"
745
634
 
746
635
 
747
636
class UnknownFormatError(BzrError):
748
 
 
749
 
    _fmt = "Unknown %(kind)s format: %(format)r"
750
 
 
751
 
    def __init__(self, format, kind='branch'):
752
 
        self.kind = kind
753
 
        self.format = format
 
637
    
 
638
    _fmt = "Unknown branch format: %(format)r"
754
639
 
755
640
 
756
641
class IncompatibleFormat(BzrError):
757
 
 
 
642
    
758
643
    _fmt = "Format %(format)s is not compatible with .bzr version %(bzrdir)s."
759
644
 
760
645
    def __init__(self, format, bzrdir_format):
764
649
 
765
650
 
766
651
class IncompatibleRepositories(BzrError):
767
 
    """Report an error that two repositories are not compatible.
768
 
 
769
 
    Note that the source and target repositories are permitted to be strings:
770
 
    this exception is thrown from the smart server and may refer to a
771
 
    repository the client hasn't opened.
772
 
    """
773
 
 
774
 
    _fmt = "%(target)s\n" \
775
 
            "is not compatible with\n" \
776
 
            "%(source)s\n" \
777
 
            "%(details)s"
778
 
 
779
 
    def __init__(self, source, target, details=None):
780
 
        if details is None:
781
 
            details = "(no details)"
782
 
        BzrError.__init__(self, target=target, source=source, details=details)
 
652
 
 
653
    _fmt = "Repository %(target)s is not compatible with repository"\
 
654
        " %(source)s"
 
655
 
 
656
    def __init__(self, source, target):
 
657
        BzrError.__init__(self, target=target, source=source)
783
658
 
784
659
 
785
660
class IncompatibleRevision(BzrError):
786
 
 
 
661
    
787
662
    _fmt = "Revision is not compatible with %(repo_format)s"
788
663
 
789
664
    def __init__(self, repo_format):
794
669
class AlreadyVersionedError(BzrError):
795
670
    """Used when a path is expected not to be versioned, but it is."""
796
671
 
797
 
    _fmt = "%(context_info)s%(path)s is already versioned."
 
672
    _fmt = "%(context_info)s%(path)s is already versioned"
798
673
 
799
674
    def __init__(self, path, context_info=None):
800
675
        """Construct a new AlreadyVersionedError.
801
676
 
802
677
        :param path: This is the path which is versioned,
803
 
            which should be in a user friendly form.
 
678
        which should be in a user friendly form.
804
679
        :param context_info: If given, this is information about the context,
805
 
            which could explain why this is expected to not be versioned.
 
680
        which could explain why this is expected to not be versioned.
806
681
        """
807
682
        BzrError.__init__(self)
808
683
        self.path = path
815
690
class NotVersionedError(BzrError):
816
691
    """Used when a path is expected to be versioned, but it is not."""
817
692
 
818
 
    _fmt = "%(context_info)s%(path)s is not versioned."
 
693
    _fmt = "%(context_info)s%(path)s is not versioned"
819
694
 
820
695
    def __init__(self, path, context_info=None):
821
696
        """Construct a new NotVersionedError.
822
697
 
823
698
        :param path: This is the path which is not versioned,
824
 
            which should be in a user friendly form.
 
699
        which should be in a user friendly form.
825
700
        :param context_info: If given, this is information about the context,
826
 
            which could explain why this is expected to be versioned.
 
701
        which could explain why this is expected to be versioned.
827
702
        """
828
703
        BzrError.__init__(self)
829
704
        self.path = path
872
747
        BzrError.__init__(self, filename=filename, kind=kind)
873
748
 
874
749
 
875
 
class BadFilenameEncoding(BzrError):
876
 
 
877
 
    _fmt = ('Filename %(filename)r is not valid in your current filesystem'
878
 
            ' encoding %(fs_encoding)s')
879
 
 
880
 
    def __init__(self, filename, fs_encoding):
881
 
        BzrError.__init__(self)
882
 
        self.filename = filename
883
 
        self.fs_encoding = fs_encoding
884
 
 
885
 
 
886
750
class ForbiddenControlFileError(BzrError):
887
751
 
888
 
    _fmt = 'Cannot operate on "%(filename)s" because it is a control file'
889
 
 
890
 
 
891
 
class LockError(InternalBzrError):
 
752
    _fmt = "Cannot operate on %(filename)s because it is a control file"
 
753
 
 
754
 
 
755
class LockError(BzrError):
892
756
 
893
757
    _fmt = "Lock error: %(msg)s"
894
758
 
 
759
    internal_error = True
 
760
 
895
761
    # All exceptions from the lock/unlock functions should be from
896
762
    # this exception class.  They will be translated as necessary. The
897
763
    # original exception is available as e.original_error
898
764
    #
899
765
    # New code should prefer to raise specific subclasses
900
 
    def __init__(self, msg):
901
 
        self.msg = msg
 
766
    def __init__(self, message):
 
767
        # Python 2.5 uses a slot for StandardError.message,
 
768
        # so use a different variable name
 
769
        # so it is exposed in self.__dict__
 
770
        self.msg = message
902
771
 
903
772
 
904
773
class LockActive(LockError):
938
807
        self.obj = obj
939
808
 
940
809
 
941
 
class LockFailed(LockError):
942
 
 
943
 
    internal_error = False
944
 
 
945
 
    _fmt = "Cannot lock %(lock)s: %(why)s"
946
 
 
947
 
    def __init__(self, lock, why):
 
810
class ReadOnlyLockError(LockError):
 
811
 
 
812
    _fmt = "Cannot acquire write lock on %(fname)s. %(msg)s"
 
813
 
 
814
    def __init__(self, fname, msg):
948
815
        LockError.__init__(self, '')
949
 
        self.lock = lock
950
 
        self.why = why
 
816
        self.fname = fname
 
817
        self.msg = msg
951
818
 
952
819
 
953
820
class OutSideTransaction(BzrError):
977
844
 
978
845
class UnlockableTransport(LockError):
979
846
 
980
 
    internal_error = False
981
 
 
982
847
    _fmt = "Cannot lock: transport is read only: %(transport)s"
983
848
 
984
849
    def __init__(self, transport):
987
852
 
988
853
class LockContention(LockError):
989
854
 
990
 
    _fmt = 'Could not acquire lock "%(lock)s": %(msg)s'
 
855
    _fmt = "Could not acquire lock %(lock)s"
 
856
    # TODO: show full url for lock, combining the transport and relative
 
857
    # bits?
991
858
 
992
859
    internal_error = False
993
860
 
994
 
    def __init__(self, lock, msg=''):
 
861
    def __init__(self, lock):
995
862
        self.lock = lock
996
 
        self.msg = msg
997
863
 
998
864
 
999
865
class LockBroken(LockError):
1020
886
        self.target = target
1021
887
 
1022
888
 
1023
 
class LockCorrupt(LockError):
1024
 
 
1025
 
    _fmt = ("Lock is apparently held, but corrupted: %(corruption_info)s\n"
1026
 
            "Use 'bzr break-lock' to clear it")
1027
 
 
1028
 
    internal_error = False
1029
 
 
1030
 
    def __init__(self, corruption_info, file_data=None):
1031
 
        self.corruption_info = corruption_info
1032
 
        self.file_data = file_data
1033
 
 
1034
 
 
1035
889
class LockNotHeld(LockError):
1036
890
 
1037
891
    _fmt = "Lock not held: %(lock)s"
1046
900
 
1047
901
    _fmt = "The object %(obj)s does not support token specifying a token when locking."
1048
902
 
 
903
    internal_error = True
 
904
 
1049
905
    def __init__(self, obj):
1050
906
        self.obj = obj
1051
907
 
1076
932
        BzrError.__init__(self, files=files, files_str=files_str)
1077
933
 
1078
934
 
1079
 
class ExcludesUnsupported(BzrError):
1080
 
 
1081
 
    _fmt = ('Excluding paths during commit is not supported by '
1082
 
            'repository at %(repository)r.')
1083
 
 
1084
 
    def __init__(self, repository):
1085
 
        BzrError.__init__(self, repository=repository)
1086
 
 
1087
 
 
1088
 
class BadCommitMessageEncoding(BzrError):
1089
 
 
1090
 
    _fmt = 'The specified commit message contains characters unsupported by '\
1091
 
        'the current encoding.'
1092
 
 
1093
 
 
1094
935
class UpgradeReadonly(BzrError):
1095
936
 
1096
937
    _fmt = "Upgrade URL cannot work with readonly URLs."
1110
951
    _fmt = "Commit refused because there are unknowns in the tree."
1111
952
 
1112
953
 
1113
 
class NoSuchRevision(InternalBzrError):
1114
 
 
1115
 
    _fmt = "%(branch)s has no revision %(revision)s"
 
954
class NoSuchRevision(BzrError):
 
955
 
 
956
    _fmt = "Branch %(branch)s has no revision %(revision)s"
 
957
 
 
958
    internal_error = True
1116
959
 
1117
960
    def __init__(self, branch, revision):
1118
 
        # 'branch' may sometimes be an internal object like a KnitRevisionStore
1119
961
        BzrError.__init__(self, branch=branch, revision=revision)
1120
962
 
1121
963
 
1122
 
class RangeInChangeOption(BzrError):
1123
 
 
1124
 
    _fmt = "Option --change does not accept revision ranges"
 
964
class NotLeftParentDescendant(BzrError):
 
965
 
 
966
    _fmt = ("Revision %(old_revision)s is not the left parent of"
 
967
            " %(new_revision)s, but branch %(branch_location)s expects this")
 
968
 
 
969
    internal_error = True
 
970
 
 
971
    def __init__(self, branch, old_revision, new_revision):
 
972
        BzrError.__init__(self, branch_location=branch.base,
 
973
                          old_revision=old_revision,
 
974
                          new_revision=new_revision)
1125
975
 
1126
976
 
1127
977
class NoSuchRevisionSpec(BzrError):
1134
984
 
1135
985
class NoSuchRevisionInTree(NoSuchRevision):
1136
986
    """When using Tree.revision_tree, and the revision is not accessible."""
1137
 
 
1138
 
    _fmt = "The revision id {%(revision_id)s} is not present in the tree %(tree)s."
 
987
    
 
988
    _fmt = "The revision id %(revision_id)s is not present in the tree %(tree)s."
1139
989
 
1140
990
    def __init__(self, tree, revision_id):
1141
991
        BzrError.__init__(self)
1145
995
 
1146
996
class InvalidRevisionSpec(BzrError):
1147
997
 
1148
 
    _fmt = ("Requested revision: '%(spec)s' does not exist in branch:"
1149
 
            " %(branch_url)s%(extra)s")
 
998
    _fmt = ("Requested revision: %(spec)r does not exist in branch:"
 
999
            " %(branch)s%(extra)s")
1150
1000
 
1151
1001
    def __init__(self, spec, branch, extra=None):
1152
1002
        BzrError.__init__(self, branch=branch, spec=spec)
1153
 
        self.branch_url = getattr(branch, 'user_url', str(branch))
1154
1003
        if extra:
1155
1004
            self.extra = '\n' + str(extra)
1156
1005
        else:
1157
1006
            self.extra = ''
1158
1007
 
1159
1008
 
 
1009
class HistoryMissing(BzrError):
 
1010
 
 
1011
    _fmt = "%(branch)s is missing %(object_type)s {%(object_id)s}"
 
1012
 
 
1013
 
1160
1014
class AppendRevisionsOnlyViolation(BzrError):
1161
1015
 
1162
1016
    _fmt = ('Operation denied because it would change the main history,'
1172
1026
class DivergedBranches(BzrError):
1173
1027
 
1174
1028
    _fmt = ("These branches have diverged."
1175
 
            " Use the missing command to see how.\n"
1176
 
            "Use the merge command to reconcile them.")
 
1029
            " Use the merge command to reconcile them.")
 
1030
 
 
1031
    internal_error = False
1177
1032
 
1178
1033
    def __init__(self, branch1, branch2):
1179
1034
        self.branch1 = branch1
1180
1035
        self.branch2 = branch2
1181
1036
 
1182
1037
 
1183
 
class NotLefthandHistory(InternalBzrError):
 
1038
class NotLefthandHistory(BzrError):
1184
1039
 
1185
1040
    _fmt = "Supplied history does not follow left-hand parents"
1186
1041
 
 
1042
    internal_error = True
 
1043
 
1187
1044
    def __init__(self, history):
1188
1045
        BzrError.__init__(self, history=history)
1189
1046
 
1193
1050
    _fmt = ("Branches have no common ancestor, and"
1194
1051
            " no merge base revision was specified.")
1195
1052
 
1196
 
 
1197
 
class CannotReverseCherrypick(BzrError):
1198
 
 
1199
 
    _fmt = ('Selected merge cannot perform reverse cherrypicks.  Try merge3'
1200
 
            ' or diff3.')
 
1053
    internal_error = False
1201
1054
 
1202
1055
 
1203
1056
class NoCommonAncestor(BzrError):
1204
 
 
 
1057
    
1205
1058
    _fmt = "Revisions have no common ancestor: %(revision_a)s %(revision_b)s"
1206
1059
 
1207
1060
    def __init__(self, revision_a, revision_b):
1227
1080
            not_ancestor_id=not_ancestor_id)
1228
1081
 
1229
1082
 
1230
 
class NoCommits(BranchError):
 
1083
class InstallFailed(BzrError):
 
1084
 
 
1085
    def __init__(self, revisions):
 
1086
        revision_str = ", ".join(str(r) for r in revisions)
 
1087
        msg = "Could not install revisions:\n%s" % revision_str
 
1088
        BzrError.__init__(self, msg)
 
1089
        self.revisions = revisions
 
1090
 
 
1091
 
 
1092
class AmbiguousBase(BzrError):
 
1093
 
 
1094
    def __init__(self, bases):
 
1095
        warn("BzrError AmbiguousBase has been deprecated as of bzrlib 0.8.",
 
1096
                DeprecationWarning)
 
1097
        msg = ("The correct base is unclear, because %s are all equally close"
 
1098
                % ", ".join(bases))
 
1099
        BzrError.__init__(self, msg)
 
1100
        self.bases = bases
 
1101
 
 
1102
 
 
1103
class NoCommits(BzrError):
1231
1104
 
1232
1105
    _fmt = "Branch %(branch)s has no commits."
1233
1106
 
 
1107
    def __init__(self, branch):
 
1108
        BzrError.__init__(self, branch=branch)
 
1109
 
1234
1110
 
1235
1111
class UnlistableStore(BzrError):
1236
1112
 
1247
1123
 
1248
1124
class BoundBranchOutOfDate(BzrError):
1249
1125
 
1250
 
    _fmt = ("Bound branch %(branch)s is out of date with master branch"
1251
 
            " %(master)s.%(extra_help)s")
 
1126
    _fmt = ("Bound branch %(branch)s is out of date"
 
1127
            " with master branch %(master)s.")
1252
1128
 
1253
1129
    def __init__(self, branch, master):
1254
1130
        BzrError.__init__(self)
1255
1131
        self.branch = branch
1256
1132
        self.master = master
1257
 
        self.extra_help = ''
1258
 
 
1259
 
 
 
1133
 
 
1134
        
1260
1135
class CommitToDoubleBoundBranch(BzrError):
1261
1136
 
1262
1137
    _fmt = ("Cannot commit to branch %(branch)s."
1292
1167
 
1293
1168
class WeaveError(BzrError):
1294
1169
 
1295
 
    _fmt = "Error in processing weave: %(msg)s"
 
1170
    _fmt = "Error in processing weave: %(message)s"
1296
1171
 
1297
 
    def __init__(self, msg=None):
 
1172
    def __init__(self, message=None):
1298
1173
        BzrError.__init__(self)
1299
 
        self.msg = msg
 
1174
        self.message = message
1300
1175
 
1301
1176
 
1302
1177
class WeaveRevisionAlreadyPresent(WeaveError):
1331
1206
 
1332
1207
class WeaveParentMismatch(WeaveError):
1333
1208
 
1334
 
    _fmt = "Parents are mismatched between two revisions. %(msg)s"
1335
 
 
 
1209
    _fmt = "Parents are mismatched between two revisions."
 
1210
    
1336
1211
 
1337
1212
class WeaveInvalidChecksum(WeaveError):
1338
1213
 
1339
 
    _fmt = "Text did not match its checksum: %(msg)s"
 
1214
    _fmt = "Text did not match it's checksum: %(message)s"
1340
1215
 
1341
1216
 
1342
1217
class WeaveTextDiffers(WeaveError):
1364
1239
 
1365
1240
 
1366
1241
class VersionedFileError(BzrError):
1367
 
 
 
1242
    
1368
1243
    _fmt = "Versioned file error"
1369
1244
 
1370
1245
 
1371
1246
class RevisionNotPresent(VersionedFileError):
1372
 
 
1373
 
    _fmt = 'Revision {%(revision_id)s} not present in "%(file_id)s".'
 
1247
    
 
1248
    _fmt = "Revision {%(revision_id)s} not present in %(file_id)s."
1374
1249
 
1375
1250
    def __init__(self, revision_id, file_id):
1376
1251
        VersionedFileError.__init__(self)
1379
1254
 
1380
1255
 
1381
1256
class RevisionAlreadyPresent(VersionedFileError):
1382
 
 
1383
 
    _fmt = 'Revision {%(revision_id)s} already present in "%(file_id)s".'
 
1257
    
 
1258
    _fmt = "Revision {%(revision_id)s} already present in %(file_id)s."
1384
1259
 
1385
1260
    def __init__(self, revision_id, file_id):
1386
1261
        VersionedFileError.__init__(self)
1390
1265
 
1391
1266
class VersionedFileInvalidChecksum(VersionedFileError):
1392
1267
 
1393
 
    _fmt = "Text did not match its checksum: %(msg)s"
1394
 
 
1395
 
 
1396
 
class KnitError(InternalBzrError):
1397
 
 
 
1268
    _fmt = "Text did not match its checksum: %(message)s"
 
1269
 
 
1270
 
 
1271
class KnitError(BzrError):
 
1272
    
1398
1273
    _fmt = "Knit error"
1399
1274
 
 
1275
    internal_error = True
 
1276
 
 
1277
 
 
1278
class KnitHeaderError(KnitError):
 
1279
 
 
1280
    _fmt = "Knit header error: %(badline)r unexpected for file %(filename)s"
 
1281
 
 
1282
    def __init__(self, badline, filename):
 
1283
        KnitError.__init__(self)
 
1284
        self.badline = badline
 
1285
        self.filename = filename
 
1286
 
1400
1287
 
1401
1288
class KnitCorrupt(KnitError):
1402
1289
 
1408
1295
        self.how = how
1409
1296
 
1410
1297
 
1411
 
class SHA1KnitCorrupt(KnitCorrupt):
1412
 
 
1413
 
    _fmt = ("Knit %(filename)s corrupt: sha-1 of reconstructed text does not "
1414
 
        "match expected sha-1. key %(key)s expected sha %(expected)s actual "
1415
 
        "sha %(actual)s")
1416
 
 
1417
 
    def __init__(self, filename, actual, expected, key, content):
1418
 
        KnitError.__init__(self)
1419
 
        self.filename = filename
1420
 
        self.actual = actual
1421
 
        self.expected = expected
1422
 
        self.key = key
1423
 
        self.content = content
1424
 
 
1425
 
 
1426
 
class KnitDataStreamIncompatible(KnitError):
1427
 
    # Not raised anymore, as we can convert data streams.  In future we may
1428
 
    # need it again for more exotic cases, so we're keeping it around for now.
1429
 
 
1430
 
    _fmt = "Cannot insert knit data stream of format \"%(stream_format)s\" into knit of format \"%(target_format)s\"."
1431
 
 
1432
 
    def __init__(self, stream_format, target_format):
1433
 
        self.stream_format = stream_format
1434
 
        self.target_format = target_format
1435
 
 
1436
 
 
1437
 
class KnitDataStreamUnknown(KnitError):
1438
 
    # Indicates a data stream we don't know how to handle.
1439
 
 
1440
 
    _fmt = "Cannot parse knit data stream of format \"%(stream_format)s\"."
1441
 
 
1442
 
    def __init__(self, stream_format):
1443
 
        self.stream_format = stream_format
1444
 
 
1445
 
 
1446
 
class KnitHeaderError(KnitError):
1447
 
 
1448
 
    _fmt = 'Knit header error: %(badline)r unexpected for file "%(filename)s".'
1449
 
 
1450
 
    def __init__(self, badline, filename):
1451
 
        KnitError.__init__(self)
1452
 
        self.badline = badline
1453
 
        self.filename = filename
1454
 
 
1455
1298
class KnitIndexUnknownMethod(KnitError):
1456
1299
    """Raised when we don't understand the storage method.
1457
1300
 
1458
1301
    Currently only 'fulltext' and 'line-delta' are supported.
1459
1302
    """
1460
 
 
 
1303
    
1461
1304
    _fmt = ("Knit index %(filename)s does not have a known method"
1462
1305
            " in options: %(options)r")
1463
1306
 
1467
1310
        self.options = options
1468
1311
 
1469
1312
 
1470
 
class RetryWithNewPacks(BzrError):
1471
 
    """Raised when we realize that the packs on disk have changed.
1472
 
 
1473
 
    This is meant as more of a signaling exception, to trap between where a
1474
 
    local error occurred and the code that can actually handle the error and
1475
 
    code that can retry appropriately.
1476
 
    """
1477
 
 
1478
 
    internal_error = True
1479
 
 
1480
 
    _fmt = ("Pack files have changed, reload and retry. context: %(context)s"
1481
 
            " %(orig_error)s")
1482
 
 
1483
 
    def __init__(self, context, reload_occurred, exc_info):
1484
 
        """create a new RetryWithNewPacks error.
1485
 
 
1486
 
        :param reload_occurred: Set to True if we know that the packs have
1487
 
            already been reloaded, and we are failing because of an in-memory
1488
 
            cache miss. If set to True then we will ignore if a reload says
1489
 
            nothing has changed, because we assume it has already reloaded. If
1490
 
            False, then a reload with nothing changed will force an error.
1491
 
        :param exc_info: The original exception traceback, so if there is a
1492
 
            problem we can raise the original error (value from sys.exc_info())
1493
 
        """
1494
 
        BzrError.__init__(self)
1495
 
        self.context = context
1496
 
        self.reload_occurred = reload_occurred
1497
 
        self.exc_info = exc_info
1498
 
        self.orig_error = exc_info[1]
1499
 
        # TODO: The global error handler should probably treat this by
1500
 
        #       raising/printing the original exception with a bit about
1501
 
        #       RetryWithNewPacks also not being caught
1502
 
 
1503
 
 
1504
 
class RetryAutopack(RetryWithNewPacks):
1505
 
    """Raised when we are autopacking and we find a missing file.
1506
 
 
1507
 
    Meant as a signaling exception, to tell the autopack code it should try
1508
 
    again.
1509
 
    """
1510
 
 
1511
 
    internal_error = True
1512
 
 
1513
 
    _fmt = ("Pack files have changed, reload and try autopack again."
1514
 
            " context: %(context)s %(orig_error)s")
1515
 
 
1516
 
 
1517
1313
class NoSuchExportFormat(BzrError):
1518
 
 
 
1314
    
1519
1315
    _fmt = "Export format %(format)r not supported"
1520
1316
 
1521
1317
    def __init__(self, format):
1524
1320
 
1525
1321
 
1526
1322
class TransportError(BzrError):
1527
 
 
 
1323
    
1528
1324
    _fmt = "Transport error: %(msg)s %(orig_error)s"
1529
1325
 
1530
1326
    def __init__(self, msg=None, orig_error=None):
1539
1335
        BzrError.__init__(self)
1540
1336
 
1541
1337
 
1542
 
class TooManyConcurrentRequests(InternalBzrError):
 
1338
class TooManyConcurrentRequests(BzrError):
1543
1339
 
1544
1340
    _fmt = ("The medium '%(medium)s' has reached its concurrent request limit."
1545
1341
            " Be sure to finish_writing and finish_reading on the"
1546
1342
            " currently open request.")
1547
1343
 
 
1344
    internal_error = True
 
1345
 
1548
1346
    def __init__(self, medium):
1549
1347
        self.medium = medium
1550
1348
 
1557
1355
        self.details = details
1558
1356
 
1559
1357
 
1560
 
class UnexpectedProtocolVersionMarker(TransportError):
1561
 
 
1562
 
    _fmt = "Received bad protocol version marker: %(marker)r"
1563
 
 
1564
 
    def __init__(self, marker):
1565
 
        self.marker = marker
1566
 
 
1567
 
 
1568
 
class UnknownSmartMethod(InternalBzrError):
1569
 
 
1570
 
    _fmt = "The server does not recognise the '%(verb)s' request."
1571
 
 
1572
 
    def __init__(self, verb):
1573
 
        self.verb = verb
1574
 
 
1575
 
 
1576
 
class SmartMessageHandlerError(InternalBzrError):
1577
 
 
1578
 
    _fmt = ("The message handler raised an exception:\n"
1579
 
            "%(traceback_text)s")
1580
 
 
1581
 
    def __init__(self, exc_info):
1582
 
        import traceback
1583
 
        # GZ 2010-08-10: Cycle with exc_tb/exc_info affects at least one test
1584
 
        self.exc_type, self.exc_value, self.exc_tb = exc_info
1585
 
        self.exc_info = exc_info
1586
 
        traceback_strings = traceback.format_exception(
1587
 
                self.exc_type, self.exc_value, self.exc_tb)
1588
 
        self.traceback_text = ''.join(traceback_strings)
1589
 
 
1590
 
 
1591
1358
# A set of semi-meaningful errors which can be thrown
1592
1359
class TransportNotPossible(TransportError):
1593
1360
 
1618
1385
            self.port = ':%s' % port
1619
1386
 
1620
1387
 
1621
 
# XXX: This is also used for unexpected end of file, which is different at the
1622
 
# TCP level from "connection reset".
1623
1388
class ConnectionReset(TransportError):
1624
1389
 
1625
1390
    _fmt = "Connection closed: %(msg)s %(orig_error)s"
1626
1391
 
1627
1392
 
1628
 
class ConnectionTimeout(ConnectionError):
1629
 
 
1630
 
    _fmt = "Connection Timeout: %(msg)s%(orig_error)s"
1631
 
 
1632
 
 
1633
1393
class InvalidRange(TransportError):
1634
1394
 
1635
 
    _fmt = "Invalid range access in %(path)s at %(offset)s: %(msg)s"
1636
 
 
1637
 
    def __init__(self, path, offset, msg=None):
1638
 
        TransportError.__init__(self, msg)
 
1395
    _fmt = "Invalid range access in %(path)s at %(offset)s."
 
1396
    
 
1397
    def __init__(self, path, offset):
 
1398
        TransportError.__init__(self, ("Invalid range access in %s at %d"
 
1399
                                       % (path, offset)))
1639
1400
        self.path = path
1640
1401
        self.offset = offset
1641
1402
 
1642
1403
 
1643
1404
class InvalidHttpResponse(TransportError):
1644
1405
 
1645
 
    _fmt = "Invalid http response for %(path)s: %(msg)s%(orig_error)s"
 
1406
    _fmt = "Invalid http response for %(path)s: %(msg)s"
1646
1407
 
1647
1408
    def __init__(self, path, msg, orig_error=None):
1648
1409
        self.path = path
1649
 
        if orig_error is None:
1650
 
            orig_error = ''
1651
 
        else:
1652
 
            # This is reached for obscure and unusual errors so we want to
1653
 
            # preserve as much info as possible to ease debug.
1654
 
            orig_error = ': %r' % (orig_error,)
1655
1410
        TransportError.__init__(self, msg, orig_error=orig_error)
1656
1411
 
1657
1412
 
1658
1413
class InvalidHttpRange(InvalidHttpResponse):
1659
1414
 
1660
1415
    _fmt = "Invalid http range %(range)r for %(path)s: %(msg)s"
1661
 
 
 
1416
    
1662
1417
    def __init__(self, path, range, msg):
1663
1418
        self.range = range
1664
1419
        InvalidHttpResponse.__init__(self, path, msg)
1665
1420
 
1666
1421
 
1667
 
class HttpBoundaryMissing(InvalidHttpResponse):
1668
 
    """A multipart response ends with no boundary marker.
1669
 
 
1670
 
    This is a special case caused by buggy proxies, described in
1671
 
    <https://bugs.launchpad.net/bzr/+bug/198646>.
1672
 
    """
1673
 
 
1674
 
    _fmt = "HTTP MIME Boundary missing for %(path)s: %(msg)s"
1675
 
 
1676
 
    def __init__(self, path, msg):
1677
 
        InvalidHttpResponse.__init__(self, path, msg)
1678
 
 
1679
 
 
1680
1422
class InvalidHttpContentType(InvalidHttpResponse):
1681
1423
 
1682
1424
    _fmt = 'Invalid http Content-type "%(ctype)s" for %(path)s: %(msg)s'
1683
 
 
 
1425
    
1684
1426
    def __init__(self, path, ctype, msg):
1685
1427
        self.ctype = ctype
1686
1428
        InvalidHttpResponse.__init__(self, path, msg)
1690
1432
 
1691
1433
    _fmt = '%(source)s is%(permanently)s redirected to %(target)s'
1692
1434
 
1693
 
    def __init__(self, source, target, is_permanent=False):
 
1435
    def __init__(self, source, target, is_permament=False, qual_proto=None):
1694
1436
        self.source = source
1695
1437
        self.target = target
1696
 
        if is_permanent:
 
1438
        if is_permament:
1697
1439
            self.permanently = ' permanently'
1698
1440
        else:
1699
1441
            self.permanently = ''
 
1442
        self.is_permament = is_permament
 
1443
        self._qualified_proto = qual_proto
1700
1444
        TransportError.__init__(self)
1701
1445
 
 
1446
    def _requalify_url(self, url):
 
1447
        """Restore the qualified proto in front of the url"""
 
1448
        # When this exception is raised, source and target are in
 
1449
        # user readable format. But some transports may use a
 
1450
        # different proto (http+urllib:// will present http:// to
 
1451
        # the user. If a qualified proto is specified, the code
 
1452
        # trapping the exception can get the qualified urls to
 
1453
        # properly handle the redirection themself (creating a
 
1454
        # new transport object from the target url for example).
 
1455
        # But checking that the scheme of the original and
 
1456
        # redirected urls are the same can be tricky. (see the
 
1457
        # FIXME in BzrDir.open_from_transport for the unique use
 
1458
        # case so far).
 
1459
        if self._qualified_proto is None:
 
1460
            return url
 
1461
 
 
1462
        # The TODO related to NotBranchError mention that doing
 
1463
        # that kind of manipulation on the urls may not be the
 
1464
        # exception object job. On the other hand, this object is
 
1465
        # the interface between the code and the user so
 
1466
        # presenting the urls in different ways is indeed its
 
1467
        # job...
 
1468
        import urlparse
 
1469
        proto, netloc, path, query, fragment = urlparse.urlsplit(url)
 
1470
        return urlparse.urlunsplit((self._qualified_proto, netloc, path,
 
1471
                                   query, fragment))
 
1472
 
 
1473
    def get_source_url(self):
 
1474
        return self._requalify_url(self.source)
 
1475
 
 
1476
    def get_target_url(self):
 
1477
        return self._requalify_url(self.target)
 
1478
 
1702
1479
 
1703
1480
class TooManyRedirections(TransportError):
1704
1481
 
1705
1482
    _fmt = "Too many redirections"
1706
1483
 
1707
 
 
1708
1484
class ConflictsInTree(BzrError):
1709
1485
 
1710
1486
    _fmt = "Working tree has conflicts."
1711
1487
 
1712
1488
 
1713
 
class ConfigContentError(BzrError):
1714
 
 
1715
 
    _fmt = "Config file %(filename)s is not UTF-8 encoded\n"
1716
 
 
1717
 
    def __init__(self, filename):
1718
 
        BzrError.__init__(self)
1719
 
        self.filename = filename
1720
 
 
1721
 
 
1722
1489
class ParseConfigError(BzrError):
1723
1490
 
1724
 
    _fmt = "Error(s) parsing config file %(filename)s:\n%(errors)s"
1725
 
 
1726
1491
    def __init__(self, errors, filename):
1727
 
        BzrError.__init__(self)
1728
 
        self.filename = filename
1729
 
        self.errors = '\n'.join(e.msg for e in errors)
1730
 
 
1731
 
 
1732
 
class ConfigOptionValueError(BzrError):
1733
 
 
1734
 
    _fmt = """Bad value "%(value)s" for option "%(name)s"."""
1735
 
 
1736
 
    def __init__(self, name, value):
1737
 
        BzrError.__init__(self, name=name, value=value)
 
1492
        if filename is None:
 
1493
            filename = ""
 
1494
        message = "Error(s) parsing config file %s:\n%s" % \
 
1495
            (filename, ('\n'.join(e.message for e in errors)))
 
1496
        BzrError.__init__(self, message)
1738
1497
 
1739
1498
 
1740
1499
class NoEmailInUsername(BzrError):
1748
1507
 
1749
1508
class SigningFailed(BzrError):
1750
1509
 
1751
 
    _fmt = 'Failed to GPG sign data with command "%(command_line)s"'
 
1510
    _fmt = "Failed to gpg sign data with command %(command_line)r"
1752
1511
 
1753
1512
    def __init__(self, command_line):
1754
1513
        BzrError.__init__(self, command_line=command_line)
1755
1514
 
1756
1515
 
1757
 
class SignatureVerificationFailed(BzrError):
1758
 
 
1759
 
    _fmt = 'Failed to verify GPG signature data with error "%(error)s"'
1760
 
 
1761
 
    def __init__(self, error):
1762
 
        BzrError.__init__(self, error=error)
1763
 
 
1764
 
 
1765
 
class DependencyNotPresent(BzrError):
1766
 
 
1767
 
    _fmt = 'Unable to import library "%(library)s": %(error)s'
1768
 
 
1769
 
    def __init__(self, library, error):
1770
 
        BzrError.__init__(self, library=library, error=error)
1771
 
 
1772
 
 
1773
 
class GpgmeNotInstalled(DependencyNotPresent):
1774
 
 
1775
 
    _fmt = 'python-gpgme is not installed, it is needed to verify signatures'
1776
 
 
1777
 
    def __init__(self, error):
1778
 
        DependencyNotPresent.__init__(self, 'gpgme', error)
1779
 
 
1780
 
 
1781
1516
class WorkingTreeNotRevision(BzrError):
1782
1517
 
1783
 
    _fmt = ("The working tree for %(basedir)s has changed since"
 
1518
    _fmt = ("The working tree for %(basedir)s has changed since" 
1784
1519
            " the last commit, but weave merge requires that it be"
1785
1520
            " unchanged")
1786
1521
 
1803
1538
        self.graph = graph
1804
1539
 
1805
1540
 
1806
 
class WritingCompleted(InternalBzrError):
 
1541
class WritingCompleted(BzrError):
1807
1542
 
1808
1543
    _fmt = ("The MediumRequest '%(request)s' has already had finish_writing "
1809
1544
            "called upon it - accept bytes may not be called anymore.")
1810
1545
 
 
1546
    internal_error = True
 
1547
 
1811
1548
    def __init__(self, request):
1812
1549
        self.request = request
1813
1550
 
1814
1551
 
1815
 
class WritingNotComplete(InternalBzrError):
 
1552
class WritingNotComplete(BzrError):
1816
1553
 
1817
1554
    _fmt = ("The MediumRequest '%(request)s' has not has finish_writing "
1818
1555
            "called upon it - until the write phase is complete no "
1819
1556
            "data may be read.")
1820
1557
 
 
1558
    internal_error = True
 
1559
 
1821
1560
    def __init__(self, request):
1822
1561
        self.request = request
1823
1562
 
1831
1570
        self.filename = filename
1832
1571
 
1833
1572
 
1834
 
class MediumNotConnected(InternalBzrError):
 
1573
class MediumNotConnected(BzrError):
1835
1574
 
1836
1575
    _fmt = """The medium '%(medium)s' is not connected."""
1837
1576
 
 
1577
    internal_error = True
 
1578
 
1838
1579
    def __init__(self, medium):
1839
1580
        self.medium = medium
1840
1581
 
1846
1587
 
1847
1588
class NoBundleFound(BzrError):
1848
1589
 
1849
 
    _fmt = 'No bundle was found in "%(filename)s".'
 
1590
    _fmt = "No bundle was found in %(filename)s"
1850
1591
 
1851
1592
    def __init__(self, filename):
1852
1593
        BzrError.__init__(self)
1875
1616
        self.text_revision = text_revision
1876
1617
        self.file_id = file_id
1877
1618
 
1878
 
 
1879
1619
class DuplicateFileId(BzrError):
1880
1620
 
1881
1621
    _fmt = "File id {%(file_id)s} already exists in inventory as %(entry)s"
1899
1639
        self.prefix = prefix
1900
1640
 
1901
1641
 
1902
 
class MalformedTransform(InternalBzrError):
 
1642
class MalformedTransform(BzrError):
1903
1643
 
1904
1644
    _fmt = "Tree transform is malformed %(conflicts)r"
1905
1645
 
1916
1656
        self.root_trans_id = transform.root
1917
1657
 
1918
1658
 
1919
 
class BzrBadParameter(InternalBzrError):
 
1659
class BzrBadParameter(BzrError):
1920
1660
 
1921
1661
    _fmt = "Bad parameter: %(param)r"
1922
1662
 
 
1663
    internal_error = True
 
1664
 
1923
1665
    # This exception should never be thrown, but it is a base class for all
1924
1666
    # parameter-to-function errors.
1925
1667
 
1943
1685
    _fmt = "Moving the root directory is not supported at this time"
1944
1686
 
1945
1687
 
1946
 
class TransformRenameFailed(BzrError):
1947
 
 
1948
 
    _fmt = "Failed to rename %(from_path)s to %(to_path)s: %(why)s"
1949
 
 
1950
 
    def __init__(self, from_path, to_path, why, errno):
1951
 
        self.from_path = from_path
1952
 
        self.to_path = to_path
1953
 
        self.why = why
1954
 
        self.errno = errno
1955
 
 
1956
 
 
1957
1688
class BzrMoveFailedError(BzrError):
1958
1689
 
1959
 
    _fmt = ("Could not move %(from_path)s%(operator)s %(to_path)s"
1960
 
        "%(_has_extra)s%(extra)s")
 
1690
    _fmt = "Could not move %(from_path)s%(operator)s %(to_path)s%(extra)s"
1961
1691
 
1962
1692
    def __init__(self, from_path='', to_path='', extra=None):
1963
 
        from bzrlib.osutils import splitpath
1964
1693
        BzrError.__init__(self)
1965
1694
        if extra:
1966
 
            self.extra, self._has_extra = extra, ': '
 
1695
            self.extra = ': ' + str(extra)
1967
1696
        else:
1968
 
            self.extra = self._has_extra = ''
 
1697
            self.extra = ''
1969
1698
 
1970
1699
        has_from = len(from_path) > 0
1971
1700
        has_to = len(to_path) > 0
1972
1701
        if has_from:
1973
 
            self.from_path = splitpath(from_path)[-1]
 
1702
            self.from_path = osutils.splitpath(from_path)[-1]
1974
1703
        else:
1975
1704
            self.from_path = ''
1976
1705
 
1977
1706
        if has_to:
1978
 
            self.to_path = splitpath(to_path)[-1]
 
1707
            self.to_path = osutils.splitpath(to_path)[-1]
1979
1708
        else:
1980
1709
            self.to_path = ''
1981
1710
 
1992
1721
 
1993
1722
class BzrRenameFailedError(BzrMoveFailedError):
1994
1723
 
1995
 
    _fmt = ("Could not rename %(from_path)s%(operator)s %(to_path)s"
1996
 
        "%(_has_extra)s%(extra)s")
 
1724
    _fmt = "Could not rename %(from_path)s%(operator)s %(to_path)s%(extra)s"
1997
1725
 
1998
1726
    def __init__(self, from_path, to_path, extra=None):
1999
1727
        BzrMoveFailedError.__init__(self, from_path, to_path, extra)
2000
1728
 
 
1729
class BzrRemoveChangedFilesError(BzrError):
 
1730
    """Used when user is trying to remove changed files."""
 
1731
 
 
1732
    _fmt = ("Can't remove changed or unknown files:\n%(changes_as_text)s"
 
1733
        "Use --keep to not delete them, or --force to delete them regardless.")
 
1734
 
 
1735
    def __init__(self, tree_delta):
 
1736
        BzrError.__init__(self)
 
1737
        self.changes_as_text = tree_delta.get_changes_as_text()
 
1738
        #self.paths_as_string = '\n'.join(changed_files)
 
1739
        #self.paths_as_string = '\n'.join([quotefn(p) for p in changed_files])
 
1740
 
2001
1741
 
2002
1742
class BzrBadParameterNotString(BzrBadParameter):
2003
1743
 
2006
1746
 
2007
1747
class BzrBadParameterMissing(BzrBadParameter):
2008
1748
 
2009
 
    _fmt = "Parameter %(param)s is required but not present."
 
1749
    _fmt = "Parameter $(param)s is required but not present."
2010
1750
 
2011
1751
 
2012
1752
class BzrBadParameterUnicode(BzrBadParameter):
2020
1760
    _fmt = "Parameter %(param)s contains a newline."
2021
1761
 
2022
1762
 
 
1763
class DependencyNotPresent(BzrError):
 
1764
 
 
1765
    _fmt = 'Unable to import library "%(library)s": %(error)s'
 
1766
 
 
1767
    def __init__(self, library, error):
 
1768
        BzrError.__init__(self, library=library, error=error)
 
1769
 
 
1770
 
2023
1771
class ParamikoNotPresent(DependencyNotPresent):
2024
1772
 
2025
1773
    _fmt = "Unable to import paramiko (required for sftp support): %(error)s"
2044
1792
 
2045
1793
class BadConversionTarget(BzrError):
2046
1794
 
2047
 
    _fmt = "Cannot convert from format %(from_format)s to format %(format)s." \
2048
 
            "    %(problem)s"
 
1795
    _fmt = "Cannot convert to format %(format)s.  %(problem)s"
2049
1796
 
2050
 
    def __init__(self, problem, format, from_format=None):
 
1797
    def __init__(self, problem, format):
2051
1798
        BzrError.__init__(self)
2052
1799
        self.problem = problem
2053
1800
        self.format = format
2054
 
        self.from_format = from_format or '(unspecified)'
2055
 
 
2056
 
 
2057
 
class NoDiffFound(BzrError):
2058
 
 
2059
 
    _fmt = 'Could not find an appropriate Differ for file "%(path)s"'
2060
 
 
2061
 
    def __init__(self, path):
2062
 
        BzrError.__init__(self, path)
2063
 
 
2064
 
 
2065
 
class ExecutableMissing(BzrError):
2066
 
 
2067
 
    _fmt = "%(exe_name)s could not be found on this machine"
2068
 
 
2069
 
    def __init__(self, exe_name):
2070
 
        BzrError.__init__(self, exe_name=exe_name)
2071
1801
 
2072
1802
 
2073
1803
class NoDiff(BzrError):
2083
1813
    _fmt = "Diff3 is not installed on this machine."
2084
1814
 
2085
1815
 
2086
 
class ExistingContent(BzrError):
2087
 
    # Added in bzrlib 0.92, used by VersionedFile.add_lines.
2088
 
 
2089
 
    _fmt = "The content being inserted is already present."
2090
 
 
2091
 
 
2092
1816
class ExistingLimbo(BzrError):
2093
1817
 
2094
1818
    _fmt = """This tree contains left-over files from a failed operation.
2095
1819
    Please examine %(limbo_dir)s to see if it contains any files you wish to
2096
1820
    keep, and delete it when you are done."""
2097
 
 
 
1821
    
2098
1822
    def __init__(self, limbo_dir):
2099
1823
       BzrError.__init__(self)
2100
1824
       self.limbo_dir = limbo_dir
2101
1825
 
2102
1826
 
2103
 
class ExistingPendingDeletion(BzrError):
2104
 
 
2105
 
    _fmt = """This tree contains left-over files from a failed operation.
2106
 
    Please examine %(pending_deletion)s to see if it contains any files you
2107
 
    wish to keep, and delete it when you are done."""
2108
 
 
2109
 
    def __init__(self, pending_deletion):
2110
 
       BzrError.__init__(self, pending_deletion=pending_deletion)
2111
 
 
2112
 
 
2113
1827
class ImmortalLimbo(BzrError):
2114
1828
 
2115
 
    _fmt = """Unable to delete transform temporary directory %(limbo_dir)s.
 
1829
    _fmt = """Unable to delete transform temporary directory $(limbo_dir)s.
2116
1830
    Please examine %(limbo_dir)s to see if it contains any files you wish to
2117
1831
    keep, and delete it when you are done."""
2118
1832
 
2121
1835
       self.limbo_dir = limbo_dir
2122
1836
 
2123
1837
 
2124
 
class ImmortalPendingDeletion(BzrError):
2125
 
 
2126
 
    _fmt = ("Unable to delete transform temporary directory "
2127
 
    "%(pending_deletion)s.  Please examine %(pending_deletion)s to see if it "
2128
 
    "contains any files you wish to keep, and delete it when you are done.")
2129
 
 
2130
 
    def __init__(self, pending_deletion):
2131
 
       BzrError.__init__(self, pending_deletion=pending_deletion)
2132
 
 
2133
 
 
2134
1838
class OutOfDateTree(BzrError):
2135
1839
 
2136
 
    _fmt = "Working tree is out of date, please run 'bzr update'.%(more)s"
 
1840
    _fmt = "Working tree is out of date, please run 'bzr update'."
2137
1841
 
2138
 
    def __init__(self, tree, more=None):
2139
 
        if more is None:
2140
 
            more = ''
2141
 
        else:
2142
 
            more = ' ' + more
 
1842
    def __init__(self, tree):
2143
1843
        BzrError.__init__(self)
2144
1844
        self.tree = tree
2145
 
        self.more = more
2146
1845
 
2147
1846
 
2148
1847
class PublicBranchOutOfDate(BzrError):
2168
1867
    _fmt = "Format error in conflict listings"
2169
1868
 
2170
1869
 
2171
 
class CorruptDirstate(BzrError):
2172
 
 
2173
 
    _fmt = ("Inconsistency in dirstate file %(dirstate_path)s.\n"
2174
 
            "Error: %(description)s")
2175
 
 
2176
 
    def __init__(self, dirstate_path, description):
2177
 
        BzrError.__init__(self)
2178
 
        self.dirstate_path = dirstate_path
2179
 
        self.description = description
2180
 
 
2181
 
 
2182
1870
class CorruptRepository(BzrError):
2183
1871
 
2184
1872
    _fmt = ("An error has been detected in the repository %(repo_path)s.\n"
2186
1874
 
2187
1875
    def __init__(self, repo):
2188
1876
        BzrError.__init__(self)
2189
 
        self.repo_path = repo.user_url
2190
 
 
2191
 
 
2192
 
class InconsistentDelta(BzrError):
2193
 
    """Used when we get a delta that is not valid."""
2194
 
 
2195
 
    _fmt = ("An inconsistent delta was supplied involving %(path)r,"
2196
 
            " %(file_id)r\nreason: %(reason)s")
2197
 
 
2198
 
    def __init__(self, path, file_id, reason):
2199
 
        BzrError.__init__(self)
2200
 
        self.path = path
2201
 
        self.file_id = file_id
2202
 
        self.reason = reason
2203
 
 
2204
 
 
2205
 
class InconsistentDeltaDelta(InconsistentDelta):
2206
 
    """Used when we get a delta that is not valid."""
2207
 
 
2208
 
    _fmt = ("An inconsistent delta was supplied: %(delta)r"
2209
 
            "\nreason: %(reason)s")
2210
 
 
2211
 
    def __init__(self, delta, reason):
2212
 
        BzrError.__init__(self)
2213
 
        self.delta = delta
2214
 
        self.reason = reason
 
1877
        self.repo_path = repo.bzrdir.root_transport.base
2215
1878
 
2216
1879
 
2217
1880
class UpgradeRequired(BzrError):
2223
1886
        self.path = path
2224
1887
 
2225
1888
 
2226
 
class RepositoryUpgradeRequired(UpgradeRequired):
2227
 
 
2228
 
    _fmt = "To use this feature you must upgrade your repository at %(path)s."
2229
 
 
2230
 
 
2231
 
class RichRootUpgradeRequired(UpgradeRequired):
2232
 
 
2233
 
    _fmt = ("To use this feature you must upgrade your branch at %(path)s to"
2234
 
           " a format which supports rich roots.")
2235
 
 
2236
 
 
2237
1889
class LocalRequiresBoundBranch(BzrError):
2238
1890
 
2239
1891
    _fmt = "Cannot perform local-only commits on unbound branches."
2240
1892
 
2241
1893
 
 
1894
class MissingProgressBarFinish(BzrError):
 
1895
 
 
1896
    _fmt = "A nested progress bar was not 'finished' correctly."
 
1897
 
 
1898
 
 
1899
class InvalidProgressBarType(BzrError):
 
1900
 
 
1901
    _fmt = ("Environment variable BZR_PROGRESS_BAR='%(bar_type)s"
 
1902
            " is not a supported type Select one of: %(valid_types)s")
 
1903
 
 
1904
    def __init__(self, bar_type, valid_types):
 
1905
        BzrError.__init__(self, bar_type=bar_type, valid_types=valid_types)
 
1906
 
 
1907
 
2242
1908
class UnsupportedOperation(BzrError):
2243
1909
 
2244
1910
    _fmt = ("The method %(mname)s is not supported on"
2260
1926
    """
2261
1927
 
2262
1928
 
2263
 
class GhostTagsNotSupported(BzrError):
2264
 
 
2265
 
    _fmt = "Ghost tags not supported by format %(format)r."
2266
 
 
2267
 
    def __init__(self, format):
2268
 
        self.format = format
2269
 
 
2270
 
 
2271
1929
class BinaryFile(BzrError):
2272
 
 
 
1930
    
2273
1931
    _fmt = "File is binary but should be text."
2274
1932
 
2275
1933
 
2295
1953
 
2296
1954
 
2297
1955
class NotABundle(BzrError):
2298
 
 
 
1956
    
2299
1957
    _fmt = "Not a bzr revision-bundle: %(text)r"
2300
1958
 
2301
1959
    def __init__(self, text):
2303
1961
        self.text = text
2304
1962
 
2305
1963
 
2306
 
class BadBundle(BzrError):
2307
 
 
 
1964
class BadBundle(BzrError): 
 
1965
    
2308
1966
    _fmt = "Bad bzr revision-bundle: %(text)r"
2309
1967
 
2310
1968
    def __init__(self, text):
2312
1970
        self.text = text
2313
1971
 
2314
1972
 
2315
 
class MalformedHeader(BadBundle):
2316
 
 
 
1973
class MalformedHeader(BadBundle): 
 
1974
    
2317
1975
    _fmt = "Malformed bzr revision-bundle header: %(text)r"
2318
1976
 
2319
1977
 
2320
 
class MalformedPatches(BadBundle):
2321
 
 
 
1978
class MalformedPatches(BadBundle): 
 
1979
    
2322
1980
    _fmt = "Malformed patches in bzr revision-bundle: %(text)r"
2323
1981
 
2324
1982
 
2325
 
class MalformedFooter(BadBundle):
2326
 
 
 
1983
class MalformedFooter(BadBundle): 
 
1984
    
2327
1985
    _fmt = "Malformed footer in bzr revision-bundle: %(text)r"
2328
1986
 
2329
1987
 
2330
1988
class UnsupportedEOLMarker(BadBundle):
2331
 
 
2332
 
    _fmt = "End of line marker was not \\n in bzr revision-bundle"
 
1989
    
 
1990
    _fmt = "End of line marker was not \\n in bzr revision-bundle"    
2333
1991
 
2334
1992
    def __init__(self):
2335
 
        # XXX: BadBundle's constructor assumes there's explanatory text,
 
1993
        # XXX: BadBundle's constructor assumes there's explanatory text, 
2336
1994
        # but for this there is not
2337
1995
        BzrError.__init__(self)
2338
1996
 
2339
1997
 
2340
1998
class IncompatibleBundleFormat(BzrError):
2341
 
 
 
1999
    
2342
2000
    _fmt = "Bundle format %(bundle_format)s is incompatible with %(other)s"
2343
2001
 
2344
2002
    def __init__(self, bundle_format, other):
2348
2006
 
2349
2007
 
2350
2008
class BadInventoryFormat(BzrError):
2351
 
 
 
2009
    
2352
2010
    _fmt = "Root class for inventory serialization errors"
2353
2011
 
2354
2012
 
2365
2023
    _fmt = """This operation requires rich root data storage"""
2366
2024
 
2367
2025
 
2368
 
class NoSmartMedium(InternalBzrError):
 
2026
class NoSmartMedium(BzrError):
2369
2027
 
2370
2028
    _fmt = "The transport '%(transport)s' cannot tunnel the smart protocol."
2371
2029
 
 
2030
    internal_error = True
 
2031
 
2372
2032
    def __init__(self, transport):
2373
2033
        self.transport = transport
2374
2034
 
2375
2035
 
 
2036
class NoSmartServer(NotBranchError):
 
2037
 
 
2038
    _fmt = "No smart server available at %(url)s"
 
2039
 
 
2040
    def __init__(self, url):
 
2041
        self.url = url
 
2042
 
 
2043
 
2376
2044
class UnknownSSH(BzrError):
2377
2045
 
2378
2046
    _fmt = "Unrecognised value for BZR_SSH environment variable: %(vendor)s"
2388
2056
            " Please set BZR_SSH environment variable.")
2389
2057
 
2390
2058
 
2391
 
class GhostRevisionsHaveNoRevno(BzrError):
2392
 
    """When searching for revnos, if we encounter a ghost, we are stuck"""
2393
 
 
2394
 
    _fmt = ("Could not determine revno for {%(revision_id)s} because"
2395
 
            " its ancestry shows a ghost at {%(ghost_revision_id)s}")
2396
 
 
2397
 
    def __init__(self, revision_id, ghost_revision_id):
2398
 
        self.revision_id = revision_id
2399
 
        self.ghost_revision_id = ghost_revision_id
2400
 
 
2401
 
 
2402
2059
class GhostRevisionUnusableHere(BzrError):
2403
2060
 
2404
2061
    _fmt = "Ghost revision {%(revision_id)s} cannot be used here."
2408
2065
        self.revision_id = revision_id
2409
2066
 
2410
2067
 
2411
 
class IllegalUseOfScopeReplacer(InternalBzrError):
 
2068
class IllegalUseOfScopeReplacer(BzrError):
2412
2069
 
2413
2070
    _fmt = ("ScopeReplacer object %(name)r was used incorrectly:"
2414
2071
            " %(msg)s%(extra)s")
2415
2072
 
 
2073
    internal_error = True
 
2074
 
2416
2075
    def __init__(self, name, msg, extra=None):
2417
2076
        BzrError.__init__(self)
2418
2077
        self.name = name
2423
2082
            self.extra = ''
2424
2083
 
2425
2084
 
2426
 
class InvalidImportLine(InternalBzrError):
 
2085
class InvalidImportLine(BzrError):
2427
2086
 
2428
2087
    _fmt = "Not a valid import statement: %(msg)\n%(text)s"
2429
2088
 
 
2089
    internal_error = True
 
2090
 
2430
2091
    def __init__(self, text, msg):
2431
2092
        BzrError.__init__(self)
2432
2093
        self.text = text
2433
2094
        self.msg = msg
2434
2095
 
2435
2096
 
2436
 
class ImportNameCollision(InternalBzrError):
 
2097
class ImportNameCollision(BzrError):
2437
2098
 
2438
2099
    _fmt = ("Tried to import an object to the same name as"
2439
2100
            " an existing object. %(name)s")
2440
2101
 
 
2102
    internal_error = True
 
2103
 
2441
2104
    def __init__(self, name):
2442
2105
        BzrError.__init__(self)
2443
2106
        self.name = name
2475
2138
class PatchMissing(BzrError):
2476
2139
    """Raise a patch type was specified but no patch supplied"""
2477
2140
 
2478
 
    _fmt = "Patch_type was %(patch_type)s, but no patch was supplied."
 
2141
    _fmt = "patch_type was %(patch_type)s, but no patch was supplied."
2479
2142
 
2480
2143
    def __init__(self, patch_type):
2481
2144
        BzrError.__init__(self)
2482
2145
        self.patch_type = patch_type
2483
2146
 
2484
2147
 
2485
 
class TargetNotBranch(BzrError):
2486
 
    """A merge directive's target branch is required, but isn't a branch"""
2487
 
 
2488
 
    _fmt = ("Your branch does not have all of the revisions required in "
2489
 
            "order to merge this merge directive and the target "
2490
 
            "location specified in the merge directive is not a branch: "
2491
 
            "%(location)s.")
2492
 
 
2493
 
    def __init__(self, location):
2494
 
        BzrError.__init__(self)
2495
 
        self.location = location
2496
 
 
2497
 
 
2498
2148
class UnsupportedInventoryKind(BzrError):
2499
 
 
 
2149
    
2500
2150
    _fmt = """Unsupported entry kind %(kind)s"""
2501
2151
 
2502
2152
    def __init__(self, kind):
2505
2155
 
2506
2156
class BadSubsumeSource(BzrError):
2507
2157
 
2508
 
    _fmt = "Can't subsume %(other_tree)s into %(tree)s. %(reason)s"
 
2158
    _fmt = """Can't subsume %(other_tree)s into %(tree)s.  %(reason)s"""
2509
2159
 
2510
2160
    def __init__(self, tree, other_tree, reason):
2511
2161
        self.tree = tree
2514
2164
 
2515
2165
 
2516
2166
class SubsumeTargetNeedsUpgrade(BzrError):
2517
 
 
 
2167
    
2518
2168
    _fmt = """Subsume target %(other_tree)s needs to be upgraded."""
2519
2169
 
2520
2170
    def __init__(self, other_tree):
2521
2171
        self.other_tree = other_tree
2522
2172
 
2523
2173
 
2524
 
class BadReferenceTarget(InternalBzrError):
2525
 
 
2526
 
    _fmt = "Can't add reference to %(other_tree)s into %(tree)s." \
2527
 
           "%(reason)s"
 
2174
class BadReferenceTarget(BzrError):
 
2175
 
 
2176
    _fmt = "Can't add reference to %(other_tree)s into %(tree)s.  %(reason)s"
 
2177
 
 
2178
    internal_error = True
2528
2179
 
2529
2180
    def __init__(self, tree, other_tree, reason):
2530
2181
        self.tree = tree
2543
2194
class TagsNotSupported(BzrError):
2544
2195
 
2545
2196
    _fmt = ("Tags not supported by %(branch)s;"
2546
 
            " you may be able to use bzr upgrade.")
 
2197
            " you may be able to use bzr upgrade --dirstate-tags.")
2547
2198
 
2548
2199
    def __init__(self, branch):
2549
2200
        self.branch = branch
2550
2201
 
2551
 
 
 
2202
        
2552
2203
class TagAlreadyExists(BzrError):
2553
2204
 
2554
2205
    _fmt = "Tag %(tag_name)s already exists."
2559
2210
 
2560
2211
class MalformedBugIdentifier(BzrError):
2561
2212
 
2562
 
    _fmt = ('Did not understand bug identifier %(bug_id)s: %(reason)s. '
2563
 
            'See "bzr help bugs" for more information on this feature.')
 
2213
    _fmt = "Did not understand bug identifier %(bug_id)s: %(reason)s"
2564
2214
 
2565
2215
    def __init__(self, bug_id, reason):
2566
2216
        self.bug_id = bug_id
2567
2217
        self.reason = reason
2568
2218
 
2569
2219
 
2570
 
class InvalidBugTrackerURL(BzrError):
2571
 
 
2572
 
    _fmt = ("The URL for bug tracker \"%(abbreviation)s\" doesn't "
2573
 
            "contain {id}: %(url)s")
2574
 
 
2575
 
    def __init__(self, abbreviation, url):
2576
 
        self.abbreviation = abbreviation
2577
 
        self.url = url
2578
 
 
2579
 
 
2580
2220
class UnknownBugTrackerAbbreviation(BzrError):
2581
2221
 
2582
2222
    _fmt = ("Cannot find registered bug tracker called %(abbreviation)s "
2587
2227
        self.branch = branch
2588
2228
 
2589
2229
 
2590
 
class InvalidLineInBugsProperty(BzrError):
2591
 
 
2592
 
    _fmt = ("Invalid line in bugs property: '%(line)s'")
2593
 
 
2594
 
    def __init__(self, line):
2595
 
        self.line = line
2596
 
 
2597
 
 
2598
 
class InvalidBugStatus(BzrError):
2599
 
 
2600
 
    _fmt = ("Invalid bug status: '%(status)s'")
2601
 
 
2602
 
    def __init__(self, status):
2603
 
        self.status = status
2604
 
 
2605
 
 
2606
2230
class UnexpectedSmartServerResponse(BzrError):
2607
2231
 
2608
2232
    _fmt = "Could not understand response from smart server: %(response_tuple)r"
2611
2235
        self.response_tuple = response_tuple
2612
2236
 
2613
2237
 
2614
 
class ErrorFromSmartServer(BzrError):
2615
 
    """An error was received from a smart server.
2616
 
 
2617
 
    :seealso: UnknownErrorFromSmartServer
2618
 
    """
2619
 
 
2620
 
    _fmt = "Error received from smart server: %(error_tuple)r"
2621
 
 
2622
 
    internal_error = True
2623
 
 
2624
 
    def __init__(self, error_tuple):
2625
 
        self.error_tuple = error_tuple
2626
 
        try:
2627
 
            self.error_verb = error_tuple[0]
2628
 
        except IndexError:
2629
 
            self.error_verb = None
2630
 
        self.error_args = error_tuple[1:]
2631
 
 
2632
 
 
2633
 
class UnknownErrorFromSmartServer(BzrError):
2634
 
    """An ErrorFromSmartServer could not be translated into a typical bzrlib
2635
 
    error.
2636
 
 
2637
 
    This is distinct from ErrorFromSmartServer so that it is possible to
2638
 
    distinguish between the following two cases:
2639
 
 
2640
 
    - ErrorFromSmartServer was uncaught.  This is logic error in the client
2641
 
      and so should provoke a traceback to the user.
2642
 
    - ErrorFromSmartServer was caught but its error_tuple could not be
2643
 
      translated.  This is probably because the server sent us garbage, and
2644
 
      should not provoke a traceback.
2645
 
    """
2646
 
 
2647
 
    _fmt = "Server sent an unexpected error: %(error_tuple)r"
2648
 
 
2649
 
    internal_error = False
2650
 
 
2651
 
    def __init__(self, error_from_smart_server):
2652
 
        """Constructor.
2653
 
 
2654
 
        :param error_from_smart_server: An ErrorFromSmartServer instance.
2655
 
        """
2656
 
        self.error_from_smart_server = error_from_smart_server
2657
 
        self.error_tuple = error_from_smart_server.error_tuple
2658
 
 
2659
 
 
2660
2238
class ContainerError(BzrError):
2661
2239
    """Base class of container errors."""
2662
2240
 
2664
2242
class UnknownContainerFormatError(ContainerError):
2665
2243
 
2666
2244
    _fmt = "Unrecognised container format: %(container_format)r"
2667
 
 
 
2245
    
2668
2246
    def __init__(self, container_format):
2669
2247
        self.container_format = container_format
2670
2248
 
2673
2251
 
2674
2252
    _fmt = "Unexpected end of container stream"
2675
2253
 
 
2254
    internal_error = False
 
2255
 
2676
2256
 
2677
2257
class UnknownRecordTypeError(ContainerError):
2678
2258
 
2700
2280
 
2701
2281
class DuplicateRecordNameError(ContainerError):
2702
2282
 
2703
 
    _fmt = "Container has multiple records with the same name: %(name)s"
 
2283
    _fmt = "Container has multiple records with the same name: \"%(name)s\""
2704
2284
 
2705
2285
    def __init__(self, name):
2706
 
        self.name = name.decode("utf-8")
2707
 
 
2708
 
 
2709
 
class NoDestinationAddress(InternalBzrError):
 
2286
        self.name = name
 
2287
 
 
2288
 
 
2289
class NoDestinationAddress(BzrError):
2710
2290
 
2711
2291
    _fmt = "Message does not have a destination address."
2712
2292
 
2713
 
 
2714
 
class RepositoryDataStreamError(BzrError):
2715
 
 
2716
 
    _fmt = "Corrupt or incompatible data stream: %(reason)s"
2717
 
 
2718
 
    def __init__(self, reason):
2719
 
        self.reason = reason
 
2293
    internal_error = True
2720
2294
 
2721
2295
 
2722
2296
class SMTPError(BzrError):
2725
2299
 
2726
2300
    def __init__(self, error):
2727
2301
        self.error = error
2728
 
 
2729
 
 
2730
 
class NoMessageSupplied(BzrError):
2731
 
 
2732
 
    _fmt = "No message supplied."
2733
 
 
2734
 
 
2735
 
class NoMailAddressSpecified(BzrError):
2736
 
 
2737
 
    _fmt = "No mail-to address (--mail-to) or output (-o) specified."
2738
 
 
2739
 
 
2740
 
class UnknownMailClient(BzrError):
2741
 
 
2742
 
    _fmt = "Unknown mail client: %(mail_client)s"
2743
 
 
2744
 
    def __init__(self, mail_client):
2745
 
        BzrError.__init__(self, mail_client=mail_client)
2746
 
 
2747
 
 
2748
 
class MailClientNotFound(BzrError):
2749
 
 
2750
 
    _fmt = "Unable to find mail client with the following names:"\
2751
 
        " %(mail_command_list_string)s"
2752
 
 
2753
 
    def __init__(self, mail_command_list):
2754
 
        mail_command_list_string = ', '.join(mail_command_list)
2755
 
        BzrError.__init__(self, mail_command_list=mail_command_list,
2756
 
                          mail_command_list_string=mail_command_list_string)
2757
 
 
2758
 
class SMTPConnectionRefused(SMTPError):
2759
 
 
2760
 
    _fmt = "SMTP connection to %(host)s refused"
2761
 
 
2762
 
    def __init__(self, error, host):
2763
 
        self.error = error
2764
 
        self.host = host
2765
 
 
2766
 
 
2767
 
class DefaultSMTPConnectionRefused(SMTPConnectionRefused):
2768
 
 
2769
 
    _fmt = "Please specify smtp_server.  No server at default %(host)s."
2770
 
 
2771
 
 
2772
 
class BzrDirError(BzrError):
2773
 
 
2774
 
    def __init__(self, bzrdir):
2775
 
        import bzrlib.urlutils as urlutils
2776
 
        display_url = urlutils.unescape_for_display(bzrdir.user_url,
2777
 
                                                    'ascii')
2778
 
        BzrError.__init__(self, bzrdir=bzrdir, display_url=display_url)
2779
 
 
2780
 
 
2781
 
class UnsyncedBranches(BzrDirError):
2782
 
 
2783
 
    _fmt = ("'%(display_url)s' is not in sync with %(target_url)s.  See"
2784
 
            " bzr help sync-for-reconfigure.")
2785
 
 
2786
 
    def __init__(self, bzrdir, target_branch):
2787
 
        BzrDirError.__init__(self, bzrdir)
2788
 
        import bzrlib.urlutils as urlutils
2789
 
        self.target_url = urlutils.unescape_for_display(target_branch.base,
2790
 
                                                        'ascii')
2791
 
 
2792
 
 
2793
 
class AlreadyBranch(BzrDirError):
2794
 
 
2795
 
    _fmt = "'%(display_url)s' is already a branch."
2796
 
 
2797
 
 
2798
 
class AlreadyTree(BzrDirError):
2799
 
 
2800
 
    _fmt = "'%(display_url)s' is already a tree."
2801
 
 
2802
 
 
2803
 
class AlreadyCheckout(BzrDirError):
2804
 
 
2805
 
    _fmt = "'%(display_url)s' is already a checkout."
2806
 
 
2807
 
 
2808
 
class AlreadyLightweightCheckout(BzrDirError):
2809
 
 
2810
 
    _fmt = "'%(display_url)s' is already a lightweight checkout."
2811
 
 
2812
 
 
2813
 
class AlreadyUsingShared(BzrDirError):
2814
 
 
2815
 
    _fmt = "'%(display_url)s' is already using a shared repository."
2816
 
 
2817
 
 
2818
 
class AlreadyStandalone(BzrDirError):
2819
 
 
2820
 
    _fmt = "'%(display_url)s' is already standalone."
2821
 
 
2822
 
 
2823
 
class AlreadyWithTrees(BzrDirError):
2824
 
 
2825
 
    _fmt = ("Shared repository '%(display_url)s' already creates "
2826
 
            "working trees.")
2827
 
 
2828
 
 
2829
 
class AlreadyWithNoTrees(BzrDirError):
2830
 
 
2831
 
    _fmt = ("Shared repository '%(display_url)s' already doesn't create "
2832
 
            "working trees.")
2833
 
 
2834
 
 
2835
 
class ReconfigurationNotSupported(BzrDirError):
2836
 
 
2837
 
    _fmt = "Requested reconfiguration of '%(display_url)s' is not supported."
2838
 
 
2839
 
 
2840
 
class NoBindLocation(BzrDirError):
2841
 
 
2842
 
    _fmt = "No location could be found to bind to at %(display_url)s."
2843
 
 
2844
 
 
2845
 
class UncommittedChanges(BzrError):
2846
 
 
2847
 
    _fmt = ('Working tree "%(display_url)s" has uncommitted changes'
2848
 
            ' (See bzr status).%(more)s')
2849
 
 
2850
 
    def __init__(self, tree, more=None):
2851
 
        if more is None:
2852
 
            more = ''
2853
 
        else:
2854
 
            more = ' ' + more
2855
 
        import bzrlib.urlutils as urlutils
2856
 
        user_url = getattr(tree, "user_url", None)
2857
 
        if user_url is None:
2858
 
            display_url = str(tree)
2859
 
        else:
2860
 
            display_url = urlutils.unescape_for_display(user_url, 'ascii')
2861
 
        BzrError.__init__(self, tree=tree, display_url=display_url, more=more)
2862
 
 
2863
 
 
2864
 
class ShelvedChanges(UncommittedChanges):
2865
 
 
2866
 
    _fmt = ('Working tree "%(display_url)s" has shelved changes'
2867
 
            ' (See bzr shelve --list).%(more)s')
2868
 
 
2869
 
 
2870
 
class MissingTemplateVariable(BzrError):
2871
 
 
2872
 
    _fmt = 'Variable {%(name)s} is not available.'
2873
 
 
2874
 
    def __init__(self, name):
2875
 
        self.name = name
2876
 
 
2877
 
 
2878
 
class NoTemplate(BzrError):
2879
 
 
2880
 
    _fmt = 'No template specified.'
2881
 
 
2882
 
 
2883
 
class UnableCreateSymlink(BzrError):
2884
 
 
2885
 
    _fmt = 'Unable to create symlink %(path_str)son this platform'
2886
 
 
2887
 
    def __init__(self, path=None):
2888
 
        path_str = ''
2889
 
        if path:
2890
 
            try:
2891
 
                path_str = repr(str(path))
2892
 
            except UnicodeEncodeError:
2893
 
                path_str = repr(path)
2894
 
            path_str += ' '
2895
 
        self.path_str = path_str
2896
 
 
2897
 
 
2898
 
class UnsupportedTimezoneFormat(BzrError):
2899
 
 
2900
 
    _fmt = ('Unsupported timezone format "%(timezone)s", '
2901
 
            'options are "utc", "original", "local".')
2902
 
 
2903
 
    def __init__(self, timezone):
2904
 
        self.timezone = timezone
2905
 
 
2906
 
 
2907
 
class CommandAvailableInPlugin(StandardError):
2908
 
 
2909
 
    internal_error = False
2910
 
 
2911
 
    def __init__(self, cmd_name, plugin_metadata, provider):
2912
 
 
2913
 
        self.plugin_metadata = plugin_metadata
2914
 
        self.cmd_name = cmd_name
2915
 
        self.provider = provider
2916
 
 
2917
 
    def __str__(self):
2918
 
 
2919
 
        _fmt = ('"%s" is not a standard bzr command. \n'
2920
 
                'However, the following official plugin provides this command: %s\n'
2921
 
                'You can install it by going to: %s'
2922
 
                % (self.cmd_name, self.plugin_metadata['name'],
2923
 
                    self.plugin_metadata['url']))
2924
 
 
2925
 
        return _fmt
2926
 
 
2927
 
 
2928
 
class NoPluginAvailable(BzrError):
2929
 
    pass
2930
 
 
2931
 
 
2932
 
class UnableEncodePath(BzrError):
2933
 
 
2934
 
    _fmt = ('Unable to encode %(kind)s path %(path)r in '
2935
 
            'user encoding %(user_encoding)s')
2936
 
 
2937
 
    def __init__(self, path, kind):
2938
 
        from bzrlib.osutils import get_user_encoding
2939
 
        self.path = path
2940
 
        self.kind = kind
2941
 
        self.user_encoding = get_user_encoding()
2942
 
 
2943
 
 
2944
 
class NoSuchConfig(BzrError):
2945
 
 
2946
 
    _fmt = ('The "%(config_id)s" configuration does not exist.')
2947
 
 
2948
 
    def __init__(self, config_id):
2949
 
        BzrError.__init__(self, config_id=config_id)
2950
 
 
2951
 
 
2952
 
class NoSuchConfigOption(BzrError):
2953
 
 
2954
 
    _fmt = ('The "%(option_name)s" configuration option does not exist.')
2955
 
 
2956
 
    def __init__(self, option_name):
2957
 
        BzrError.__init__(self, option_name=option_name)
2958
 
 
2959
 
 
2960
 
class NoSuchAlias(BzrError):
2961
 
 
2962
 
    _fmt = ('The alias "%(alias_name)s" does not exist.')
2963
 
 
2964
 
    def __init__(self, alias_name):
2965
 
        BzrError.__init__(self, alias_name=alias_name)
2966
 
 
2967
 
 
2968
 
class DirectoryLookupFailure(BzrError):
2969
 
    """Base type for lookup errors."""
2970
 
 
2971
 
    pass
2972
 
 
2973
 
 
2974
 
class InvalidLocationAlias(DirectoryLookupFailure):
2975
 
 
2976
 
    _fmt = '"%(alias_name)s" is not a valid location alias.'
2977
 
 
2978
 
    def __init__(self, alias_name):
2979
 
        DirectoryLookupFailure.__init__(self, alias_name=alias_name)
2980
 
 
2981
 
 
2982
 
class UnsetLocationAlias(DirectoryLookupFailure):
2983
 
 
2984
 
    _fmt = 'No %(alias_name)s location assigned.'
2985
 
 
2986
 
    def __init__(self, alias_name):
2987
 
        DirectoryLookupFailure.__init__(self, alias_name=alias_name[1:])
2988
 
 
2989
 
 
2990
 
class CannotBindAddress(BzrError):
2991
 
 
2992
 
    _fmt = 'Cannot bind address "%(host)s:%(port)i": %(orig_error)s.'
2993
 
 
2994
 
    def __init__(self, host, port, orig_error):
2995
 
        # nb: in python2.4 socket.error doesn't have a useful repr
2996
 
        BzrError.__init__(self, host=host, port=port,
2997
 
            orig_error=repr(orig_error.args))
2998
 
 
2999
 
 
3000
 
class UnknownRules(BzrError):
3001
 
 
3002
 
    _fmt = ('Unknown rules detected: %(unknowns_str)s.')
3003
 
 
3004
 
    def __init__(self, unknowns):
3005
 
        BzrError.__init__(self, unknowns_str=", ".join(unknowns))
3006
 
 
3007
 
 
3008
 
class TipChangeRejected(BzrError):
3009
 
    """A pre_change_branch_tip hook function may raise this to cleanly and
3010
 
    explicitly abort a change to a branch tip.
3011
 
    """
3012
 
 
3013
 
    _fmt = u"Tip change rejected: %(msg)s"
3014
 
 
3015
 
    def __init__(self, msg):
3016
 
        self.msg = msg
3017
 
 
3018
 
 
3019
 
class ShelfCorrupt(BzrError):
3020
 
 
3021
 
    _fmt = "Shelf corrupt."
3022
 
 
3023
 
 
3024
 
class DecompressCorruption(BzrError):
3025
 
 
3026
 
    _fmt = "Corruption while decompressing repository file%(orig_error)s"
3027
 
 
3028
 
    def __init__(self, orig_error=None):
3029
 
        if orig_error is not None:
3030
 
            self.orig_error = ", %s" % (orig_error,)
3031
 
        else:
3032
 
            self.orig_error = ""
3033
 
        BzrError.__init__(self)
3034
 
 
3035
 
 
3036
 
class NoSuchShelfId(BzrError):
3037
 
 
3038
 
    _fmt = 'No changes are shelved with id "%(shelf_id)d".'
3039
 
 
3040
 
    def __init__(self, shelf_id):
3041
 
        BzrError.__init__(self, shelf_id=shelf_id)
3042
 
 
3043
 
 
3044
 
class InvalidShelfId(BzrError):
3045
 
 
3046
 
    _fmt = '"%(invalid_id)s" is not a valid shelf id, try a number instead.'
3047
 
 
3048
 
    def __init__(self, invalid_id):
3049
 
        BzrError.__init__(self, invalid_id=invalid_id)
3050
 
 
3051
 
 
3052
 
class JailBreak(BzrError):
3053
 
 
3054
 
    _fmt = "An attempt to access a url outside the server jail was made: '%(url)s'."
3055
 
 
3056
 
    def __init__(self, url):
3057
 
        BzrError.__init__(self, url=url)
3058
 
 
3059
 
 
3060
 
class UserAbort(BzrError):
3061
 
 
3062
 
    _fmt = 'The user aborted the operation.'
3063
 
 
3064
 
 
3065
 
class MustHaveWorkingTree(BzrError):
3066
 
 
3067
 
    _fmt = ("Branching '%(url)s'(%(format)s) must create a working tree.")
3068
 
 
3069
 
    def __init__(self, format, url):
3070
 
        BzrError.__init__(self, format=format, url=url)
3071
 
 
3072
 
 
3073
 
class NoSuchView(BzrError):
3074
 
    """A view does not exist.
3075
 
    """
3076
 
 
3077
 
    _fmt = u"No such view: %(view_name)s."
3078
 
 
3079
 
    def __init__(self, view_name):
3080
 
        self.view_name = view_name
3081
 
 
3082
 
 
3083
 
class ViewsNotSupported(BzrError):
3084
 
    """Views are not supported by a tree format.
3085
 
    """
3086
 
 
3087
 
    _fmt = ("Views are not supported by %(tree)s;"
3088
 
            " use 'bzr upgrade' to change your tree to a later format.")
3089
 
 
3090
 
    def __init__(self, tree):
3091
 
        self.tree = tree
3092
 
 
3093
 
 
3094
 
class FileOutsideView(BzrError):
3095
 
 
3096
 
    _fmt = ('Specified file "%(file_name)s" is outside the current view: '
3097
 
            '%(view_str)s')
3098
 
 
3099
 
    def __init__(self, file_name, view_files):
3100
 
        self.file_name = file_name
3101
 
        self.view_str = ", ".join(view_files)
3102
 
 
3103
 
 
3104
 
class UnresumableWriteGroup(BzrError):
3105
 
 
3106
 
    _fmt = ("Repository %(repository)s cannot resume write group "
3107
 
            "%(write_groups)r: %(reason)s")
3108
 
 
3109
 
    internal_error = True
3110
 
 
3111
 
    def __init__(self, repository, write_groups, reason):
3112
 
        self.repository = repository
3113
 
        self.write_groups = write_groups
3114
 
        self.reason = reason
3115
 
 
3116
 
 
3117
 
class UnsuspendableWriteGroup(BzrError):
3118
 
 
3119
 
    _fmt = ("Repository %(repository)s cannot suspend a write group.")
3120
 
 
3121
 
    internal_error = True
3122
 
 
3123
 
    def __init__(self, repository):
3124
 
        self.repository = repository
3125
 
 
3126
 
 
3127
 
class LossyPushToSameVCS(BzrError):
3128
 
 
3129
 
    _fmt = ("Lossy push not possible between %(source_branch)r and "
3130
 
            "%(target_branch)r that are in the same VCS.")
3131
 
 
3132
 
    internal_error = True
3133
 
 
3134
 
    def __init__(self, source_branch, target_branch):
3135
 
        self.source_branch = source_branch
3136
 
        self.target_branch = target_branch
3137
 
 
3138
 
 
3139
 
class NoRoundtrippingSupport(BzrError):
3140
 
 
3141
 
    _fmt = ("Roundtripping is not supported between %(source_branch)r and "
3142
 
            "%(target_branch)r.")
3143
 
 
3144
 
    internal_error = True
3145
 
 
3146
 
    def __init__(self, source_branch, target_branch):
3147
 
        self.source_branch = source_branch
3148
 
        self.target_branch = target_branch
3149
 
 
3150
 
 
3151
 
class FileTimestampUnavailable(BzrError):
3152
 
 
3153
 
    _fmt = "The filestamp for %(path)s is not available."
3154
 
 
3155
 
    internal_error = True
3156
 
 
3157
 
    def __init__(self, path):
3158
 
        self.path = path
3159
 
 
3160
 
 
3161
 
class NoColocatedBranchSupport(BzrError):
3162
 
 
3163
 
    _fmt = ("%(bzrdir)r does not support co-located branches.")
3164
 
 
3165
 
    def __init__(self, bzrdir):
3166
 
        self.bzrdir = bzrdir
3167
 
 
3168
 
 
3169
 
class NoWhoami(BzrError):
3170
 
 
3171
 
    _fmt = ('Unable to determine your name.\n'
3172
 
        "Please, set your name with the 'whoami' command.\n"
3173
 
        'E.g. bzr whoami "Your Name <name@example.com>"')
3174
 
 
3175
 
 
3176
 
class InvalidPattern(BzrError):
3177
 
 
3178
 
    _fmt = ('Invalid pattern(s) found. %(msg)s')
3179
 
 
3180
 
    def __init__(self, msg):
3181
 
        self.msg = msg
3182
 
 
3183
 
 
3184
 
class RecursiveBind(BzrError):
3185
 
 
3186
 
    _fmt = ('Branch "%(branch_url)s" appears to be bound to itself. '
3187
 
        'Please use `bzr unbind` to fix.')
3188
 
 
3189
 
    def __init__(self, branch_url):
3190
 
        self.branch_url = branch_url
3191
 
 
3192
 
 
3193
 
# FIXME: I would prefer to define the config related exception classes in
3194
 
# config.py but the lazy import mechanism proscribes this -- vila 20101222
3195
 
class OptionExpansionLoop(BzrError):
3196
 
 
3197
 
    _fmt = 'Loop involving %(refs)r while expanding "%(string)s".'
3198
 
 
3199
 
    def __init__(self, string, refs):
3200
 
        self.string = string
3201
 
        self.refs = '->'.join(refs)
3202
 
 
3203
 
 
3204
 
class ExpandingUnknownOption(BzrError):
3205
 
 
3206
 
    _fmt = 'Option %(name)s is not defined while expanding "%(string)s".'
3207
 
 
3208
 
    def __init__(self, name, string):
3209
 
        self.name = name
3210
 
        self.string = string
3211
 
 
3212
 
 
3213
 
class NoCompatibleInter(BzrError):
3214
 
 
3215
 
    _fmt = ('No compatible object available for operations from %(source)r '
3216
 
            'to %(target)r.')
3217
 
 
3218
 
    def __init__(self, source, target):
3219
 
        self.source = source
3220
 
        self.target = target
3221
 
 
3222
 
 
3223
 
class HpssVfsRequestNotAllowed(BzrError):
3224
 
 
3225
 
    _fmt = ("VFS requests over the smart server are not allowed. Encountered: "
3226
 
            "%(method)s, %(arguments)s.")
3227
 
 
3228
 
    def __init__(self, method, arguments):
3229
 
        self.method = method
3230
 
        self.arguments = arguments
3231
 
 
3232
 
 
3233
 
class UnsupportedKindChange(BzrError):
3234
 
 
3235
 
    _fmt = ("Kind change from %(from_kind)s to %(to_kind)s for "
3236
 
            "%(path)s not supported by format %(format)r")
3237
 
 
3238
 
    def __init__(self, path, from_kind, to_kind, format):
3239
 
        self.path = path
3240
 
        self.from_kind = from_kind
3241
 
        self.to_kind = to_kind
3242
 
        self.format = format
3243
 
 
3244
 
 
3245
 
class PatchSyntax(BzrError):
3246
 
    """Base class for patch syntax errors."""
3247
 
 
3248
 
 
3249
 
class BinaryFiles(BzrError):
3250
 
 
3251
 
    _fmt = 'Binary files section encountered.'
3252
 
 
3253
 
    def __init__(self, orig_name, mod_name):
3254
 
        self.orig_name = orig_name
3255
 
        self.mod_name = mod_name
3256
 
 
3257
 
 
3258
 
class MalformedPatchHeader(PatchSyntax):
3259
 
 
3260
 
    _fmt = "Malformed patch header.  %(desc)s\n%(line)r"
3261
 
 
3262
 
    def __init__(self, desc, line):
3263
 
        self.desc = desc
3264
 
        self.line = line
3265
 
 
3266
 
 
3267
 
class MalformedHunkHeader(PatchSyntax):
3268
 
 
3269
 
    _fmt = "Malformed hunk header.  %(desc)s\n%(line)r"
3270
 
 
3271
 
    def __init__(self, desc, line):
3272
 
        self.desc = desc
3273
 
        self.line = line
3274
 
 
3275
 
 
3276
 
class MalformedLine(PatchSyntax):
3277
 
 
3278
 
    _fmt = "Malformed line.  %(desc)s\n%(line)r"
3279
 
 
3280
 
    def __init__(self, desc, line):
3281
 
        self.desc = desc
3282
 
        self.line = line
3283
 
 
3284
 
 
3285
 
class PatchConflict(BzrError):
3286
 
 
3287
 
    _fmt = ('Text contents mismatch at line %(line_no)d.  Original has '
3288
 
            '"%(orig_line)s", but patch says it should be "%(patch_line)s"')
3289
 
 
3290
 
    def __init__(self, line_no, orig_line, patch_line):
3291
 
        self.line_no = line_no
3292
 
        self.orig_line = orig_line.rstrip('\n')
3293
 
        self.patch_line = patch_line.rstrip('\n')