~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/errors.py

  • Committer: Martin Pool
  • Date: 2006-11-02 10:20:19 UTC
  • mfrom: (2114 +trunk)
  • mto: This revision was merged to the branch mainline in revision 2119.
  • Revision ID: mbp@sourcefrog.net-20061102102019-9a5a02f485dff6f6
merge bzr.dev and reconcile several changes, also some test fixes

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# -*- coding: UTF-8 -*-
2
 
 
 
1
# Copyright (C) 2005, 2006 Canonical Ltd
 
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
5
5
# the Free Software Foundation; either version 2 of the License, or
6
6
# (at your option) any later version.
7
 
 
 
7
#
8
8
# This program is distributed in the hope that it will be useful,
9
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
11
# GNU General Public License for more details.
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
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
 
 
19
 
Exceptions are caught at a high level to report errors to the user, and
20
 
might also be caught inside the program.  Therefore it needs to be
21
 
possible to convert them to a meaningful string, and also for them to be
22
 
interrogated by the program.
23
 
 
24
 
Exceptions are defined such that the arguments given to the constructor
25
 
are stored in the object as properties of the same name.  When the
26
 
object is printed as a string, the doc string of the class is used as
27
 
a format string with the property dictionary available to it.
28
 
 
29
 
This means that exceptions can used like this:
30
 
 
31
 
>>> import sys
32
 
>>> try:
33
 
...   raise NotBranchError(path='/foo/bar')
34
 
... except:
35
 
...   print sys.exc_type
36
 
...   print sys.exc_value
37
 
...   print sys.exc_value.path
38
 
bzrlib.errors.NotBranchError
39
 
Not a branch: /foo/bar
40
 
/foo/bar
41
 
 
42
 
Therefore:
43
 
 
44
 
 * create a new exception class for any class of error that can be
45
 
   usefully distinguished.
46
 
 
47
 
 * the printable form of an exception is generated by the base class
48
 
   __str__ method
49
18
"""
50
19
 
51
 
# based on Scott James Remnant's hct error classes
 
20
 
 
21
from bzrlib import symbol_versioning
 
22
from bzrlib.patches import (PatchSyntax, 
 
23
                            PatchConflict, 
 
24
                            MalformedPatchHeader,
 
25
                            MalformedHunkHeader,
 
26
                            MalformedLine,)
 
27
 
52
28
 
53
29
# TODO: is there any value in providing the .args field used by standard
54
30
# python exceptions?   A list of values with no names seems less useful 
58
34
# constructed to make sure it will succeed.  But that says nothing about
59
35
# exceptions that are never raised.
60
36
 
61
 
# TODO: Convert all the other error classes here to BzrNewError, and eliminate
62
 
# the old one.
 
37
# TODO: selftest assertRaises should probably also check that every error
 
38
# raised can be formatted as a string successfully, and without giving
 
39
# 'unprintable'.
63
40
 
64
41
 
65
42
class BzrError(StandardError):
 
43
    """
 
44
    Base class for errors raised by bzrlib.
 
45
 
 
46
    :cvar internal_error: if true (or absent) this was probably caused by a
 
47
    bzr bug and should be displayed with a traceback; if False this was
 
48
    probably a user or environment error and they don't need the gory details.
 
49
    (That can be overridden by -Derror on the command line.)
 
50
 
 
51
    :cvar _fmt: Format string to display the error; this is expanded
 
52
    by the instance's dict.
 
53
    """
 
54
    
 
55
    internal_error = False
 
56
 
 
57
    def __init__(self, msg=None, **kwds):
 
58
        """Construct a new BzrError.
 
59
 
 
60
        There are two alternative forms for constructing these objects.
 
61
        Either a preformatted string may be passed, or a set of named
 
62
        arguments can be given.  The first is for generic "user" errors which
 
63
        are not intended to be caught and so do not need a specific subclass.
 
64
        The second case is for use with subclasses that provide a _fmt format
 
65
        string to print the arguments.  
 
66
 
 
67
        Keyword arguments are taken as parameters to the error, which can 
 
68
        be inserted into the format string template.  It's recommended 
 
69
        that subclasses override the __init__ method to require specific 
 
70
        parameters.
 
71
 
 
72
        :param msg: If given, this is the literal complete text for the error,
 
73
        not subject to expansion.
 
