/brz/remove-bazaar

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

« back to all changes in this revision

Viewing changes to bzrlib/errors.py

  • Committer: Robey Pointer
  • Date: 2006-09-08 18:46:29 UTC
  • mto: This revision was merged to the branch mainline in revision 1996.
  • Revision ID: robey@lag.net-20060908184629-e3fc4c61ca21508c
pychecker is on crack; go back to using 'is None'.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2005, 2006 Canonical
 
2
#
 
3
# This program is free software; you can redistribute it and/or modify
 
4
# it under the terms of the GNU General Public License as published by
 
5
# the Free Software Foundation; either version 2 of the License, or
 
6
# (at your option) any later version.
 
7
#
 
8
# This program is distributed in the hope that it will be useful,
 
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
11
# GNU General Public License for more details.
 
12
#
 
13
# You should have received a copy of the GNU General Public License
 
14
# along with this program; if not, write to the Free Software
 
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
16
 
 
17
"""Exceptions for bzr, and reporting of them.
 
18
 
 
19
There are 3 different classes of error:
 
20
 
 
21
 * KeyboardInterrupt, and OSError with EPIPE - the program terminates 
 
22
   with an appropriate short message
 
23
 
 
24
 * User errors, indicating a problem caused by the user such as a bad URL.
 
25
   These are printed in a short form.
 
26
 
 
27
 * Internal unexpected errors, including most Python builtin errors
 
28
   and some raised from inside bzr.  These are printed with a full 
 
29
   traceback and an invitation to report the bug.
 
30
 
 
31
Exceptions are caught at a high level to report errors to the user, and
 
32
might also be caught inside the program.  Therefore it needs to be
 
33
possible to convert them to a meaningful string, and also for them to be
 
34
interrogated by the program.
 
35
 
 
36
Exceptions are defined such that the arguments given to the constructor
 
37
are stored in the object as properties of the same name.  When the
 
38
object is printed as a string, the doc string of the class is used as
 
39
a format string with the property dictionary available to it.
 
40
 
 
41
This means that exceptions can used like this:
 
42
 
 
43
>>> import sys
 
44
>>> try:
 
45
...   raise NotBranchError(path='/foo/bar')
 
46
... except:
 
47
...   print sys.exc_type
 
48
...   print sys.exc_value
 
49
...   path = getattr(sys.exc_value, 'path', None)
 
50
...   if path is not None:
 
51
...     print path
 
52
bzrlib.errors.NotBranchError
 
53
Not a branch: /foo/bar
 
54
/foo/bar
 
55
 
 
56
Therefore:
 
57
 
 
58
 * create a new exception class for any class of error that can be
 
59
   usefully distinguished.  If no callers are likely to want to catch
 
60
   one but not another, don't worry about them.
 
61
 
 
62
 * the __str__ method should generate something useful; BzrError provides
 
63
   a good default implementation
 
64
 
 
65
Exception strings should start with a capital letter and should not have a
 
66
final fullstop.
 
67
"""
 
68
 
 
69
from warnings import warn
 
70
 
 
71
from bzrlib.patches import (PatchSyntax, 
 
72
                            PatchConflict, 
 
73
                            MalformedPatchHeader,
 
74
                            MalformedHunkHeader,
 
75
                            MalformedLine,)
 
76
 
 
77
 
 
78
# based on Scott James Remnant's hct error classes
 
79
 
 
80
# TODO: is there any value in providing the .args field used by standard
 
81
# python exceptions?   A list of values with no names seems less useful 
 
82
# to me.
 
83
 
 
84
# TODO: Perhaps convert the exception to a string at the moment it's 
 
85
# constructed to make sure it will succeed.  But that says nothing about
 
86
# exceptions that are never raised.
 
87
 
 
88
# TODO: Convert all the other error classes here to BzrNewError, and eliminate
 
89
# the old one.
 
90
 
 
91
# TODO: The pattern (from hct) of using classes docstrings as message
 
92
# templates is cute but maybe not such a great idea - perhaps should have a
 
93
# separate static message_template.
 
94
 
 
95
 
 
96
class BzrError(StandardError):
 
97
    
 
98
    is_user_error = True
 
99
    
 
100
    def __str__(self):
 
101
        # XXX: Should we show the exception class in 
 
102
        # exceptions that don't provide their own message?  
 
103
        # maybe it should be done at a higher level
 
104
        ## n = self.__class__.__name__ + ': '
 
105
        n = ''
 
106
        if len(self.args) == 1:
 
107
            return str(self.args[0])
 
108
        elif len(self.args) == 2:
 
109
            # further explanation or suggestions
 
110
            try:
 
111
                return n + '\n  '.join([self.args[0]] + self.args[1])
 
112
            except TypeError:
 
113
                return n + "%r" % self
 
114
        else:
 
115
            return n + `self.args`
 
116
 
 
117
 
 
118
class BzrNewError(BzrError):
 
119
    """bzr error"""
 
120
    # base classes should override the docstring with their human-
 
121
    # readable explanation
 
122
 
 
123
    def __init__(self, **kwds):
 
124
        for key, value in kwds.items():
 
125
            setattr(self, key, value)
 
126
 
 
127
    def __str__(self):
 
128
        try:
 
129
            # __str__() should always return a 'str' object
 
130
            # never a 'unicode' object.
 
131
            s = self.__doc__ % self.__dict__
 
132
            if isinstance(s, unicode):
 
133
                return s.encode('utf8')
 
134
            return s
 
135
        except (NameError, ValueError, KeyError), e:
 
136
            return 'Unprintable exception %s: %s' \
 
137
                % (self.__class__.__name__, str(e))
 