74
        """
 
75
        StandardError.__init__(self)
 
76
        if msg is not None:
 
77
            ## symbol_versioning.warn(
 
78
            ##         'constructing a BzrError from a string was deprecated '
 
79
            ##         'in bzr 0.12; please raise a specific subclass instead',
 
80
            ##         DeprecationWarning,
 
81
            ##         stacklevel=2)
 
82
            self._preformatted_string = msg
 
83
        else:
 
84
            self._preformatted_string = None
 
85
            for key, value in kwds.items():
 
86
                setattr(self, key, value)
 
87
 
66
88
    def __str__(self):
67
 
        # XXX: Should we show the exception class in 
68
 
        # exceptions that don't provide their own message?  
69
 
        # maybe it should be done at a higher level
70
 
        ## n = self.__class__.__name__ + ': '
71
 
        n = ''
72
 
        if len(self.args) == 1:
73
 
            return str(self.args[0])
74
 
        elif len(self.args) == 2:
75
 
            # further explanation or suggestions
76
 
            try:
77
 
                return n + '\n  '.join([self.args[0]] + self.args[1])
78
 
            except TypeError:
79
 
                return n + "%r" % self
80
 
        else:
81
 
            return n + `self.args`
 
89
        s = getattr(self, '_preformatted_string', None)
 
90
        if s is not None:
 
91
            # contains a preformatted message; must be cast to plain str
 
92
            return str(s)
 
93
        try:
 
94
            fmt = self._get_format_string()
 
95
            if fmt:
 
96
                s = fmt % self.__dict__
 
97
                # __str__() should always return a 'str' object
 
98
                # never a 'unicode' object.
 
99
                if isinstance(s, unicode):
 
100
                    return s.encode('utf8')
 
101
                return s
 
102
        except (AttributeError, TypeError, NameError, ValueError, KeyError), e:
 
103
            return 'Unprintable exception %s: dict=%r, fmt=%r, error=%s' \
 
104
                % (self.__class__.__name__,
 
105
                   self.__dict__,
 
106
                   getattr(self, '_fmt', None),
 
107
                   str(e))
 
108
 
 
109
    def _get_format_string(self):
 
110
        """Return format string for this exception or None"""
 
111
        fmt = getattr(self, '_fmt', None)
 
112
        if fmt is not None:
 
113
            return fmt
 
114
        fmt = getattr(self, '__doc__', None)
 
115
        if fmt is not None:
 
116
            symbol_versioning.warn("%s uses its docstring as a format, "
 
117
                    "it should use _fmt instead" % self.__class__.__name__,
 
118
                    DeprecationWarning)
 
119
            # TODO: This should be deprecated when all exceptions have
 
120
            # been changed not to rely on this.
 
121
            return fmt
 
122
        return 'Unprintable exception %s: dict=%r, fmt=%r' \
 
123
            % (self.__class__.__name__,
 
124
               self.__dict__,
 
125
               getattr(self, '_fmt', None),
 
126
               )
82
127
 
83
128
 
84
129
class BzrNewError(BzrError):
85
 
    """bzr error"""
 
130
    """Deprecated error base class."""
86
131
    # base classes should override the docstring with their human-
87
132
    # readable explanation
88
133
 
89
 
    def __init__(self, **kwds):
 
134
    def __init__(self, *args, **kwds):
 
135
        # XXX: Use the underlying BzrError to always generate the args attribute
 
136
        # if it doesn't exist.  We can't use super here, because exceptions are
 
137
        # old-style classes in python2.4 (but new in 2.5).  --bmc, 20060426
 
138
        symbol_versioning.warn('BzrNewError was deprecated in bzr 0.12; '
 
139
             'please convert %s to use BzrError instead' 
 
140
             % self.__class__.__name__,
 
141
             DeprecationWarning,
 
142
             stacklevel=2)
 
143
        BzrError.__init__(self, *args)
90
144
        for key, value in kwds.items():
91
145
            setattr(self, key, value)
92
146
 
93
147
    def __str__(self):
94
148
        try:
95
 
            return self.__doc__ % self.__dict__
96
 
        except (NameError, ValueError, KeyError), e:
97
 
            return 'Unprintable exception %s: %s' \
98
 
                % (self.__class__.__name__, str(e))
99
 
 
100
 
 
101
 
class BzrCheckError(BzrNewError):
102
 
    """Internal check failed: %(message)s"""
 
149
            # __str__() should always return a 'str' object
 
150
            # never a 'unicode' object.
 
151
            s = self.__doc__ % self.__dict__
 
152
            if isinstance(s, unicode):
 
153
                return s.encode('utf8')
 
154
            return s
 
155
        except (TypeError, NameError, ValueError, KeyError), e:
 
156
            return 'Unprintable exception %s(%r): %s' \
 
157
                % (self.__class__.__name__,
 
158
                   self.__dict__, str(e))
 
159
 
 
160
 
 
161
class AlreadyBuilding(BzrError):
 
162
    
 
163
    _fmt = "The tree builder is already building a tree."
 
164
 
 
165
 
 
166
class BzrCheckError(BzrError):
 
167
    
 
168
    _fmt = "Internal check failed: %(message)s"
 
169
 
 
170
    internal_error = True
 
171
 
103
172
    def __init__(self, message):
 
173
        BzrError.__init__(self)
104
174
        self.message = message
105
175
 
106
176
 
107
 
class InvalidEntryName(BzrNewError):
108
 
    """Invalid entry name: %(name)s"""
 
177
class InvalidEntryName(BzrError):
 
178
    
 
179
    _fmt = "Invalid entry name: %(name)s"
 
180
 
 
181
    internal_error = True
 
182
 
109
183
    def __init__(self, name):
 
184
        BzrError.__init__(self)
110
185
        self.name = name
111
186
 
112
187
 
113
 
class InvalidRevisionNumber(BzrNewError):
114
 
    """Invalid revision number %(revno)d"""
 
188
class InvalidRevisionNumber(BzrError):
 
189
    
 
190
    _fmt = "Invalid revision number %(revno)s"
 
191
 
115
192
    def __init__(self, revno):
 
193
        BzrError.__init__(self)
116
194
        self.revno = revno
117
195
 
118
196
 
119
 
class InvalidRevisionId(BzrNewError):
120
 
    """Invalid revision-id"""
121
 
 
 
197
class InvalidRevisionId(BzrError):
 
198
 
 
199
    _fmt = "Invalid revision-id {%(revision_id)s} in %(branch)s"
 
200
 
 
201
    def __init__(self, revision_id, branch):
 
202
        # branch can be any string or object with __str__ defined
 
203
        BzrError.__init__(self)
 
204
        self.revision_id = revision_id
 
205
        self.branch = branch
 
206
 
 
207
 
 
208
class NoSuchId(BzrError):
 
209
 
 
210
    _fmt = "The file id %(file_id)s is not present in the tree %(tree)s."
 
211
    
 
212
    def __init__(self, tree, file_id):
 
213
        BzrError.__init__(self)
 
214
        self.file_id = file_id
 
215
        self.tree = tree
 
216
 
 
217
 
 
218
class InventoryModified(BzrError):
 
219
 
 
220
    _fmt = ("The current inventory for the tree %(tree)r has been modified, "
 
221
            "so a clean inventory cannot be read without data loss.")
 
222
 
 
223
    internal_error = True
 
224
 
 
225
    def __init__(self, tree):
 
226
        self.tree = tree
 
227
 
 
228
 
 
229
class NoWorkingTree(BzrError):
 
230
 
 
231
    _fmt = "No WorkingTree exists for %(base)s."
 
232
    
 
233
    def __init__(self, base):
 
234
        BzrError.__init__(self)
 
235
        self.base = base
 
236
 
 
237
 
 
238
class NotBuilding(BzrError):
 
239
 
 
240
    _fmt = "Not currently building a tree."
 
241
 
 
242
 
 
243
class NotLocalUrl(BzrError):
 
244
 
 
245
    _fmt = "%(url)s is not a local path."
 
246
 
 
247
    def __init__(self, url):
 
248
        self.url = url
 
249
 
 
250
 
 
251
class WorkingTreeAlreadyPopulated(BzrError):
 
252
 
 
253
    _fmt = """Working tree already populated in %(base)s"""
 
254
 
 
255
    internal_error = True
 
256
 
 
257
    def __init__(self, base):
 
258
        self.base = base
122
259
 
123
260
class BzrCommandError(BzrError):
124
 
    # Error from malformed user command
 
261
    """Error from user command"""
 
262
 
 
263
    internal_error = False
 
264
 
 
265
    # Error from malformed user command; please avoid raising this as a
 
266
    # generic exception not caused by user input.
 
267
    #
 
268
    # I think it's a waste of effort to differentiate between errors that
 
269
    # are not intended to be caught anyway.  UI code need not subclass
 
270
    # BzrCommandError, and non-UI code should not throw a subclass of
 
271
    # BzrCommandError.  ADHB 20051211
 
272
    def __init__(self, msg):
 
273
        # Object.__str__() must return a real string
 
274
        # returning a Unicode string is a python error.
 
275
        if isinstance(msg, unicode):
 
276
            self.msg = msg.encode('utf8')
 
277
        else:
 
278
            self.msg = msg
 
279
 
125
280
    def __str__(self):
126
 
        return self.args[0]
127
 
 
128
 
class StrictCommitFailed(Exception):
129
 
    """Commit refused because there are unknowns in the tree."""
130
 
 
131
 
class NotBranchError(BzrNewError):
132
 
    """Not a branch: %(path)s"""
 
281
        return self.msg
 
282
 
 
283
 
 
284
class NotWriteLocked(BzrError):
 
285
 
 
286
    _fmt = """%(not_locked)r is not write locked but needs to be."""
 
287
 
 
288
    def __init__(self, not_locked):
 
289
        self.not_locked = not_locked
 
290
 
 
291
 
 
292
class BzrOptionError(BzrCommandError):
 
293
 
 
294
    _fmt = "Error in command line options"
 
295
 
 
296
    
 
297
class StrictCommitFailed(BzrError):
 
298
 
 
299
    _fmt = "Commit refused because there are unknown files in the tree"
 
300
 
 
301
 
 
302
# XXX: Should be unified with TransportError; they seem to represent the
 
303
# same thing
 
304
class PathError(BzrError):
 
305
    
 
306
    _fmt = "Generic path error: %(path)r%(extra)s)"
 
307
 
 
308
    def __init__(self, path, extra=None):
 
309
        BzrError.__init__(self)
 
310
        self.path = path
 
311
        if extra:
 
312
            self.extra = ': ' + str(extra)
 
313
        else:
 
314
            self.extra = ''
 
315
 
 
316
 
 
317
class NoSuchFile(PathError):
 
318
 
 
319
    _fmt = "No such file: %(path)r%(extra)s"
 
320
 
 
321
 
 
322
class FileExists(PathError):
 
323
 
 
324
    _fmt = "File exists: %(path)r%(extra)s"
 
325
 
 
326
 
 
327
class DirectoryNotEmpty(PathError):
 
328
 
 
329
    _fmt = "Directory not empty: %(path)r%(extra)s"
 
330
 
 
331
 
 
332
class ReadingCompleted(BzrError):
 
333
    
 
334
    _fmt = ("The MediumRequest '%(request)s' has already had finish_reading "
 
335
            "called upon it - the request has been completed and no more "
 
336
            "data may be read.")
 
337
 
 
338
    internal_error = True
 
339
 
 
340
    def __init__(self, request):
 
341
        self.request = request
 
342
 
 
343
 
 
344
class ResourceBusy(PathError):
 
345
 
 
346
    _fmt = "Device or resource busy: %(path)r%(extra)s"
 
347
 
 
348
 
 
349
class PermissionDenied(PathError):
 
350
 
 
351
    _fmt = "Permission denied: %(path)r%(extra)s"
 
352
 
 
353
 
 
354
class InvalidURL(PathError):
 
355
 
 
356
    _fmt = "Invalid url supplied to transport: %(path)r%(extra)s"
 
357
 
 
358
 
 
359
class InvalidURLJoin(PathError):
 
360
 
 
361
    _fmt = "Invalid URL join request: %(args)s%(extra)s"
 
362
 
 
363
    def __init__(self, msg, base, args):
 
364
        PathError.__init__(self, base, msg)
 
365
        self.args = [base] + list(args)
 
366
 
 
367
 
 
368
class UnsupportedProtocol(PathError):
 
369
 
 
370
    _fmt = 'Unsupported protocol for url "%(path)s"%(extra)s'
 
371
 
 
372
    def __init__(self, url, extra):
 
373
        PathError.__init__(self, url, extra=extra)
 
374
 
 
375
 
 
376
class ShortReadvError(PathError):
 
377
 
 
378
    _fmt = "readv() read %(actual)s bytes rather than %(length)s bytes at %(offset)s for %(path)s%(extra)s"
 
379
 
 
380
    internal_error = True
 
381
 
 
382
    def __init__(self, path, offset, length, actual, extra=None):
 
383
        PathError.__init__(self, path, extra=extra)
 
384
        self.offset = offset
 
385
        self.length = length
 
386
        self.actual = actual
 
387
 
 
388
 
 
389
class PathNotChild(BzrError):
 
390
 
 
391
    _fmt = "Path %(path)r is not a child of path %(base)r%(extra)s"
 
392
 
 
393
    internal_error = True
 
394
 
 
395
    def __init__(self, path, base, extra=None):
 
396
        BzrError.__init__(self)
 
397
        self.path = path
 
398
        self.base = base
 
399
        if extra:
 
400
            self.extra = ': ' + str(extra)
 
401
        else:
 
402
            self.extra = ''
 
403
 
 
404
 
 
405
class InvalidNormalization(PathError):
 
406
 
 
407
    _fmt = "Path %(path)r is not unicode normalized"
 
408
 
 
409
 
 
410
# TODO: This is given a URL; we try to unescape it but doing that from inside
 
411
# the exception object is a bit undesirable.
 
412
# TODO: Probably this behavior of should be a common superclass 
 
413
class NotBranchError(PathError):
 
414
 
 
415
    _fmt = "Not a branch: %(path)s"
 
416
 
133
417
    def __init__(self, path):
134
 
        BzrNewError.__init__(self)
 
418
       import bzrlib.urlutils as urlutils
 
419
       self.path = urlutils.unescape_for_display(path, 'ascii')
 
420
 
 
421
 
 
422
class AlreadyBranchError(PathError):
 
423
 
 
424
    _fmt = "Already a branch: %(path)s."
 
425
 
 
426
 
 
427
class BranchExistsWithoutWorkingTree(PathError):
 
428
 
 
429
    _fmt = "Directory contains a branch, but no working tree \
 
430
(use bzr checkout if you wish to build a working tree): %(path)s"
 
431
 
 
432
 
 
433
class AtomicFileAlreadyClosed(PathError):
 
434
 
 
435
    _fmt = "'%(function)s' called on an AtomicFile after it was closed: %(path)s"
 
436
 
 
437
    def __init__(self, path, function):
 
438
        PathError.__init__(self, path=path, extra=None)
 
439
        self.function = function
 
440
 
 
441
 
 
442
class InaccessibleParent(PathError):
 
443
 
 
444
    _fmt = "Parent not accessible given base %(base)s and relative path %(path)s"
 
445
 
 
446
    def __init__(self, path, base):
 
447
        PathError.__init__(self, path)
 
448
        self.base = base
 
449
 
 
450
 
 
451
class NoRepositoryPresent(BzrError):
 
452
 
 
453
    _fmt = "No repository present: %(path)r"
 
454
    def __init__(self, bzrdir):
 
455
        BzrError.__init__(self)
 
456
        self.path = bzrdir.transport.clone('..').base
 
457
 
 
458
 
 
459
class FileInWrongBranch(BzrError):
 
460
 
 
461
    _fmt = "File %(path)s in not in branch %(branch_base)s."
 
462
 
 
463
    def __init__(self, branch, path):
 
464
        BzrError.__init__(self)
 
465
        self.branch = branch
 
466
        self.branch_base = branch.base
135
467
        self.path = path
136
468
 
137
469
 
138
470
class UnsupportedFormatError(BzrError):
139
 
    """Specified path is a bzr branch that we cannot read."""
140
 
    def __str__(self):
141
 
        return 'unsupported branch format: %s' % self.args[0]
142
 
 
143
 
 
144
 
class NotVersionedError(BzrNewError):
145
 
    """%(path)s is not versioned"""
 
471
    
 
472
    _fmt = "Unsupported branch format: %(format)s"
 
473
 
 
474
 
 
475
class UnknownFormatError(BzrError):
 
476
    
 
477
    _fmt = "Unknown branch format: %(format)r"
 
478
 
 
479
 
 
480
class IncompatibleFormat(BzrError):
 
481
    
 
482
    _fmt = "Format %(format)s is not compatible with .bzr version %(bzrdir)s."
 
483
 
 
484
    def __init__(self, format, bzrdir_format):
 
485
        BzrError.__init__(self)
 
486
        self.format = format
 
487
        self.bzrdir = bzrdir_format
 
488
 
 
489
 
 
490
class IncompatibleRevision(BzrError):
 
491
    
 
492
    _fmt = "Revision is not compatible with %(repo_format)s"
 
493
 
 
494
    def __init__(self, repo_format):
 
495
        BzrError.__init__(self)
 
496
        self.repo_format = repo_format
 
497
 
 
498
 
 
499
class NotVersionedError(BzrError):
 
500
 
 
501
    _fmt = "%(path)s is not versioned"
 
502
 
146
503
    def __init__(self, path):
147
 
        BzrNewError.__init__(self)
 
504
        BzrError.__init__(self)
148
505
        self.path = path
149
506
 
150
507
 
 
508
class PathsNotVersionedError(BzrError):
 
509
    # used when reporting several paths are not versioned
 
510
 
 
511
    _fmt = "Path(s) are not versioned: %(paths_as_string)s"
 
512
 
 
513
    def __init__(self, paths):
 
514
        from bzrlib.osutils import quotefn
 
515
        BzrError.__init__(self)
 
516
        self.paths = paths
 
517
        self.paths_as_string = ' '.join([quotefn(p) for p in paths])
 
518
 
 
519
 
 
520
class PathsDoNotExist(BzrError):
 
521
 
 
522
    _fmt = "Path(s) do not exist: %(paths_as_string)s"
 
523
 
 
524
    # used when reporting that paths are neither versioned nor in the working
 
525
    # tree
 
526
 
 
527
    def __init__(self, paths):
 
528
        # circular import
 
529
        from bzrlib.osutils import quotefn
 
530
        BzrError.__init__(self)
 
531
        self.paths = paths
 
532
        self.paths_as_string = ' '.join([quotefn(p) for p in paths])
 
533
 
 
534
 
151
535
class BadFileKindError(BzrError):
152
 
    """Specified file is of a kind that cannot be added.