138
 
 
139
 
 
140
class BzrCheckError(BzrNewError):
 
141
    """Internal check failed: %(message)s"""
 
142
 
 
143
    is_user_error = False
 
144
 
 
145
    def __init__(self, message):
 
146
        BzrNewError.__init__(self)
 
147
        self.message = message
 
148
 
 
149
 
 
150
class InvalidEntryName(BzrNewError):
 
151
    """Invalid entry name: %(name)s"""
 
152
 
 
153
    is_user_error = False
 
154
 
 
155
    def __init__(self, name):
 
156
        BzrNewError.__init__(self)
 
157
        self.name = name
 
158
 
 
159
 
 
160
class InvalidRevisionNumber(BzrNewError):
 
161
    """Invalid revision number %(revno)d"""
 
162
    def __init__(self, revno):
 
163
        BzrNewError.__init__(self)
 
164
        self.revno = revno
 
165
 
 
166
 
 
167
class InvalidRevisionId(BzrNewError):
 
168
    """Invalid revision-id {%(revision_id)s} in %(branch)s"""
 
169
 
 
170
    def __init__(self, revision_id, branch):
 
171
        # branch can be any string or object with __str__ defined
 
172
        BzrNewError.__init__(self)
 
173
        self.revision_id = revision_id
 
174
        self.branch = branch
 
175
 
 
176
 
 
177
class NoWorkingTree(BzrNewError):
 
178
    """No WorkingTree exists for %(base)s."""
 
179
    
 
180
    def __init__(self, base):
 
181
        BzrNewError.__init__(self)
 
182
        self.base = base
 
183
 
 
184
 
 
185
class NotLocalUrl(BzrNewError):
 
186
    """%(url)s is not a local path."""
 
187
    
 
188
    def __init__(self, url):
 
189
        BzrNewError.__init__(self)
 
190
        self.url = url
 
191
 
 
192
 
 
193
class BzrCommandError(BzrNewError):
 
194
    """Error from user command"""
 
195
 
 
196
    is_user_error = True
 
197
 
 
198
    # Error from malformed user command; please avoid raising this as a
 
199
    # generic exception not caused by user input.
 
200
    #
 
201
    # I think it's a waste of effort to differentiate between errors that
 
202
    # are not intended to be caught anyway.  UI code need not subclass
 
203
    # BzrCommandError, and non-UI code should not throw a subclass of
 
204
    # BzrCommandError.  ADHB 20051211
 
205
    def __init__(self, msg):
 
206
        # Object.__str__() must return a real string
 
207
        # returning a Unicode string is a python error.
 
208
        if isinstance(msg, unicode):
 
209
            self.msg = msg.encode('utf8')
 
210
        else:
 
211
            self.msg = msg
 
212
 
 
213
    def __str__(self):
 
214
        return self.msg
 
215
 
 
216
 
 
217
class BzrOptionError(BzrCommandError):
 
218
    """Error in command line options"""
 
219
 
 
220
    
 
221
class StrictCommitFailed(BzrNewError):
 
222
    """Commit refused because there are unknown files in the tree"""
 
223
 
 
224
 
 
225
# XXX: Should be unified with TransportError; they seem to represent the
 
226
# same thing
 
227
class PathError(BzrNewError):
 
228
    """Generic path error: %(path)r%(extra)s)"""
 
229
 
 
230
    def __init__(self, path, extra=None):
 
231
        BzrNewError.__init__(self)
 
232
        self.path = path
 
233
        if extra:
 
234
            self.extra = ': ' + str(extra)
 
235
        else:
 
236
            self.extra = ''
 
237
 
 
238
 
 
239
class NoSuchFile(PathError):
 
240
    """No such file: %(path)r%(extra)s"""
 
241
 
 
242
 
 
243
class FileExists(PathError):
 
244
    """File exists: %(path)r%(extra)s"""
 
245
 
 
246
 
 
247
class DirectoryNotEmpty(PathError):
 
248
    """Directory not empty: %(path)r%(extra)s"""
 
249
 
 
250
 
 
251
class ResourceBusy(PathError):
 
252
    """Device or resource busy: %(path)r%(extra)s"""
 
253
 
 
254
 
 
255
class PermissionDenied(PathError):
 
256
    """Permission denied: %(path)r%(extra)s"""
 
257
 
 
258
 
 
259
class InvalidURL(PathError):
 
260
    """Invalid url supplied to transport: %(path)r%(extra)s"""
 
261
 
 
262
 
 
263
class InvalidURLJoin(PathError):
 
264
    """Invalid URL join request: %(args)s%(extra)s"""
 
265
 
 
266
    def __init__(self, msg, base, args):
 
267
        PathError.__init__(self, base, msg)
 
268
        self.args = [base]
 
269
        self.args.extend(args)
 
270
 
 
271
 
 
272
class UnsupportedProtocol(PathError):
 
273
    """Unsupported protocol for url "%(path)s"%(extra)s"""
 
274
 
 
275
    def __init__(self, url, extra):
 
276
        PathError.__init__(self, url, extra=extra)
 
277
 
 
278
 
 
279
class PathNotChild(BzrNewError):
 
280
    """Path %(path)r is not a child of path %(base)r%(extra)s"""
 
281
 
 
282
    is_user_error = False
 
283
 
 
284
    def __init__(self, path, base, extra=None):
 
285
        BzrNewError.__init__(self)
 
286
        self.path = path
 
287
        self.base = base
 
288
        if extra:
 
289
            self.extra = ': ' + str(extra)
 
290
        else:
 
291
            self.extra = ''
 
292
 
 
293
 
 
294
class InvalidNormalization(PathError):
 
295
    """Path %(path)r is not unicode normalized"""
 