153
 
 
154
 
    (For example a symlink or device file.)"""
155
 
 
156
 
 
157
 
class ForbiddenFileError(BzrError):
158
 
    """Cannot operate on a file because it is a control file."""
159
 
 
160
 
 
161
 
class LockError(Exception):
162
 
    """Lock error"""
 
536
 
 
537
    _fmt = "Cannot operate on %(filename)s of unsupported kind %(kind)s"
 
538
 
 
539
 
 
540
class ForbiddenControlFileError(BzrError):
 
541
 
 
542
    _fmt = "Cannot operate on %(filename)s because it is a control file"
 
543
 
 
544
 
 
545
class LockError(BzrError):
 
546
 
 
547
    _fmt = "Lock error: %(message)s"
 
548
 
163
549
    # All exceptions from the lock/unlock functions should be from
164
550
    # this exception class.  They will be translated as necessary. The
165
551
    # original exception is available as e.original_error
 
552
    #
 
553
    # New code should prefer to raise specific subclasses
 
554
    def __init__(self, message):
 
555
        self.message = message
166
556
 
167
557
 
168
558
class CommitNotPossible(LockError):
169
 
    """A commit was attempted but we do not have a write lock open."""
 
559
 
 
560
    _fmt = "A commit was attempted but we do not have a write lock open."
 
561
 
 
562
    def __init__(self):
 
563
        pass
170
564
 
171
565
 
172
566
class AlreadyCommitted(LockError):
173
 
    """A rollback was requested, but is not able to be accomplished."""
 
567
 
 
568
    _fmt = "A rollback was requested, but is not able to be accomplished."
 
569
 
 
570
    def __init__(self):
 
571
        pass
174
572
 
175
573
 
176
574
class ReadOnlyError(LockError):
177
 
    """A write attempt was made in a read only transaction."""
178
 
 
179
 
 
180
 
class PointlessCommit(BzrNewError):
181
 
    """No changes to commit"""
 
575
 
 
576
    _fmt = "A write attempt was made in a read only transaction on %(obj)s"
 
577
 
 
578
    def __init__(self, obj):
 
579
        self.obj = obj
 
580
 
 
581
 
 
582
class OutSideTransaction(BzrError):
 
583
 
 
584
    _fmt = "A transaction related operation was attempted after the transaction finished."
 
585
 
 
586
 
 
587
class ObjectNotLocked(LockError):
 
588
 
 
589
    _fmt = "%(obj)r is not locked"
 
590
 
 
591
    internal_error = True
 
592
 
 
593
    # this can indicate that any particular object is not locked; see also
 
594
    # LockNotHeld which means that a particular *lock* object is not held by
 
595
    # the caller -- perhaps they should be unified.
 
596
    def __init__(self, obj):
 
597
        self.obj = obj
 
598
 
 
599
 
 
600
class ReadOnlyObjectDirtiedError(ReadOnlyError):
 
601
 
 
602
    _fmt = "Cannot change object %(obj)r in read only transaction"
 
603
 
 
604
    def __init__(self, obj):
 
605
        self.obj = obj
 
606
 
 
607
 
 
608
class UnlockableTransport(LockError):
 
609
 
 
610
    _fmt = "Cannot lock: transport is read only: %(transport)s"
 
611
 
 
612
    def __init__(self, transport):
 
613
        self.transport = transport
 
614
 
 
615
 
 
616
class LockContention(LockError):
 
617
 
 
618
    _fmt = "Could not acquire lock %(lock)s"
 
619
    # TODO: show full url for lock, combining the transport and relative bits?
 
620
    
 
621
    def __init__(self, lock):
 
622
        self.lock = lock
 
623
 
 
624
 
 
625
class LockBroken(LockError):
 
626
 
 
627
    _fmt = "Lock was broken while still open: %(lock)s - check storage consistency!"
 
628
 
 
629
    def __init__(self, lock):
 
630
        self.lock = lock
 
631
 
 
632
 
 
633
class LockBreakMismatch(LockError):
 
634
 
 
635
    _fmt = "Lock was released and re-acquired before being broken: %(lock)s: held by %(holder)r, wanted to break %(target)r"
 
636
 
 
637
    def __init__(self, lock, holder, target):
 
638
        self.lock = lock
 
639
        self.holder = holder
 
640
        self.target = target
 
641
 
 
642
 
 
643
class LockNotHeld(LockError):
 
644
 
 
645
    _fmt = "Lock not held: %(lock)s"
 
646
 
 
647
    def __init__(self, lock):
 
648
        self.lock = lock
 
649
 
 
650
 
 
651
class PointlessCommit(BzrError):
 
652
 
 
653
    _fmt = "No changes to commit"
 
654
 
 
655
 
 
656
class UpgradeReadonly(BzrError):
 
657
 
 
658
    _fmt = "Upgrade URL cannot work with readonly URLs."
 
659
 
 
660
 
 
661
class UpToDateFormat(BzrError):
 
662
 
 
663
    _fmt = "The branch format %(format)s is already at the most recent format."
 
664
 
 
665
    def __init__(self, format):
 
666
        BzrError.__init__(self)
 
667
        self.format = format
 
668
 
 
669
 
 
670
class StrictCommitFailed(Exception):
 
671
 
 
672
    _fmt = "Commit refused because there are unknowns in the tree."
182
673
 
183
674
 
184
675
class NoSuchRevision(BzrError):
 
676
 
 
677
    _fmt = "Branch %(branch)s has no revision %(revision)s"
 
678
 
 
679
    internal_error = True
 
680
 
185
681
    def __init__(self, branch, revision):
186
 
        self.branch = branch
187
 
        self.revision = revision
188
 
        msg = "Branch %s has no revision %s" % (branch, revision)
189
 
        BzrError.__init__(self, msg)
 
682
        BzrError.__init__(self, branch=branch, revision=revision)
 
683
 
 
684
 
 
685
class NoSuchRevisionSpec(BzrError):
 
686
 
 
687
    _fmt = "No namespace registered for string: %(spec)r"
 
688
 
 
689
    def __init__(self, spec):
 
690
        BzrError.__init__(self, spec=spec)
 
691
 
 
692
 
 
693
class InvalidRevisionSpec(BzrError):
 
694
 
 
695
    _fmt = "Requested revision: %(spec)r does not exist in branch: %(branch)s%(extra)s"
 
696
 
 
697
    def __init__(self, spec, branch, extra=None):
 
698
        BzrError.__init__(self, branch=branch, spec=spec)
 
699
        if extra:
 
700
            self.extra = '\n' + str(extra)
 
701
        else:
 
702
            self.extra = ''
190
703
 
191
704
 
192
705
class HistoryMissing(BzrError):
193
 
    def __init__(self, branch, object_type, object_id):
194
 
        self.branch = branch
195
 
        BzrError.__init__(self,
196
 
                          '%s is missing %s {%s}'
197
 
                          % (branch, object_type, object_id))
 
706
 
 
707
    _fmt = "%(branch)s is missing %(object_type)s {%(object_id)s}"
198
708
 
199
709
 
200
710
class DivergedBranches(BzrError):
 
711
    
 
712
    _fmt = "These branches have diverged.  Use the merge command to reconcile them."""
 
713
 
 
714
    internal_error = False
 
715
 
201
716
    def __init__(self, branch1, branch2):
202
 
        BzrError.__init__(self, "These branches have diverged.")
203
717
        self.branch1 = branch1
204
718
        self.branch2 = branch2
205
719
 
206
720
 
207
 
class UnrelatedBranches(BzrCommandError):
208
 
    def __init__(self):
209
 
        msg = "Branches have no common ancestor, and no base revision"\
210
 
            " specified."
211
 
        BzrCommandError.__init__(self, msg)
 
721
class UnrelatedBranches(BzrError):
 
722
 
 
723
    _fmt = "Branches have no common ancestor, and no merge base revision was specified."
 
724
 
 
725
    internal_error = False
 
726
 
212
727
 
213
728
class NoCommonAncestor(BzrError):
 
729
    
 
730
    _fmt = "Revisions have no common ancestor: %(revision_a)s %(revision_b)s"
 
731
 
214
732
    def __init__(self, revision_a, revision_b):
215
 
        msg = "Revisions have no common ancestor: %s %s." \
216
 
            % (revision_a, revision_b) 
217
 
        BzrError.__init__(self, msg)
 
733
        self.revision_a = revision_a
 
734
        self.revision_b = revision_b
 
735
 
218
736
 
219
737
class NoCommonRoot(BzrError):
 
738
 
 
739
    _fmt = "Revisions are not derived from the same root: " \
 
740
           "%(revision_a)s %(revision_b)s."
 
741
 
220
742
    def __init__(self, revision_a, revision_b):
221
 
        msg = "Revisions are not derived from the same root: %s %s." \
222
 
            % (revision_a, revision_b) 
223
 
        BzrError.__init__(self, msg)
224
 
 
225
 
class NotAncestor(BzrError):
226
 
    def __init__(self, rev_id, not_ancestor_id):
227
 
        msg = "Revision %s is not an ancestor of %s" % (not_ancestor_id, 
228
 
                                                        rev_id)
229
 
        BzrError.__init__(self, msg)
230
 
        self.rev_id = rev_id
231
 
        self.not_ancestor_id = not_ancestor_id
232
 
 
233
 
 
234
 
class NotAncestor(BzrError):
235
 
    def __init__(self, rev_id, not_ancestor_id):
236
 
        self.rev_id = rev_id
237
 
        self.not_ancestor_id = not_ancestor_id
238
 
        msg = "Revision %s is not an ancestor of %s" % (not_ancestor_id, 
239
 
                                                        rev_id)
240
 
        BzrError.__init__(self, msg)
 
743
        BzrError.__init__(self, revision_a=revision_a, revision_b=revision_b)
 
744
 
 
745
 
 
746
class NotAncestor(BzrError):
 
747
 
 
748
    _fmt = "Revision %(rev_id)s is not an ancestor of %(not_ancestor_id)s"
 
749
 
 
750
    def __init__(self, rev_id, not_ancestor_id):
 
751
        BzrError.__init__(self, rev_id=rev_id,
 
752
            not_ancestor_id=not_ancestor_id)
241
753
 
242
754
 