296
 
 
297
 
 
298
# TODO: This is given a URL; we try to unescape it but doing that from inside
 
299
# the exception object is a bit undesirable.
 
300
# TODO: Probably this behavior of should be a common superclass 
 
301
class NotBranchError(PathError):
 
302
    """Not a branch: %(path)s"""
 
303
 
 
304
    def __init__(self, path):
 
305
       import bzrlib.urlutils as urlutils
 
306
       self.path = urlutils.unescape_for_display(path, 'ascii')
 
307
 
 
308
 
 
309
class AlreadyBranchError(PathError):
 
310
    """Already a branch: %(path)s."""
 
311
 
 
312
 
 
313
class BranchExistsWithoutWorkingTree(PathError):
 
314
    """Directory contains a branch, but no working tree \
 
315
(use bzr checkout if you wish to build a working tree): %(path)s"""
 
316
 
 
317
 
 
318
class AtomicFileAlreadyClosed(PathError):
 
319
    """'%(function)s' called on an AtomicFile after it was closed: %(path)s"""
 
320
 
 
321
    def __init__(self, path, function):
 
322
        PathError.__init__(self, path=path, extra=None)
 
323
        self.function = function
 
324
 
 
325
 
 
326
class InaccessibleParent(PathError):
 
327
    """Parent not accessible given base %(base)s and relative path %(path)s"""
 
328
 
 
329
    def __init__(self, path, base):
 
330
        PathError.__init__(self, path)
 
331
        self.base = base
 
332
 
 
333
 
 
334
class NoRepositoryPresent(BzrNewError):
 
335
    """No repository present: %(path)r"""
 
336
    def __init__(self, bzrdir):
 
337
        BzrNewError.__init__(self)
 
338
        self.path = bzrdir.transport.clone('..').base
 
339
 
 
340
 
 
341
class FileInWrongBranch(BzrNewError):
 
342
    """File %(path)s in not in branch %(branch_base)s."""
 
343
 
 
344
    def __init__(self, branch, path):
 
345
        BzrNewError.__init__(self)
 
346
        self.branch = branch
 
347
        self.branch_base = branch.base
 
348
        self.path = path
 
349
 
 
350
 
 
351
class UnsupportedFormatError(BzrNewError):
 
352
    """Unsupported branch format: %(format)s"""
 
353
 
 
354
 
 
355
class UnknownFormatError(BzrNewError):
 
356
    """Unknown branch format: %(format)r"""
 
357
 
 
358
 
 
359
class IncompatibleFormat(BzrNewError):
 
360
    """Format %(format)s is not compatible with .bzr version %(bzrdir)s."""
 
361
 
 
362
    def __init__(self, format, bzrdir_format):
 
363
        BzrNewError.__init__(self)
 
364
        self.format = format
 
365
        self.bzrdir = bzrdir_format
 
366
 
 
367
 
 
368
class NotVersionedError(BzrNewError):
 
369
    """%(path)s is not versioned"""
 
370
    def __init__(self, path):
 
371
        BzrNewError.__init__(self)
 
372
        self.path = path
 
373
 
 
374
 
 
375
class PathsNotVersionedError(BzrNewError):
 
376
    # used when reporting several paths are not versioned
 
377
    """Path(s) are not versioned: %(paths_as_string)s"""
 
378
 
 
379
    def __init__(self, paths):
 
380
        from bzrlib.osutils import quotefn
 
381
        BzrNewError.__init__(self)
 
382
        self.paths = paths
 
383
        self.paths_as_string = ' '.join([quotefn(p) for p in paths])
 
384
 
 
385
 
 
386
class PathsDoNotExist(BzrNewError):
 
387
    """Path(s) do not exist: %(paths_as_string)s"""
 
388
 
 
389
    # used when reporting that paths are neither versioned nor in the working
 
390
    # tree
 
391
 
 
392
    def __init__(self, paths):
 
393
        # circular import
 
394
        from bzrlib.osutils import quotefn
 
395
        BzrNewError.__init__(self)
 
396
        self.paths = paths
 
397
        self.paths_as_string = ' '.join([quotefn(p) for p in paths])
 
398
 
 
399
 
 
400
class BadFileKindError(BzrNewError):
 
401
    """Cannot operate on %(filename)s of unsupported kind %(kind)s"""
 
402
 
 
403
 
 
404
class ForbiddenControlFileError(BzrNewError):
 
405
    """Cannot operate on %(filename)s because it is a control file"""
 
406
 
 
407
 
 
408
class LockError(BzrNewError):
 
409
    """Lock error: %(message)s"""
 
410
    # All exceptions from the lock/unlock functions should be from
 
411
    # this exception class.  They will be translated as necessary. The
 
412
    # original exception is available as e.original_error
 
413
    #
 
414
    # New code should prefer to raise specific subclasses
 
415
    def __init__(self, message):
 
416
        self.message = message
 
417
 
 
418
 
 
419
class CommitNotPossible(LockError):
 
420
    """A commit was attempted but we do not have a write lock open."""
 
421
    def __init__(self):
 
422
        pass
 
423
 
 
424
 
 
425
class AlreadyCommitted(LockError):
 
426
    """A rollback was requested, but is not able to be accomplished."""
 
427
    def __init__(self):
 
428
        pass
 
429
 
 
430
 
 
431
class ReadOnlyError(LockError):
 
432
    """A write attempt was made in a read only transaction on %(obj)s"""
 
433
    def __init__(self, obj):
 
434
        self.obj = obj
 
435
 
 
436
 
 
437
class OutSideTransaction(BzrNewError):
 
438
    """A transaction related operation was attempted after the transaction finished."""
 