243
755
class InstallFailed(BzrError):
 
756
 
244
757
    def __init__(self, revisions):
245
758
        msg = "Could not install revisions:\n%s" % " ,".join(revisions)
246
759
        BzrError.__init__(self, msg)
248
761
 
249
762
 
250
763
class AmbiguousBase(BzrError):
 
764
 
251
765
    def __init__(self, bases):
252
 
        msg = "The correct base is unclear, becase %s are all equally close" %\
 
766
        warn("BzrError AmbiguousBase has been deprecated as of bzrlib 0.8.",
 
767
                DeprecationWarning)
 
768
        msg = "The correct base is unclear, because %s are all equally close" %\
253
769
            ", ".join(bases)
254
770
        BzrError.__init__(self, msg)
255
771
        self.bases = bases
256
772
 
 
773
 
257
774
class NoCommits(BzrError):
 
775
 
 
776
    _fmt = "Branch %(branch)s has no commits."
 
777
 
258
778
    def __init__(self, branch):
259
 
        msg = "Branch %s has no commits." % branch
260
 
        BzrError.__init__(self, msg)
 
779
        BzrError.__init__(self, branch=branch)
 
780
 
261
781
 
262
782
class UnlistableStore(BzrError):
 
783
 
263
784
    def __init__(self, store):
264
785
        BzrError.__init__(self, "Store %s is not listable" % store)
265
786
 
 
787
 
 
788
 
266
789
class UnlistableBranch(BzrError):
 
790
 
267
791
    def __init__(self, br):
268
792
        BzrError.__init__(self, "Stores for branch %s are not listable" % br)
269
793
 
270
794
 
271
 
from bzrlib.weave import WeaveError, WeaveParentMismatch
 
795
class BoundBranchOutOfDate(BzrError):
 
796
 
 
797
    _fmt = "Bound branch %(branch)s is out of date with master branch %(master)s."
 
798
 
 
799
    def __init__(self, branch, master):
 
800
        BzrError.__init__(self)
 
801
        self.branch = branch
 
802
        self.master = master
 
803
 
 
804
        
 
805
class CommitToDoubleBoundBranch(BzrError):
 
806
 
 
807
    _fmt = "Cannot commit to branch %(branch)s. It is bound to %(master)s, which is bound to %(remote)s."
 
808
 
 
809
    def __init__(self, branch, master, remote):
 
810
        BzrError.__init__(self)
 
811
        self.branch = branch
 
812
        self.master = master
 
813
        self.remote = remote
 
814
 
 
815
 
 
816
class OverwriteBoundBranch(BzrError):
 
817
 
 
818
    _fmt = "Cannot pull --overwrite to a branch which is bound %(branch)s"
 
819
 
 
820
    def __init__(self, branch):
 
821
        BzrError.__init__(self)
 
822
        self.branch = branch
 
823
 
 
824
 
 
825
class BoundBranchConnectionFailure(BzrError):
 
826
 
 
827
    _fmt = "Unable to connect to target of bound branch %(branch)s => %(target)s: %(error)s"
 
828
 
 
829
    def __init__(self, branch, target, error):
 
830
        BzrError.__init__(self)
 
831
        self.branch = branch
 
832
        self.target = target
 
833
        self.error = error
 
834
 
 
835
 
 
836
class WeaveError(BzrError):
 
837
 
 
838
    _fmt = "Error in processing weave: %(message)s"
 
839
 
 
840
    def __init__(self, message=None):
 
841
        BzrError.__init__(self)
 
842
        self.message = message
 
843
 
 
844
 
 
845
class WeaveRevisionAlreadyPresent(WeaveError):
 
846
 
 
847
    _fmt = "Revision {%(revision_id)s} already present in %(weave)s"
 
848
 
 
849
    def __init__(self, revision_id, weave):
 
850
 
 
851
        WeaveError.__init__(self)
 
852
        self.revision_id = revision_id
 
853
        self.weave = weave
 
854
 
 
855
 
 
856
class WeaveRevisionNotPresent(WeaveError):
 
857
 
 
858
    _fmt = "Revision {%(revision_id)s} not present in %(weave)s"
 
859
 
 
860
    def __init__(self, revision_id, weave):
 
861
        WeaveError.__init__(self)
 
862
        self.revision_id = revision_id
 
863
        self.weave = weave
 
864
 
 
865
 
 
866
class WeaveFormatError(WeaveError):
 
867
 
 
868
    _fmt = "Weave invariant violated: %(what)s"
 
869
 
 
870
    def __init__(self, what):
 
871
        WeaveError.__init__(self)
 
872
        self.what = what
 
873
 
 
874
 
 
875
class WeaveParentMismatch(WeaveError):
 
876
 
 
877
    _fmt = "Parents are mismatched between two revisions."
 
878
    
 
879
 
 
880
class WeaveInvalidChecksum(WeaveError):
 
881
 
 
882
    _fmt = "Text did not match it's checksum: %(message)s"
 
883
 
 
884
 
 
885
class WeaveTextDiffers(WeaveError):
 
886
 
 
887
    _fmt = "Weaves differ on text content. Revision: {%(revision_id)s}, %(weave_a)s, %(weave_b)s"
 
888
 
 
889
    def __init__(self, revision_id, weave_a, weave_b):
 
890
        WeaveError.__init__(self)
 
891
        self.revision_id = revision_id
 
892
        self.weave_a = weave_a
 
893
        self.weave_b = weave_b
 
894
 
 
895
 
 
896
class WeaveTextDiffers(WeaveError):
 
897
 
 
898
    _fmt = "Weaves differ on text content. Revision: {%(revision_id)s}, %(weave_a)s, %(weave_b)s"
 
899
 
 
900
    def __init__(self, revision_id, weave_a, weave_b):
 
901
        WeaveError.__init__(self)
 
902
        self.revision_id = revision_id
 
903
        self.weave_a = weave_a
 
904
        self.weave_b = weave_b
 
905
 
 
906
 
 
907
class VersionedFileError(BzrError):
 
908
    
 
909
    _fmt = "Versioned file error"
 
910
 
 
911
 
 
912
class RevisionNotPresent(VersionedFileError):
 
913
    
 
914
    _fmt = "Revision {%(revision_id)s} not present in %(file_id)s."
 
915
 
 
916
    def __init__(self, revision_id, file_id):
 
917
        VersionedFileError.__init__(self)
 
918
        self.revision_id = revision_id
 
919
        self.file_id = file_id
 
920
 
 
921
 
 
922
class RevisionAlreadyPresent(VersionedFileError):
 
923
    
 
924
    _fmt = "Revision {%(revision_id)s} already present in %(file_id)s."
 
925
 
 
926
    def __init__(self, revision_id, file_id):
 
927
        VersionedFileError.__init__(self)
 
928
        self.revision_id = revision_id
 
929
        self.file_id = file_id
 
930
 
 
931
 
 
932
class KnitError(BzrError):
 
933
    
 
934
    _fmt = "Knit error"
 
935
 
 
936
 
 
937
class KnitHeaderError(KnitError):
 
938
 
 
939
    _fmt = "Knit header error: %(badline)r unexpected"
 
940
 
 
941
    def __init__(self, badline):
 
942
        KnitError.__init__(self)
 
943
        self.badline = badline
 
944
 
 
945
 
 
946
class KnitCorrupt(KnitError):
 
947
 
 
948
    _fmt = "Knit %(filename)s corrupt: %(how)s"
 
949
 
 
950
    def __init__(self, filename, how):
 
951
        KnitError.__init__(self)
 
952
        self.filename = filename
 
953
        self.how = how
 
954
 
 
955
 
 
956
class NoSuchExportFormat(BzrError):
 
957
    
 
958
    _fmt = "Export format %(format)r not supported"
 
959
 
 
960
    def __init__(self, format):
 
961
        BzrError.__init__(self)
 
962
        self.format = format
 
963
 
272
964
 
273
965
class TransportError(BzrError):
274
 
    """All errors thrown by Transport implementations should derive
275
 
    from this class.
276
 
    """
 
966
    
 
967
    _fmt = "Transport error: %(msg)s %(orig_error)s"
 
968
 
277
969
    def __init__(self, msg=None, orig_error=None):
278
970
        if msg is None and orig_error is not None:
279
971
            msg = str(orig_error)
280
 
        BzrError.__init__(self, msg)
 
972
        if orig_error is None:
 
973
            orig_error = ''
 