439
 
 
440
 
 
441
class ObjectNotLocked(LockError):
 
442
    """%(obj)r is not locked"""
 
443
 
 
444
    is_user_error = False
 
445
 
 
446
    # this can indicate that any particular object is not locked; see also
 
447
    # LockNotHeld which means that a particular *lock* object is not held by
 
448
    # the caller -- perhaps they should be unified.
 
449
    def __init__(self, obj):
 
450
        self.obj = obj
 
451
 
 
452
 
 
453
class ReadOnlyObjectDirtiedError(ReadOnlyError):
 
454
    """Cannot change object %(obj)r in read only transaction"""
 
455
    def __init__(self, obj):
 
456
        self.obj = obj
 
457
 
 
458
 
 
459
class UnlockableTransport(LockError):
 
460
    """Cannot lock: transport is read only: %(transport)s"""
 
461
    def __init__(self, transport):
 
462
        self.transport = transport
 
463
 
 
464
 
 
465
class LockContention(LockError):
 
466
    """Could not acquire lock %(lock)s"""
 
467
    # TODO: show full url for lock, combining the transport and relative bits?
 
468
    def __init__(self, lock):
 
469
        self.lock = lock
 
470
 
 
471
 
 
472
class LockBroken(LockError):
 
473
    """Lock was broken while still open: %(lock)s - check storage consistency!"""
 
474
    def __init__(self, lock):
 
475
        self.lock = lock
 
476
 
 
477
 
 
478
class LockBreakMismatch(LockError):
 
479
    """Lock was released and re-acquired before being broken: %(lock)s: held by %(holder)r, wanted to break %(target)r"""
 
480
    def __init__(self, lock, holder, target):
 
481
        self.lock = lock
 
482
        self.holder = holder
 
483
        self.target = target
 
484
 
 
485
 
 
486
class LockNotHeld(LockError):
 
487
    """Lock not held: %(lock)s"""
 
488
    def __init__(self, lock):
 
489
        self.lock = lock
 
490
 
 
491
 
 
492
class PointlessCommit(BzrNewError):
 
493
    """No changes to commit"""
 
494
 
 
495
 
 
496
class UpgradeReadonly(BzrNewError):
 
497
    """Upgrade URL cannot work with readonly URL's."""
 
498
 
 
499
 
 
500
class UpToDateFormat(BzrNewError):
 
501
    """The branch format %(format)s is already at the most recent format."""
 
502
 
 
503
    def __init__(self, format):
 
504
        BzrNewError.__init__(self)
 
505
        self.format = format
 
506
 
 
507
 
 
508
class StrictCommitFailed(Exception):
 
509
    """Commit refused because there are unknowns in the tree."""
 
510
 
 
511
 
 
512
class NoSuchRevision(BzrNewError):
 
513
    """Branch %(branch)s has no revision %(revision)s"""
 
514
 
 
515
    is_user_error = False
 
516
 
 
517
    def __init__(self, branch, revision):
 
518
        BzrNewError.__init__(self, branch=branch, revision=revision)
 
519
 
 
520
 
 
521
class NoSuchRevisionSpec(BzrNewError):
 
522
    """No namespace registered for string: %(spec)r"""
 
523
 
 
524
    def __init__(self, spec):
 
525
        BzrNewError.__init__(self, spec=spec)
 
526
 
 
527
 
 
528
class InvalidRevisionSpec(BzrNewError):
 
529
    """Requested revision: '%(spec)s' does not exist in branch:
 
530
%(branch)s%(extra)s"""
 
531
 
 
532
    def __init__(self, spec, branch, extra=None):
 
533
        BzrNewError.__init__(self, branch=branch, spec=spec)
 
534
        if extra:
 
535
            self.extra = '\n' + str(extra)
 
536
        else:
 
537
            self.extra = ''
 
538
 
 
539
 
 
540
class HistoryMissing(BzrError):
 
541
    def __init__(self, branch, object_type, object_id):
 
542
        self.branch = branch
 
543
        BzrError.__init__(self,
 
544
                          '%s is missing %s {%s}'
 
545
                          % (branch, object_type, object_id))
 
546
 
 
547
 
 
548
class DivergedBranches(BzrNewError):
 
549
    "These branches have diverged.  Use the merge command to reconcile them."""
 
550
 
 
551
    is_user_error = True
 
552
 
 
553
    def __init__(self, branch1, branch2):
 
554
        self.branch1 = branch1
 
555
        self.branch2 = branch2
 
556
 
 
557
 
 
558
class UnrelatedBranches(BzrNewError):
 
559
    "Branches have no common ancestor, and no merge base revision was specified."
 
560
 
 
561
    is_user_error = True
 
562
 
 
563
 
 
564
class NoCommonAncestor(BzrNewError):
 
565
    "Revisions have no common ancestor: %(revision_a)s %(revision_b)s"
 
566
 
 
567
    def __init__(self, revision_a, revision_b):
 
568
        self.revision_a = revision_a
 
569
        self.revision_b = revision_b
 
570
 
 
571
 
 
572
class NoCommonRoot(BzrError):
 
573
    def __init__(self, revision_a, revision_b):
 
574
        msg = "Revisions are not derived from the same root: %s %s." \
 
575
            % (revision_a, revision_b) 
 
576
        BzrError.__init__(self, msg)
 
577
 
 
578
 
 
579
 
 
580
class NotAncestor(BzrError):
 
581
    def __init__(self, rev_id, not_ancestor_id):
 
582
        msg = "Revision %s is not an ancestor of %s" % (not_ancestor_id, 
 
583
                                                        rev_id)
 
584
        BzrError.__init__(self, msg)
 
585
        self.rev_id = rev_id
 
586
        self.not_ancestor_id = not_ancestor_id
 
587
 
 
588
 
 
589
class InstallFailed(BzrError):
 
590
    def __init__(self, revisions):
 
591
        msg = "Could not install revisions:\n%s" % " ,".join(revisions)
 
592
        BzrError.__init__(self, msg)
 
593
        self.revisions = revisions
 
594
 
 
595
 
 
596
class AmbiguousBase(BzrError):
 
597
    def __init__(self, bases):
 
598
        warn("BzrError AmbiguousBase has been deprecated as of bzrlib 0.8.",
 
599
                DeprecationWarning)
 
600
        msg = "The correct base is unclear, because %s are all equally close" %\
 
601
            ", ".join(bases)
 
602
        BzrError.__init__(self, msg)
 
603
        self.bases = bases
 
604
 
 
605
 
 
606
class NoCommits(BzrNewError):
 
607
    """Branch %(branch)s has no commits."""
 
608
 
 
609
    def __init__(self, branch):
 
610
        BzrNewError.__init__(self, branch=branch)
 
611
 
 
612
 
 
613
class UnlistableStore(BzrError):
 
614
    def __init__(self, store):
 
615
        BzrError.__init__(self, "Store %s is not listable" % store)
 
616
 
 
617
 
 
618
 
 
619
class UnlistableBranch(BzrError):
 
620
    def __init__(self, br):
 
621
        BzrError.__init__(self, "Stores for branch %s are not listable" % br)
 
622
 
 
623
 
 
624
class BoundBranchOutOfDate(BzrNewError):
 
625
    """Bound branch %(branch)s is out of date with master branch %(master)s."""
 
626
    def __init__(self, branch, master):
 
627
        BzrNewError.__init__(self)
 
628
        self.branch = branch
 
629
        self.master = master
 
630
 
 
631
        
 
632
class CommitToDoubleBoundBranch(BzrNewError):
 
633
    """Cannot commit to branch %(branch)s. It is bound to %(master)s, which is bound to %(remote)s."""
 
634
    def __init__(self, branch, master, remote):
 
635
        BzrNewError.__init__(self)
 
636
        self.branch = branch
 
637
        self.master = master
 
638
        self.remote = remote
 
639
 
 
640
 
 
641
class OverwriteBoundBranch(BzrNewError):
 
642
    """Cannot pull --overwrite to a branch which is bound %(branch)s"""
 
643
    def __init__(self, branch):
 
644
        BzrNewError.__init__(self)
 
645
        self.branch = branch
 
646
 
 
647
 
 
648
class BoundBranchConnectionFailure(BzrNewError):
 
649
    """Unable to connect to target of bound branch %(branch)s => %(target)s: %(error)s"""
 
650
    def __init__(self, branch, target, error):
 
651
        BzrNewError.__init__(self)
 
652
        self.branch = branch
 
653
        self.target = target
 
654
        self.error = error
 
655
 
 
656
 
 
657
class WeaveError(BzrNewError):
 
658
    """Error in processing weave: %(message)s"""
 
659
 
 
660
    def __init__(self, message=None):
 
661
        BzrNewError.__init__(self)
 
662
        self.message = message
 
663
 
 
664
 
 
665
class WeaveRevisionAlreadyPresent(WeaveError):
 
666
    """Revision {%(revision_id)s} already present in %(weave)s"""
 
667
    def __init__(self, revision_id, weave):
 
668
 
 
669
        WeaveError.__init__(self)
 
670
        self.revision_id = revision_id
 
671
        self.weave = weave
 
672
 
 
673
 
 
674
class WeaveRevisionNotPresent(WeaveError):
 
675
    """Revision {%(revision_id)s} not present in %(weave)s"""
 
676
 
 
677
    def __init__(self, revision_id, weave):
 
678
        WeaveError.__init__(self)
 
679
        self.revision_id = revision_id
 
680
        self.weave = weave
 
681
 
 
682
 
 
683
class WeaveFormatError(WeaveError):
 
684
    """Weave invariant violated: %(what)s"""
 
685
 
 
686
    def __init__(self, what):
 
687
        WeaveError.__init__(self)
 
688
        self.what = what
 
689
 
 
690
 
 
691
class WeaveParentMismatch(WeaveError):
 
692
    """Parents are mismatched between two revisions."""
 
693
    
 
694
 
 
695
class WeaveInvalidChecksum(WeaveError):
 
696
    """Text did not match it's checksum: %(message)s"""
 
697
 
 
698
 
 
699
class WeaveTextDiffers(WeaveError):
 
700
    """Weaves differ on text content. Revision: {%(revision_id)s}, %(weave_a)s, %(weave_b)s"""
 
701
 
 
702
    def __init__(self, revision_id, weave_a, weave_b):
 
703
        WeaveError.__init__(self)
 
704
        self.revision_id = revision_id
 
705
        self.weave_a = weave_a
 
706
        self.weave_b = weave_b
 
707
 
 
708
 
 
709
class WeaveTextDiffers(WeaveError):
 
710
    """Weaves differ on text content. Revision: {%(revision_id)s}, %(weave_a)s, %(weave_b)s"""
 
711
 
 
712
    def __init__(self, revision_id, weave_a, weave_b):
 
713
        WeaveError.__init__(self)
 
714
        self.revision_id = revision_id
 
715
        self.weave_a = weave_a
 
716
        self.weave_b = weave_b
 
717
 
 
718
 
 
719
class VersionedFileError(BzrNewError):
 
720
    """Versioned file error."""
 
721
 
 
722
 
 
723
class RevisionNotPresent(VersionedFileError):
 