974
        if msg is None:
 
975
            msg =  ''
281
976
        self.msg = msg
282
977
        self.orig_error = orig_error
 
978
        BzrError.__init__(self)
 
979
 
 
980
 
 
981
class TooManyConcurrentRequests(BzrError):
 
982
 
 
983
    _fmt = ("The medium '%(medium)s' has reached its concurrent request limit. "
 
984
            "Be sure to finish_writing and finish_reading on the "
 
985
            "current request that is open.")
 
986
 
 
987
    internal_error = True
 
988
 
 
989
    def __init__(self, medium):
 
990
        self.medium = medium
 
991
 
 
992
 
 
993
class SmartProtocolError(TransportError):
 
994
 
 
995
    _fmt = "Generic bzr smart protocol error: %(details)s"
 
996
 
 
997
    def __init__(self, details):
 
998
        self.details = details
 
999
 
283
1000
 
284
1001
# A set of semi-meaningful errors which can be thrown
285
1002
class TransportNotPossible(TransportError):
286
 
    """This is for transports where a specific function is explicitly not
287
 
    possible. Such as pushing files to an HTTP server.
288
 
    """
289
 
    pass
290
 
 
291
 
class NonRelativePath(TransportError):
292
 
    """An absolute path was supplied, that could not be decoded into
293
 
    a relative path.
294
 
    """
295
 
    pass
296
 
 
297
 
class NoSuchFile(TransportError, IOError):
298
 
    """A get() was issued for a file that doesn't exist."""
299
 
 
300
 
    # XXX: Is multiple inheritance for exceptions really needed?
301
 
 
302
 
    def __str__(self):
303
 
        return 'no such file: ' + self.msg
304
 
 
305
 
    def __init__(self, msg=None, orig_error=None):
306
 
        import errno
307
 
        TransportError.__init__(self, msg=msg, orig_error=orig_error)
308
 
        IOError.__init__(self, errno.ENOENT, self.msg)
309
 
 
310
 
class FileExists(TransportError, OSError):
311
 
    """An operation was attempted, which would overwrite an entry,
312
 
    but overwritting is not supported.
313
 
 
314
 
    mkdir() can throw this, but put() just overwites existing files.
315
 
    """
316
 
    # XXX: Is multiple inheritance for exceptions really needed?
317
 
    def __init__(self, msg=None, orig_error=None):
318
 
        import errno
319
 
        TransportError.__init__(self, msg=msg, orig_error=orig_error)
320
 
        OSError.__init__(self, errno.EEXIST, self.msg)
321
 
 
322
 
class PermissionDenied(TransportError):
323
 
    """An operation cannot succeed because of a lack of permissions."""
324
 
    pass
 
1003
 
 
1004
    _fmt = "Transport operation not possible: %(msg)s %(orig_error)s"
 
1005
 
 
1006
 
 
1007
class ConnectionError(TransportError):
 
1008
 
 
1009
    _fmt = "Connection error: %(msg)s %(orig_error)s"
 
1010
 
 
1011
 
 
1012
class SocketConnectionError(ConnectionError):
 
1013
 
 
1014
    _fmt = "%(msg)s %(host)s%(port)s%(orig_error)s"
 
1015
 
 
1016
    def __init__(self, host, port=None, msg=None, orig_error=None):
 
1017
        if msg is None:
 
1018
            msg = 'Failed to connect to'
 
1019
        if orig_error is None:
 
1020
            orig_error = ''
 
1021
        else:
 
1022
            orig_error = '; ' + str(orig_error)
 
1023
        ConnectionError.__init__(self, msg=msg, orig_error=orig_error)
 
1024
        self.host = host
 
1025
        if port is None:
 
1026
            self.port = ''
 
1027
        else:
 
1028
            self.port = ':%s' % port
 
1029
 
325
1030
 
326
1031
class ConnectionReset(TransportError):
327
 
    """The connection has been closed."""
328
 
    pass
 
1032
 
 
1033
    _fmt = "Connection closed: %(msg)s %(orig_error)s"
 
1034
 
 
1035
 
 
1036
class InvalidRange(TransportError):
 
1037
 
 
1038
    _fmt = "Invalid range access in %(path)s at %(offset)s."
 
1039
    
 
1040
    def __init__(self, path, offset):
 
1041
        TransportError.__init__(self, ("Invalid range access in %s at %d"
 
1042
                                       % (path, offset)))
 
1043
        self.path = path
 
1044
        self.offset = offset
 
1045
 
 
1046
 
 
1047
class InvalidHttpResponse(TransportError):
 
1048
 
 
1049
    _fmt = "Invalid http response for %(path)s: %(msg)s"
 
1050
 
 
1051
    def __init__(self, path, msg, orig_error=None):
 
1052
        self.path = path
 
1053
        TransportError.__init__(self, msg, orig_error=orig_error)
 
1054
 
 
1055
 
 
1056
class InvalidHttpRange(InvalidHttpResponse):
 
1057
 
 
1058
    _fmt = "Invalid http range %(range)r for %(path)s: %(msg)s"
 
1059
    
 
1060
    def __init__(self, path, range, msg):
 
1061
        self.range = range
 
1062
        InvalidHttpResponse.__init__(self, path, msg)
 
1063
 
 
1064
 
 
1065
class InvalidHttpContentType(InvalidHttpResponse):
 
1066
 
 
1067
    _fmt = 'Invalid http Content-type "%(ctype)s" for %(path)s: %(msg)s'
 
1068
    
 
1069
    def __init__(self, path, ctype, msg):
 
1070
        self.ctype = ctype
 
1071
        InvalidHttpResponse.__init__(self, path, msg)
 
1072
 
329
1073
 
330
1074
class ConflictsInTree(BzrError):
331
 
    def __init__(self):
332
 
        BzrError.__init__(self, "Working tree has conflicts.")
 
1075
 
 
1076
    _fmt = "Working tree has conflicts."
 
1077
 
 
1078
 
 
1079
class ParseConfigError(BzrError):
 
1080
 
 
1081
    def __init__(self, errors, filename):
 
1082
        if filename is None:
 
1083
            filename = ""
 
1084
        message = "Error(s) parsing config file %s:\n%s" % \
 
1085
            (filename, ('\n'.join(e.message for e in errors)))
 
1086
        BzrError.__init__(self, message)
 
1087
 
 
1088
 
 
1089
class NoEmailInUsername(BzrError):
 
1090
 
 
1091
    _fmt = "%(username)r does not seem to contain a reasonable email address"
 
1092
 
 
1093
    def __init__(self, username):
 
1094
        BzrError.__init__(self)
 
1095
        self.username = username
 
1096
 
333
1097
 
334
1098
class SigningFailed(BzrError):
 
1099
 
 
1100
    _fmt = "Failed to gpg sign data with command %(command_line)r"
 
1101
 
335
1102
    def __init__(self, command_line):
336
 
        BzrError.__init__(self, "Failed to gpg sign data with command '%s'"
337
 
                               % command_line)
 
1103
        BzrError.__init__(self, command_line=command_line)
 
1104
 
 
1105
 
 
1106
class WorkingTreeNotRevision(BzrError):
 
1107
 
 
1108
    _fmt = ("The working tree for %(basedir)s has changed since" 
 
1109
            " the last commit, but weave merge requires that it be"
 
1110
            " unchanged")
 
1111
 
 
1112
    def __init__(self, tree):
 
1113
        BzrError.__init__(self, basedir=tree.basedir)
 
1114
 
 
1115
 
 
1116
class CantReprocessAndShowBase(BzrError):
 
1117
 
 
1118
    _fmt = "Can't reprocess and show base, because reprocessing obscures " \
 
1119
           "the relationship of conflicting lines to the base"
 
1120
 
 
1121
 
 
1122
class GraphCycleError(BzrError):
 
1123
 
 
1124
    _fmt = "Cycle in graph %(graph)r"
 
1125
 
 
1126
    def __init__(self, graph):
 
1127
        BzrError.__init__(self)
 
1128
        self.graph = graph
 
1129
 
 
1130
 
 
1131
class WritingCompleted(BzrError):
 
1132
 
 
1133
    _fmt = ("The MediumRequest '%(request)s' has already had finish_writing "
 
1134
            "called upon it - accept bytes may not be called anymore.")
 
1135
 
 
1136
    internal_error = True
 
1137
 
 
1138
    def __init__(self, request):
 
1139
        self.request = request
 