724
    """Revision {%(revision_id)s} not present in %(file_id)s."""
 
725
 
 
726
    def __init__(self, revision_id, file_id):
 
727
        VersionedFileError.__init__(self)
 
728
        self.revision_id = revision_id
 
729
        self.file_id = file_id
 
730
 
 
731
 
 
732
class RevisionAlreadyPresent(VersionedFileError):
 
733
    """Revision {%(revision_id)s} already present in %(file_id)s."""
 
734
 
 
735
    def __init__(self, revision_id, file_id):
 
736
        VersionedFileError.__init__(self)
 
737
        self.revision_id = revision_id
 
738
        self.file_id = file_id
 
739
 
 
740
 
 
741
class KnitError(BzrNewError):
 
742
    """Knit error"""
 
743
 
 
744
 
 
745
class KnitHeaderError(KnitError):
 
746
    """Knit header error: %(badline)r unexpected"""
 
747
 
 
748
    def __init__(self, badline):
 
749
        KnitError.__init__(self)
 
750
        self.badline = badline
 
751
 
 
752
 
 
753
class KnitCorrupt(KnitError):
 
754
    """Knit %(filename)s corrupt: %(how)s"""
 
755
 
 
756
    def __init__(self, filename, how):
 
757
        KnitError.__init__(self)
 
758
        self.filename = filename
 
759
        self.how = how
 
760
 
 
761
 
 
762
class NoSuchExportFormat(BzrNewError):
 
763
    """Export format %(format)r not supported"""
 
764
    def __init__(self, format):
 
765
        BzrNewError.__init__(self)
 
766
        self.format = format
 
767
 
 
768
 
 
769
class TransportError(BzrNewError):
 
770
    """Transport error: %(msg)s %(orig_error)s"""
 
771
 
 
772
    def __init__(self, msg=None, orig_error=None):
 
773
        if msg is None and orig_error is not None:
 
774
            msg = str(orig_error)
 
775
        if orig_error is None:
 
776
            orig_error = ''
 
777
        if msg is None:
 
778
            msg =  ''
 
779
        self.msg = msg
 
780
        self.orig_error = orig_error
 
781
        BzrNewError.__init__(self)
 
782
 
 
783
 
 
784
# A set of semi-meaningful errors which can be thrown
 
785
class TransportNotPossible(TransportError):
 
786
    """Transport operation not possible: %(msg)s %(orig_error)%"""
 
787
 
 
788
 
 
789
class ConnectionError(TransportError):
 
790
    """Connection error: %(msg)s %(orig_error)s"""
 
791
 
 
792
 
 
793
class ConnectionReset(TransportError):
 
794
    """Connection closed: %(msg)s %(orig_error)s"""
 
795
 
 
796
 
 
797
class InvalidRange(TransportError):
 
798
    """Invalid range access in %(path)s at %(offset)s."""
 
799
    
 
800
    def __init__(self, path, offset):
 
801
        TransportError.__init__(self, ("Invalid range access in %s at %d"
 
802
                                       % (path, offset)))
 
803
        self.path = path
 
804
        self.offset = offset
 
805
 
 
806
 
 
807
class InvalidHttpResponse(TransportError):
 
808
    """Invalid http response for %(path)s: %(msg)s"""
 
809
 
 
810
    def __init__(self, path, msg, orig_error=None):
 
811
        self.path = path
 
812
        TransportError.__init__(self, msg, orig_error=orig_error)
 
813
 
 
814
 
 
815
class InvalidHttpRange(InvalidHttpResponse):
 
816
    """Invalid http range "%(range)s" for %(path)s: %(msg)s"""
 
817
    
 
818
    def __init__(self, path, range, msg):
 
819
        self.range = range
 
820
        InvalidHttpResponse.__init__(self, path, msg)
 
821
 
 
822
 
 
823
class InvalidHttpContentType(InvalidHttpResponse):
 
824
    """Invalid http Content-type "%(ctype)s" for %(path)s: %(msg)s"""
 
825
    
 
826
    def __init__(self, path, ctype, msg):
 
827
        self.ctype = ctype
 
828
        InvalidHttpResponse.__init__(self, path, msg)
 
829
 
 
830
 
 
831
class ConflictsInTree(BzrError):
 
832
    def __init__(self):
 
833
        BzrError.__init__(self, "Working tree has conflicts.")
 
834
 
 
835
 
 
836
class ParseConfigError(BzrError):
 
837
    def __init__(self, errors, filename):
 
838
        if filename is None:
 
839
            filename = ""
 
840
        message = "Error(s) parsing config file %s:\n%s" % \
 
841
            (filename, ('\n'.join(e.message for e in errors)))
 
842
        BzrError.__init__(self, message)
 
843
 
 
844
 
 
845
class SigningFailed(BzrError):
 
846
    def __init__(self, command_line):
 
847
        BzrError.__init__(self, "Failed to gpg sign data with command '%s'"
 
848
                               % command_line)
 
849
 
 
850
 
 
851
class WorkingTreeNotRevision(BzrError):
 
852
    def __init__(self, tree):
 
853
        BzrError.__init__(self, "The working tree for %s has changed since"
 
854
                          " last commit, but weave merge requires that it be"
 
855
                          " unchanged." % tree.basedir)
 
856
 
 
857
 
 
858
class CantReprocessAndShowBase(BzrNewError):
 
859
    """Can't reprocess and show base.
 
860
Reprocessing obscures relationship of conflicting lines to base."""
 
861
 
 
862
 
 
863
class GraphCycleError(BzrNewError):
 
864
    """Cycle in graph %(graph)r"""
 
865
    def __init__(self, graph):
 
866
        BzrNewError.__init__(self)
 