1140
 
 
1141
 
 
1142
class WritingNotComplete(BzrError):
 
1143
 
 
1144
    _fmt = ("The MediumRequest '%(request)s' has not has finish_writing "
 
1145
            "called upon it - until the write phase is complete no "
 
1146
            "data may be read.")
 
1147
 
 
1148
    internal_error = True
 
1149
 
 
1150
    def __init__(self, request):
 
1151
        self.request = request
 
1152
 
 
1153
 
 
1154
class NotConflicted(BzrError):
 
1155
 
 
1156
    _fmt = "File %(filename)s is not conflicted."
 
1157
 
 
1158
    def __init__(self, filename):
 
1159
        BzrError.__init__(self)
 
1160
        self.filename = filename
 
1161
 
 
1162
 
 
1163
class MediumNotConnected(BzrError):
 
1164
 
 
1165
    _fmt = """The medium '%(medium)s' is not connected."""
 
1166
 
 
1167
    internal_error = True
 
1168
 
 
1169
    def __init__(self, medium):
 
1170
        self.medium = medium
 
1171
 
 
1172
 
 
1173
class MustUseDecorated(Exception):
 
1174
    
 
1175
    _fmt = """A decorating function has requested its original command be used."""
 
1176
    
 
1177
 
 
1178
class NoBundleFound(BzrError):
 
1179
 
 
1180
    _fmt = "No bundle was found in %(filename)s"
 
1181
 
 
1182
    def __init__(self, filename):
 
1183
        BzrError.__init__(self)
 
1184
        self.filename = filename
 
1185
 
 
1186
 
 
1187
class BundleNotSupported(BzrError):
 
1188
 
 
1189
    _fmt = "Unable to handle bundle version %(version)s: %(msg)s"
 
1190
 
 
1191
    def __init__(self, version, msg):
 
1192
        BzrError.__init__(self)
 
1193
        self.version = version
 
1194
        self.msg = msg
 
1195
 
 
1196
 
 
1197
class MissingText(BzrError):
 
1198
 
 
1199
    _fmt = "Branch %(base)s is missing revision %(text_revision)s of %(file_id)s"
 
1200
 
 
1201
    def __init__(self, branch, text_revision, file_id):
 
1202
        BzrError.__init__(self)
 
1203
        self.branch = branch
 
1204
        self.base = branch.base
 
1205
        self.text_revision = text_revision
 
1206
        self.file_id = file_id
 
1207
 
 
1208
 
 
1209
class DuplicateKey(BzrError):
 
1210
 
 
1211
    _fmt = "Key %(key)s is already present in map"
 
1212
 
 
1213
 
 
1214
class MalformedTransform(BzrError):
 
1215
 
 
1216
    _fmt = "Tree transform is malformed %(conflicts)r"
 
1217
 
 
1218
 
 
1219
class NoFinalPath(BzrError):
 
1220
 
 
1221
    _fmt = ("No final name for trans_id %(trans_id)r\n"
 
1222
            "file-id: %(file_id)r\n"
 
1223
            "root trans-id: %(root_trans_id)r\n")
 
1224
 
 
1225
    def __init__(self, trans_id, transform):
 
1226
        self.trans_id = trans_id
 
1227
        self.file_id = transform.final_file_id(trans_id)
 
1228
        self.root_trans_id = transform.root
 
1229
 
 
1230
 
 
1231
class BzrBadParameter(BzrError):
 
1232
 
 
1233
    _fmt = "Bad parameter: %(param)r"
 
1234
 
 
1235
    # This exception should never be thrown, but it is a base class for all
 
1236
    # parameter-to-function errors.
 
1237
 
 
1238
    def __init__(self, param):
 
1239
        BzrError.__init__(self)
 
1240
        self.param = param
 
1241
 
 
1242
 
 
1243
class BzrBadParameterNotUnicode(BzrBadParameter):
 
1244
 
 
1245
    _fmt = "Parameter %(param)s is neither unicode nor utf8."
 
1246
 
 
1247
 
 
1248
class ReusingTransform(BzrError):
 
1249
 
 
1250
    _fmt = "Attempt to reuse a transform that has already been applied."
 
1251
 
 
1252
 
 
1253
class CantMoveRoot(BzrError):
 
1254
 
 
1255
    _fmt = "Moving the root directory is not supported at this time"
 
1256
 
 
1257
 
 
1258
class BzrBadParameterNotString(BzrBadParameter):
 
1259
 
 
1260
    _fmt = "Parameter %(param)s is not a string or unicode string."
 
1261
 
 
1262
 
 
1263
class BzrBadParameterMissing(BzrBadParameter):
 
1264
 
 
1265
    _fmt = "Parameter $(param)s is required but not present."
 
1266
 
 
1267
 
 
1268
class BzrBadParameterUnicode(BzrBadParameter):
 
1269
 
 
1270
    _fmt = "Parameter %(param)s is unicode but only byte-strings are permitted."
 
1271
 
 
1272
 
 
1273
class BzrBadParameterContainsNewline(BzrBadParameter):
 
1274
 
 
1275
    _fmt = "Parameter %(param)s contains a newline."
 
1276
 
 
1277
 
 
1278
class DependencyNotPresent(BzrError):
 
1279
 
 
1280
    _fmt = 'Unable to import library "%(library)s": %(error)s'
 
1281
 
 
1282
    def __init__(self, library, error):
 
1283
        BzrError.__init__(self, library=library, error=error)
 
1284
 
 
1285
 
 
1286
class ParamikoNotPresent(DependencyNotPresent):
 
1287
 
 
1288
    _fmt = "Unable to import paramiko (required for sftp support): %(error)s"
 
1289
 
 
1290
    def __init__(self, error):
 
1291
        DependencyNotPresent.__init__(self, 'paramiko', error)
 
1292
 
 
1293
 
 
1294
class PointlessMerge(BzrError):
 
1295
 
 
1296
    _fmt = "Nothing to merge."
 
1297
 
 
1298
 
 
1299
class UninitializableFormat(BzrError):
 
1300
 
 
1301
    _fmt = "Format %(format)s cannot be initialised by this version of bzr."
 
1302
 
 
1303
    def __init__(self, format):
 
1304
        BzrError.__init__(self)
 
1305
        self.format = format
 
1306
 
 
1307
 
 
1308
class BadConversionTarget(BzrError):
 
1309
 
 
1310
    _fmt = "Cannot convert to format %(format)s.  %(problem)s"
 
1311
 
 
1312
    def __init__(self, problem, format):
 
1313
        BzrError.__init__(self)
 
1314
        self.problem = problem
 
1315
        self.format = format
 
1316
 
 
1317
 
 
1318
class NoDiff(BzrError):
 
1319
 
 
1320
    _fmt = "Diff is not installed on this machine: %(msg)s"
 
1321
 
 
1322
    def __init__(self, msg):
 
1323
        BzrError.__init__(self, msg=msg)
 
1324
 
 
1325
 
 
1326
class NoDiff3(BzrError):
 
1327
 
 
1328
    _fmt = "Diff3 is not installed on this machine."
 
1329
 
 
1330
 
 
1331
class ExistingLimbo(BzrError):
 
1332
 
 
1333
    _fmt = """This tree contains left-over files from a failed operation.
 
1334
    Please examine %(limbo_dir)s to see if it contains any files you wish to
 
1335
    keep, and delete it when you are done."""
 
1336
    
 
1337
    def __init__(self, limbo_dir):
 
1338
       BzrError.__init__(self)
 
1339
       self.limbo_dir = limbo_dir
 
1340
 
 
1341
 
 
1342
class ImmortalLimbo(BzrError):
 
1343
 
 
1344
    _fmt = """Unable to delete transform temporary directory $(limbo_dir)s.
 
1345
    Please examine %(limbo_dir)s to see if it contains any files you wish to
 
1346
    keep, and delete it when you are done."""
 
1347
 
 
1348
    def __init__(self, limbo_dir):
 
1349
       BzrError.__init__(self)
 
1350
       self.limbo_dir = limbo_dir
 
1351
 
 
1352
 
 
1353
class OutOfDateTree(BzrError):
 
1354
 
 
1355
    _fmt = "Working tree is out of date, please run 'bzr update'."
 
1356
 
 
1357
    def __init__(self, tree):
 
1358
        BzrError.__init__(self)
 
1359
        self.tree = tree
 