867
        self.graph = graph
 
868
 
 
869
 
 
870
class NotConflicted(BzrNewError):
 
871
    """File %(filename)s is not conflicted."""
 
872
 
 
873
    def __init__(self, filename):
 
874
        BzrNewError.__init__(self)
 
875
        self.filename = filename
 
876
 
 
877
 
 
878
class MustUseDecorated(Exception):
 
879
    """A decorating function has requested its original command be used.
 
880
    
 
881
    This should never escape bzr, so does not need to be printable.
 
882
    """
 
883
 
 
884
 
 
885
class NoBundleFound(BzrNewError):
 
886
    """No bundle was found in %(filename)s"""
 
887
    def __init__(self, filename):
 
888
        BzrNewError.__init__(self)
 
889
        self.filename = filename
 
890
 
 
891
 
 
892
class BundleNotSupported(BzrNewError):
 
893
    """Unable to handle bundle version %(version)s: %(msg)s"""
 
894
    def __init__(self, version, msg):
 
895
        BzrNewError.__init__(self)
 
896
        self.version = version
 
897
        self.msg = msg
 
898
 
 
899
 
 
900
class MissingText(BzrNewError):
 
901
    """Branch %(base)s is missing revision %(text_revision)s of %(file_id)s"""
 
902
 
 
903
    def __init__(self, branch, text_revision, file_id):
 
904
        BzrNewError.__init__(self)
 
905
        self.branch = branch
 
906
        self.base = branch.base
 
907
        self.text_revision = text_revision
 
908
        self.file_id = file_id
 
909
 
 
910
 
 
911
class DuplicateKey(BzrNewError):
 
912
    """Key %(key)s is already present in map"""
 
913
 
 
914
 
 
915
class MalformedTransform(BzrNewError):
 
916
    """Tree transform is malformed %(conflicts)r"""
 
917
 
 
918
 
 
919
class BzrBadParameter(BzrNewError):
 
920
    """A bad parameter : %(param)s is not usable.
 
921
    
 
922
    This exception should never be thrown, but it is a base class for all
 
923
    parameter-to-function errors.
 
924
    """
 
925
    def __init__(self, param):
 
926
        BzrNewError.__init__(self)
 
927
        self.param = param
 
928
 
 
929
 
 
930
class BzrBadParameterNotUnicode(BzrBadParameter):
 
931
    """Parameter %(param)s is neither unicode nor utf8."""
 
932
 
 
933
 
 
934
class ReusingTransform(BzrNewError):
 
935
    """Attempt to reuse a transform that has already been applied."""
 
936
 
 
937
 
 
938
class CantMoveRoot(BzrNewError):
 
939
    """Moving the root directory is not supported at this time"""
 
940
 
 
941
 
 
942
class BzrBadParameterNotString(BzrBadParameter):
 
943
    """Parameter %(param)s is not a string or unicode string."""
 
944
 
 
945
 
 
946
class BzrBadParameterMissing(BzrBadParameter):
 
947
    """Parameter $(param)s is required but not present."""
 
948
 
 
949
 
 
950
class BzrBadParameterUnicode(BzrBadParameter):
 
951
    """Parameter %(param)s is unicode but only byte-strings are permitted."""
 
952
 
 
953
 
 
954
class BzrBadParameterContainsNewline(BzrBadParameter):
 
955
    """Parameter %(param)s contains a newline."""
 
956
 
 
957
 
 
958
class DependencyNotPresent(BzrNewError):
 
959
    """Unable to import library "%(library)s": %(error)s"""
 
960
 
 
961
    def __init__(self, library, error):
 
962
        BzrNewError.__init__(self, library=library, error=error)
 
963
 
 
964
 
 
965
class ParamikoNotPresent(DependencyNotPresent):
 
966
    """Unable to import paramiko (required for sftp support): %(error)s"""
 
967
 
 
968
    def __init__(self, error):
 
969
        DependencyNotPresent.__init__(self, 'paramiko', error)
 
970
 
 
971
 
 
972
class UninitializableFormat(BzrNewError):
 
973
    """Format %(format)s cannot be initialised by this version of bzr."""
 
974
 
 
975
    def __init__(self, format):
 
976
        BzrNewError.__init__(self)
 
977
        self.format = format
 
978
 
 
979
 
 
980
class NoDiff(BzrNewError):
 
981
    """Diff is not installed on this machine: %(msg)s"""
 
982
 
 
983
    def __init__(self, msg):
 
984
        BzrNewError.__init__(self, msg=msg)
 
985
 
 
986
 
 
987
class NoDiff3(BzrNewError):
 
988
    """Diff3 is not installed on this machine."""
 
989
 
 
990
 
 
991
class ExistingLimbo(BzrNewError):
 
992
    """This tree contains left-over files from a failed operation.
 
993
    Please examine %(limbo_dir)s to see if it contains any files you wish to
 
994
    keep, and delete it when you are done.
 
995
    """
 
996
    def __init__(self, limbo_dir):
 
997
       BzrNewError.__init__(self)
 
998
       self.limbo_dir = limbo_dir
 
999
 
 
1000
 
 
1001
class ImmortalLimbo(BzrNewError):
 
1002
    """Unable to delete transform temporary directory $(limbo_dir)s.
 
1003
    Please examine %(limbo_dir)s to see if it contains any files you wish to
 
1004
    keep, and delete it when you are done.
 
1005
    """
 
1006
    def __init__(self, limbo_dir):
 
1007
       BzrNewError.__init__(self)
 
1008
       self.limbo_dir = limbo_dir
 
1009
 
 
1010
 
 
1011
class OutOfDateTree(BzrNewError):
 