1360
 
 
1361
 
 
1362
class MergeModifiedFormatError(BzrError):
 
1363
 
 
1364
    _fmt = "Error in merge modified format"
 
1365
 
 
1366
 
 
1367
class ConflictFormatError(BzrError):
 
1368
 
 
1369
    _fmt = "Format error in conflict listings"
 
1370
 
 
1371
 
 
1372
class CorruptRepository(BzrError):
 
1373
 
 
1374
    _fmt = """An error has been detected in the repository %(repo_path)s.
 
1375
Please run bzr reconcile on this repository."""
 
1376
 
 
1377
    def __init__(self, repo):
 
1378
        BzrError.__init__(self)
 
1379
        self.repo_path = repo.bzrdir.root_transport.base
 
1380
 
 
1381
 
 
1382
class UpgradeRequired(BzrError):
 
1383
 
 
1384
    _fmt = "To use this feature you must upgrade your branch at %(path)s."
 
1385
 
 
1386
    def __init__(self, path):
 
1387
        BzrError.__init__(self)
 
1388
        self.path = path
 
1389
 
 
1390
 
 
1391
class LocalRequiresBoundBranch(BzrError):
 
1392
 
 
1393
    _fmt = "Cannot perform local-only commits on unbound branches."
 
1394
 
 
1395
 
 
1396
class MissingProgressBarFinish(BzrError):
 
1397
 
 
1398
    _fmt = "A nested progress bar was not 'finished' correctly."
 
1399
 
 
1400
 
 
1401
class InvalidProgressBarType(BzrError):
 
1402
 
 
1403
    _fmt = """Environment variable BZR_PROGRESS_BAR='%(bar_type)s is not a supported type
 
1404
Select one of: %(valid_types)s"""
 
1405
 
 
1406
    def __init__(self, bar_type, valid_types):
 
1407
        BzrError.__init__(self, bar_type=bar_type, valid_types=valid_types)
 
1408
 
 
1409
 
 
1410
class UnsupportedOperation(BzrError):
 
1411
 
 
1412
    _fmt = "The method %(mname)s is not supported on objects of type %(tname)s."
 
1413
 
 
1414
    def __init__(self, method, method_self):
 
1415
        self.method = method
 
1416
        self.mname = method.__name__
 
1417
        self.tname = type(method_self).__name__
 
1418
 
 
1419
 
 
1420
class BinaryFile(BzrError):
 
1421
    
 
1422
    _fmt = "File is binary but should be text."
 
1423
 
 
1424
 
 
1425
class IllegalPath(BzrError):
 
1426
 
 
1427
    _fmt = "The path %(path)s is not permitted on this platform"
 
1428
 
 
1429
    def __init__(self, path):
 
1430
        BzrError.__init__(self)
 
1431
        self.path = path
 
1432
 
 
1433
 
 
1434
class TestamentMismatch(BzrError):
 
1435
 
 
1436
    _fmt = """Testament did not match expected value.  
 
1437
       For revision_id {%(revision_id)s}, expected {%(expected)s}, measured 
 
1438
       {%(measured)s}"""
 
1439
 
 
1440
    def __init__(self, revision_id, expected, measured):
 
1441
        self.revision_id = revision_id
 
1442
        self.expected = expected
 
1443
        self.measured = measured
 
1444
 
 
1445
 
 
1446
class NotABundle(BzrError):
 
1447
    
 
1448
    _fmt = "Not a bzr revision-bundle: %(text)r"
 
1449
 
 
1450
    def __init__(self, text):
 
1451
        BzrError.__init__(self)
 
1452
        self.text = text
 
1453
 
 
1454
 
 
1455
class BadBundle(BzrError): 
 
1456
    
 
1457
    _fmt = "Bad bzr revision-bundle: %(text)r"
 
1458
 
 
1459
    def __init__(self, text):
 
1460
        BzrError.__init__(self)
 
1461
        self.text = text
 
1462
 
 
1463
 
 
1464
class MalformedHeader(BadBundle): 
 
1465
    
 
1466
    _fmt = "Malformed bzr revision-bundle header: %(text)r"
 
1467
 
 
1468
 
 
1469
class MalformedPatches(BadBundle): 
 
1470
    
 
1471
    _fmt = "Malformed patches in bzr revision-bundle: %(text)r"
 
1472
 
 
1473
 
 
1474
class MalformedFooter(BadBundle): 
 
1475
    
 
1476
    _fmt = "Malformed footer in bzr revision-bundle: %(text)r"
 
1477
 
 
1478
 
 
1479
class UnsupportedEOLMarker(BadBundle):
 
1480
    
 
1481
    _fmt = "End of line marker was not \\n in bzr revision-bundle"    
 
1482
 
 
1483
    def __init__(self):
 
1484
        # XXX: BadBundle's constructor assumes there's explanatory text, 
 
1485
        # but for this there is not
 
1486
        BzrError.__init__(self)
 
1487
 
 
1488
 
 
1489
class IncompatibleBundleFormat(BzrError):
 
1490
    
 
1491
    _fmt = "Bundle format %(bundle_format)s is incompatible with %(other)s"
 
1492
 
 
1493
    def __init__(self, bundle_format, other):
 
1494
        BzrError.__init__(self)
 
1495
        self.bundle_format = bundle_format
 
1496
        self.other = other
 
1497
 
 
1498
 
 
1499
class BadInventoryFormat(BzrError):
 
1500
    
 
1501
    _fmt = "Root class for inventory serialization errors"
 
1502
 
 
1503
 
 
1504
class UnexpectedInventoryFormat(BadInventoryFormat):
 
1505
 
 
1506
    _fmt = "The inventory was not in the expected format:\n %(msg)s"
 
1507
 
 
1508
    def __init__(self, msg):
 
1509
        BadInventoryFormat.__init__(self, msg=msg)
 
1510
 
 
1511
 
 
1512
class NoSmartMedium(BzrError):
 
1513
 
 
1514
    _fmt = "The transport '%(transport)s' cannot tunnel the smart protocol."
 
1515
 
 
1516
    def __init__(self, transport):
 
1517
        self.transport = transport
 
1518
 
 
1519
 
 
1520
class NoSmartServer(NotBranchError):
 
1521
 
 
1522
    _fmt = "No smart server available at %(url)s"
 
1523
 
 
1524
    def __init__(self, url):
 
1525
        self.url = url
 
1526
 
 
1527
 
 
1528
class UnknownSSH(BzrError):
 
1529
 
 
1530
    _fmt = "Unrecognised value for BZR_SSH environment variable: %(vendor)s"
 
1531
 
 
1532
    def __init__(self, vendor):
 
1533
        BzrError.__init__(self)
 
1534
        self.vendor = vendor
 
1535
 
 
1536
 
 
1537
class GhostRevisionUnusableHere(BzrError):
 
1538
 
 
1539
    _fmt = "Ghost revision {%(revision_id)s} cannot be used here."
 
1540
 
 
1541
    def __init__(self, revision_id):
 
1542
        BzrError.__init__(self)
 
1543
        self.revision_id = revision_id
 
1544
 
 
1545
 
 
1546
class IllegalUseOfScopeReplacer(BzrError):
 
1547
 
 
1548
    _fmt = "ScopeReplacer object %(name)r was used incorrectly: %(msg)s%(extra)s"
 
1549
 
 
1550
    internal_error = True
 
1551
 
 
1552
    def __init__(self, name, msg, extra=None):
 
1553
        BzrError.__init__(self)
 
1554
        self.name = name
 
1555
        self.msg = msg
 
1556
        if extra:
 
1557
            self.extra = ': ' + str(extra)
 
1558
        else:
 
1559
            self.extra = ''
 
1560
 
 
1561
 
 
1562
class InvalidImportLine(BzrError):
 
1563
 
 
1564
    _fmt = "Not a valid import statement: %(msg)\n%(text)s"
 
1565
 
 
1566
    internal_error = True
 
1567
 
 
1568
    def __init__(self, text, msg):
 
1569
        BzrError.__init__(self)
 
1570
        self.text = text
 
1571
        self.msg = msg
 
1572
 
 
1573
 
 
1574
class ImportNameCollision(BzrError):
 
1575
 
 
1576
    _fmt = "Tried to import an object to the same name as an existing object. %(name)s"
 
1577
 
 
1578
    internal_error = True
 
1579
 
 
1580
    def __init__(self, name):
 
1581
        BzrError.__init__(self)
 
1582
        self.name = name