1012
    """Working tree is out of date, please run 'bzr update'."""
 
1013
 
 
1014
    def __init__(self, tree):
 
1015
        BzrNewError.__init__(self)
 
1016
        self.tree = tree
 
1017
 
 
1018
 
 
1019
class MergeModifiedFormatError(BzrNewError):
 
1020
    """Error in merge modified format"""
 
1021
 
 
1022
 
 
1023
class ConflictFormatError(BzrNewError):
 
1024
    """Format error in conflict listings"""
 
1025
 
 
1026
 
 
1027
class CorruptRepository(BzrNewError):
 
1028
    """An error has been detected in the repository %(repo_path)s.
 
1029
Please run bzr reconcile on this repository."""
 
1030
 
 
1031
    def __init__(self, repo):
 
1032
        BzrNewError.__init__(self)
 
1033
        self.repo_path = repo.bzrdir.root_transport.base
 
1034
 
 
1035
 
 
1036
class UpgradeRequired(BzrNewError):
 
1037
    """To use this feature you must upgrade your branch at %(path)s."""
 
1038
 
 
1039
    def __init__(self, path):
 
1040
        BzrNewError.__init__(self)
 
1041
        self.path = path
 
1042
 
 
1043
 
 
1044
class LocalRequiresBoundBranch(BzrNewError):
 
1045
    """Cannot perform local-only commits on unbound branches."""
 
1046
 
 
1047
 
 
1048
class MissingProgressBarFinish(BzrNewError):
 
1049
    """A nested progress bar was not 'finished' correctly."""
 
1050
 
 
1051
 
 
1052
class InvalidProgressBarType(BzrNewError):
 
1053
    """Environment variable BZR_PROGRESS_BAR='%(bar_type)s is not a supported type
 
1054
Select one of: %(valid_types)s"""
 
1055
 
 
1056
    def __init__(self, bar_type, valid_types):
 
1057
        BzrNewError.__init__(self, bar_type=bar_type, valid_types=valid_types)
 
1058
 
 
1059
 
 
1060
class UnsupportedOperation(BzrNewError):
 
1061
    """The method %(mname)s is not supported on objects of type %(tname)s."""
 
1062
    def __init__(self, method, method_self):
 
1063
        self.method = method
 
1064
        self.mname = method.__name__
 
1065
        self.tname = type(method_self).__name__
 
1066
 
 
1067
 
 
1068
class BinaryFile(BzrNewError):
 
1069
    """File is binary but should be text."""
 
1070
 
 
1071
 
 
1072
class IllegalPath(BzrNewError):
 
1073
    """The path %(path)s is not permitted on this platform"""
 
1074
 
 
1075
    def __init__(self, path):
 
1076
        BzrNewError.__init__(self)
 
1077
        self.path = path
 
1078
 
 
1079
 
 
1080
class TestamentMismatch(BzrNewError):
 
1081
    """Testament did not match expected value.  
 
1082
       For revision_id {%(revision_id)s}, expected {%(expected)s}, measured 
 
1083
       {%(measured)s}
 
1084
    """
 
1085
    def __init__(self, revision_id, expected, measured):
 
1086
        self.revision_id = revision_id
 
1087
        self.expected = expected
 
1088
        self.measured = measured
 
1089
 
 
1090
 
 
1091
class NotABundle(BzrNewError):
 
1092
    """Not a bzr revision-bundle: %(text)r"""
 
1093
 
 
1094
    def __init__(self, text):
 
1095
        BzrNewError.__init__(self)
 
1096
        self.text = text
 
1097
 
 
1098
 
 
1099
class BadBundle(BzrNewError): 
 
1100
    """Bad bzr revision-bundle: %(text)r"""
 
1101
 
 
1102
    def __init__(self, text):
 
1103
        BzrNewError.__init__(self)
 
1104
        self.text = text
 
1105
 
 
1106
 
 
1107
class MalformedHeader(BadBundle): 
 
1108
    """Malformed bzr revision-bundle header: %(text)r"""
 
1109
 
 
1110
    def __init__(self, text):
 
1111
        BzrNewError.__init__(self)
 
1112
        self.text = text
 
1113
 
 
1114
 
 
1115
class MalformedPatches(BadBundle): 
 
1116
    """Malformed patches in bzr revision-bundle: %(text)r"""
 
1117
 
 
1118
    def __init__(self, text):
 
1119
        BzrNewError.__init__(self)
 
1120
        self.text = text
 
1121
 
 
1122
 
 
1123
class MalformedFooter(BadBundle): 
 
1124
    """Malformed footer in bzr revision-bundle: %(text)r"""
 
1125
 
 
1126
    def __init__(self, text):
 
1127
        BzrNewError.__init__(self)
 
1128
        self.text = text
 
1129
 
 
1130
 
 
1131
class UnsupportedEOLMarker(BadBundle):
 
1132
    """End of line marker was not \\n in bzr revision-bundle"""    
 
1133
 
 
1134
    def __init__(self):
 
1135
        BzrNewError.__init__(self)
 
1136
 
 
1137
 
 
1138
class UnknownSSH(BzrNewError):
 
1139
    """Unrecognised value for BZR_SSH environment variable: %(vendor)s"""
 
1140
 
 
1141
    def __init__(self, vendor):
 
1142
        BzrNewError.__init__(self)
 
1143
        self.vendor = vendor
 
1144
 
 
1145
 
 
1146
class GhostRevisionUnusableHere(BzrNewError):
 
1147
    """Ghost revision {%(revision_id)s} cannot be used here."""
 
1148
 
 
1149
    def __init__(self, revision_id):
 
1150
        BzrNewError.__init__(self)
 
1151
        self.revision_id = revision_id