/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

Roundtrip tree roots in bundles

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
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
...   path = getattr(sys.exc_value, 'path', None)
 
38
...   if path is not None:
 
39
...     print path
 
40
bzrlib.errors.NotBranchError
 
41
Not a branch: /foo/bar
 
42
/foo/bar
 
43
 
 
44
Therefore:
 
45
 
 
46
 * create a new exception class for any class of error that can be
 
47
   usefully distinguished.
 
48
 
 
49
 * the printable form of an exception is generated by the base class
 
50
   __str__ method
 
51
 
 
52
Exception strings should start with a capital letter and not have a final
 
53
fullstop.
 
54
"""
 
55
 
 
56
from warnings import warn
 
57
 
 
58
from bzrlib.patches import (PatchSyntax, 
 
59
                            PatchConflict, 
 
60
                            MalformedPatchHeader,
 
61
                            MalformedHunkHeader,
 
62
                            MalformedLine,)
 
63
 
 
64
 
 
65
# based on Scott James Remnant's hct error classes
 
66
 
 
67
# TODO: is there any value in providing the .args field used by standard
 
68
# python exceptions?   A list of values with no names seems less useful 
 
69
# to me.
 
70
 
 
71
# TODO: Perhaps convert the exception to a string at the moment it's 
 
72
# constructed to make sure it will succeed.  But that says nothing about
 
73
# exceptions that are never raised.
 
74
 
 
75
# TODO: Convert all the other error classes here to BzrNewError, and eliminate
 
76
# the old one.
 
77
 
 
78
# TODO: The pattern (from hct) of using classes docstrings as message
 
79
# templates is cute but maybe not such a great idea - perhaps should have a
 
80
# separate static message_template.
 
81
 
 
82
 
 
83
class BzrError(StandardError):
 
84
    def __str__(self):
 
85
        # XXX: Should we show the exception class in 
 
86
        # exceptions that don't provide their own message?  
 
87
        # maybe it should be done at a higher level
 
88
        ## n = self.__class__.__name__ + ': '
 
89
        n = ''
 
90
        if len(self.args) == 1:
 
91
            return str(self.args[0])
 
92
        elif len(self.args) == 2:
 
93
            # further explanation or suggestions
 
94
            try:
 
95
                return n + '\n  '.join([self.args[0]] + self.args[1])
 
96
            except TypeError:
 
97
                return n + "%r" % self
 
98
        else:
 
99
            return n + `self.args`
 
100
 
 
101
 
 
102
class BzrNewError(BzrError):
 
103
    """bzr error"""
 
104
    # base classes should override the docstring with their human-
 
105
    # readable explanation
 
106
 
 
107
    def __init__(self, **kwds):
 
108
        for key, value in kwds.items():
 
109
            setattr(self, key, value)
 
110
 
 
111
    def __str__(self):
 
112
        try:
 
113
            return self.__doc__ % self.__dict__
 
114
        except (NameError, ValueError, KeyError), e:
 
115
            return 'Unprintable exception %s: %s' \
 
116
                % (self.__class__.__name__, str(e))
 
117
 
 
118
 
 
119
class BzrCheckError(BzrNewError):
 
120
    """Internal check failed: %(message)s"""
 
121
 
 
122
    def __init__(self, message):
 
123
        BzrNewError.__init__(self)
 
124
        self.message = message
 
125
 
 
126
 
 
127
class InvalidEntryName(BzrNewError):
 
128
    """Invalid entry name: %(name)s"""
 
129
    def __init__(self, name):
 
130
        BzrNewError.__init__(self)
 
131
        self.name = name
 
132
 
 
133
 
 
134
class InvalidRevisionNumber(BzrNewError):
 
135
    """Invalid revision number %(revno)d"""
 
136
    def __init__(self, revno):
 
137
        BzrNewError.__init__(self)
 
138
        self.revno = revno
 
139
 
 
140
 
 
141
class InvalidRevisionId(BzrNewError):
 
142
    """Invalid revision-id {%(revision_id)s} in %(branch)s"""
 
143
    def __init__(self, revision_id, branch):
 
144
        # branch can be any string or object with __str__ defined
 
145
        BzrNewError.__init__(self)
 
146
        self.revision_id = revision_id
 
147
        self.branch = branch
 
148
 
 
149
 
 
150
class NoWorkingTree(BzrNewError):
 
151
    """No WorkingTree exists for %(base)s."""
 
152
    
 
153
    def __init__(self, base):
 
154
        BzrNewError.__init__(self)
 
155
        self.base = base
 
156
 
 
157
 
 
158
class NotLocalUrl(BzrNewError):
 
159
    """%(url)s is not a local path."""
 
160
    
 
161
    def __init__(self, url):
 
162
        BzrNewError.__init__(self)
 
163
        self.url = url
 
164
 
 
165
 
 
166
class BzrCommandError(BzrError):
 
167
    # Error from malformed user command
 
168
    # This is being misused as a generic exception
 
169
    # pleae subclass. RBC 20051030
 
170
    #
 
171
    # I think it's a waste of effort to differentiate between errors that
 
172
    # are not intended to be caught anyway.  UI code need not subclass
 
173
    # BzrCommandError, and non-UI code should not throw a subclass of
 
174
    # BzrCommandError.  ADHB 20051211
 
175
    def __str__(self):
 
176
        return self.args[0]
 
177
 
 
178
 
 
179
class BzrOptionError(BzrCommandError):
 
180
    """Some missing or otherwise incorrect option was supplied."""
 
181
 
 
182
    
 
183
class StrictCommitFailed(Exception):
 
184
    """Commit refused because there are unknowns in the tree."""
 
185
 
 
186
 
 
187
# XXX: Should be unified with TransportError; they seem to represent the
 
188
# same thing
 
189
class PathError(BzrNewError):
 
190
    """Generic path error: %(path)r%(extra)s)"""
 
191
 
 
192
    def __init__(self, path, extra=None):
 
193
        BzrNewError.__init__(self)
 
194
        self.path = path
 
195
        if extra:
 
196
            self.extra = ': ' + str(extra)
 
197
        else:
 
198
            self.extra = ''
 
199
 
 
200
 
 
201
class NoSuchFile(PathError):
 
202
    """No such file: %(path)r%(extra)s"""
 
203
 
 
204
 
 
205
class FileExists(PathError):
 
206
    """File exists: %(path)r%(extra)s"""
 
207
 
 
208
 
 
209
class DirectoryNotEmpty(PathError):
 
210
    """Directory not empty: %(path)r%(extra)s"""
 
211
 
 
212
 
 
213
class ResourceBusy(PathError):
 
214
    """Device or resource busy: %(path)r%(extra)s"""
 
215
 
 
216
 
 
217
class PermissionDenied(PathError):
 
218
    """Permission denied: %(path)r%(extra)s"""
 
219
 
 
220
 
 
221
class PathNotChild(BzrNewError):
 
222
    """Path %(path)r is not a child of path %(base)r%(extra)s"""
 
223
    def __init__(self, path, base, extra=None):
 
224
        BzrNewError.__init__(self)
 
225
        self.path = path
 
226
        self.base = base
 
227
        if extra:
 
228
            self.extra = ': ' + str(extra)
 
229
        else:
 
230
            self.extra = ''
 
231
 
 
232
 
 
233
class NotBranchError(PathError):
 
234
    """Not a branch: %(path)s"""
 
235
 
 
236
 
 
237
class AlreadyBranchError(PathError):
 
238
    """Already a branch: %(path)s."""
 
239
 
 
240
 
 
241
class BranchExistsWithoutWorkingTree(PathError):
 
242
    """Directory contains a branch, but no working tree \
 
243
(use bzr checkout if you wish to build a working tree): %(path)s"""
 
244
 
 
245
 
 
246
class NoRepositoryPresent(BzrNewError):
 
247
    """No repository present: %(path)r"""
 
248
    def __init__(self, bzrdir):
 
249
        BzrNewError.__init__(self)
 
250
        self.path = bzrdir.transport.clone('..').base
 
251
 
 
252
 
 
253
class FileInWrongBranch(BzrNewError):
 
254
    """File %(path)s in not in branch %(branch_base)s."""
 
255
 
 
256
    def __init__(self, branch, path):
 
257
        BzrNewError.__init__(self)
 
258
        self.branch = branch
 
259
        self.branch_base = branch.base
 
260
        self.path = path
 
261
 
 
262
 
 
263
class UnsupportedFormatError(BzrError):
 
264
    """Specified path is a bzr branch that we recognize but cannot read."""
 
265
    def __str__(self):
 
266
        return 'unsupported branch format: %s' % self.args[0]
 
267
 
 
268
 
 
269
class UnknownFormatError(BzrError):
 
270
    """Specified path is a bzr branch whose format we do not recognize."""
 
271
    def __str__(self):
 
272
        return 'unknown branch format: %s' % self.args[0]
 
273
 
 
274
 
 
275
class IncompatibleFormat(BzrNewError):
 
276
    """Format %(format)s is not compatible with .bzr version %(bzrdir)s."""
 
277
 
 
278
    def __init__(self, format, bzrdir_format):
 
279
        BzrNewError.__init__(self)
 
280
        self.format = format
 
281
        self.bzrdir = bzrdir_format
 
282
 
 
283
 
 
284
class NotVersionedError(BzrNewError):
 
285
    """%(path)s is not versioned"""
 
286
    def __init__(self, path):
 
287
        BzrNewError.__init__(self)
 
288
        self.path = path
 
289
 
 
290
 
 
291
class PathsNotVersionedError(BzrNewError):
 
292
    # used when reporting several paths are not versioned
 
293
    """Path(s) are not versioned: %(paths_as_string)s"""
 
294
 
 
295
    def __init__(self, paths):
 
296
        from bzrlib.osutils import quotefn
 
297
        BzrNewError.__init__(self)
 
298
        self.paths = paths
 
299
        self.paths_as_string = ' '.join([quotefn(p) for p in paths])
 
300
 
 
301
 
 
302
class PathsDoNotExist(BzrNewError):
 
303
    """Path(s) do not exist: %(paths_as_string)s"""
 
304
 
 
305
    # used when reporting that paths are neither versioned nor in the working
 
306
    # tree
 
307
 
 
308
    def __init__(self, paths):
 
309
        # circular import
 
310
        from bzrlib.osutils import quotefn
 
311
        BzrNewError.__init__(self)
 
312
        self.paths = paths
 
313
        self.paths_as_string = ' '.join([quotefn(p) for p in paths])
 
314
 
 
315
 
 
316
class BadFileKindError(BzrError):
 
317
    """Specified file is of a kind that cannot be added.
 
318
 
 
319
    (For example a symlink or device file.)"""
 
320
 
 
321
 
 
322
class ForbiddenFileError(BzrError):
 
323
    """Cannot operate on a file because it is a control file."""
 
324
 
 
325
 
 
326
class LockError(BzrNewError):
 
327
    """Lock error: %(message)s"""
 
328
    # All exceptions from the lock/unlock functions should be from
 
329
    # this exception class.  They will be translated as necessary. The
 
330
    # original exception is available as e.original_error
 
331
    #
 
332
    # New code should prefer to raise specific subclasses
 
333
    def __init__(self, message):
 
334
        self.message = message
 
335
 
 
336
 
 
337
class CommitNotPossible(LockError):
 
338
    """A commit was attempted but we do not have a write lock open."""
 
339
    def __init__(self):
 
340
        pass
 
341
 
 
342
 
 
343
class AlreadyCommitted(LockError):
 
344
    """A rollback was requested, but is not able to be accomplished."""
 
345
    def __init__(self):
 
346
        pass
 
347
 
 
348
 
 
349
class ReadOnlyError(LockError):
 
350
    """A write attempt was made in a read only transaction on %(obj)s"""
 
351
    def __init__(self, obj):
 
352
        self.obj = obj
 
353
 
 
354
 
 
355
class OutSideTransaction(BzrNewError):
 
356
    """A transaction related operation was attempted after the transaction finished."""
 
357
 
 
358
 
 
359
class ObjectNotLocked(LockError):
 
360
    """%(obj)r is not locked"""
 
361
    # this can indicate that any particular object is not locked; see also
 
362
    # LockNotHeld which means that a particular *lock* object is not held by
 
363
    # the caller -- perhaps they should be unified.
 
364
    def __init__(self, obj):
 
365
        self.obj = obj
 
366
 
 
367
 
 
368
class ReadOnlyObjectDirtiedError(ReadOnlyError):
 
369
    """Cannot change object %(obj)r in read only transaction"""
 
370
    def __init__(self, obj):
 
371
        self.obj = obj
 
372
 
 
373
 
 
374
class UnlockableTransport(LockError):
 
375
    """Cannot lock: transport is read only: %(transport)s"""
 
376
    def __init__(self, transport):
 
377
        self.transport = transport
 
378
 
 
379
 
 
380
class LockContention(LockError):
 
381
    """Could not acquire lock %(lock)s"""
 
382
    # TODO: show full url for lock, combining the transport and relative bits?
 
383
    def __init__(self, lock):
 
384
        self.lock = lock
 
385
 
 
386
 
 
387
class LockBroken(LockError):
 
388
    """Lock was broken while still open: %(lock)s - check storage consistency!"""
 
389
    def __init__(self, lock):
 
390
        self.lock = lock
 
391
 
 
392
 
 
393
class LockBreakMismatch(LockError):
 
394
    """Lock was released and re-acquired before being broken: %(lock)s: held by %(holder)r, wanted to break %(target)r"""
 
395
    def __init__(self, lock, holder, target):
 
396
        self.lock = lock
 
397
        self.holder = holder
 
398
        self.target = target
 
399
 
 
400
 
 
401
class LockNotHeld(LockError):
 
402
    """Lock not held: %(lock)s"""
 
403
    def __init__(self, lock):
 
404
        self.lock = lock
 
405
 
 
406
 
 
407
class PointlessCommit(BzrNewError):
 
408
    """No changes to commit"""
 
409
 
 
410
 
 
411
class UpgradeReadonly(BzrNewError):
 
412
    """Upgrade URL cannot work with readonly URL's."""
 
413
 
 
414
 
 
415
class UpToDateFormat(BzrNewError):
 
416
    """The branch format %(format)s is already at the most recent format."""
 
417
 
 
418
    def __init__(self, format):
 
419
        BzrNewError.__init__(self)
 
420
        self.format = format
 
421
 
 
422
 
 
423
 
 
424
class StrictCommitFailed(Exception):
 
425
    """Commit refused because there are unknowns in the tree."""
 
426
 
 
427
 
 
428
class NoSuchRevision(BzrError):
 
429
    def __init__(self, branch, revision):
 
430
        self.branch = branch
 
431
        self.revision = revision
 
432
        msg = "Branch %s has no revision %s" % (branch, revision)
 
433
        BzrError.__init__(self, msg)
 
434
 
 
435
 
 
436
class HistoryMissing(BzrError):
 
437
    def __init__(self, branch, object_type, object_id):
 
438
        self.branch = branch
 
439
        BzrError.__init__(self,
 
440
                          '%s is missing %s {%s}'
 
441
                          % (branch, object_type, object_id))
 
442
 
 
443
 
 
444
class DivergedBranches(BzrError):
 
445
 
 
446
    def __init__(self, branch1, branch2):
 
447
        BzrError.__init__(self, "These branches have diverged.  Try merge.")
 
448
        self.branch1 = branch1
 
449
        self.branch2 = branch2
 
450
 
 
451
 
 
452
class UnrelatedBranches(BzrCommandError):
 
453
    def __init__(self):
 
454
        msg = "Branches have no common ancestor, and no base revision"\
 
455
            " specified."
 
456
        BzrCommandError.__init__(self, msg)
 
457
 
 
458
 
 
459
class NoCommonAncestor(BzrError):
 
460
    def __init__(self, revision_a, revision_b):
 
461
        msg = "Revisions have no common ancestor: %s %s." \
 
462
            % (revision_a, revision_b) 
 
463
        BzrError.__init__(self, msg)
 
464
 
 
465
 
 
466
class NoCommonRoot(BzrError):
 
467
    def __init__(self, revision_a, revision_b):
 
468
        msg = "Revisions are not derived from the same root: %s %s." \
 
469
            % (revision_a, revision_b) 
 
470
        BzrError.__init__(self, msg)
 
471
 
 
472
 
 
473
 
 
474
class NotAncestor(BzrError):
 
475
    def __init__(self, rev_id, not_ancestor_id):
 
476
        msg = "Revision %s is not an ancestor of %s" % (not_ancestor_id, 
 
477
                                                        rev_id)
 
478
        BzrError.__init__(self, msg)
 
479
        self.rev_id = rev_id
 
480
        self.not_ancestor_id = not_ancestor_id
 
481
 
 
482
 
 
483
class InstallFailed(BzrError):
 
484
    def __init__(self, revisions):
 
485
        msg = "Could not install revisions:\n%s" % " ,".join(revisions)
 
486
        BzrError.__init__(self, msg)
 
487
        self.revisions = revisions
 
488
 
 
489
 
 
490
class AmbiguousBase(BzrError):
 
491
    def __init__(self, bases):
 
492
        warn("BzrError AmbiguousBase has been deprecated as of bzrlib 0.8.",
 
493
                DeprecationWarning)
 
494
        msg = "The correct base is unclear, becase %s are all equally close" %\
 
495
            ", ".join(bases)
 
496
        BzrError.__init__(self, msg)
 
497
        self.bases = bases
 
498
 
 
499
 
 
500
class NoCommits(BzrError):
 
501
    def __init__(self, branch):
 
502
        msg = "Branch %s has no commits." % branch
 
503
        BzrError.__init__(self, msg)
 
504
 
 
505
 
 
506
class UnlistableStore(BzrError):
 
507
    def __init__(self, store):
 
508
        BzrError.__init__(self, "Store %s is not listable" % store)
 
509
 
 
510
 
 
511
 
 
512
class UnlistableBranch(BzrError):
 
513
    def __init__(self, br):
 
514
        BzrError.__init__(self, "Stores for branch %s are not listable" % br)
 
515
 
 
516
 
 
517
class BoundBranchOutOfDate(BzrNewError):
 
518
    """Bound branch %(branch)s is out of date with master branch %(master)s."""
 
519
    def __init__(self, branch, master):
 
520
        BzrNewError.__init__(self)
 
521
        self.branch = branch
 
522
        self.master = master
 
523
 
 
524
        
 
525
class CommitToDoubleBoundBranch(BzrNewError):
 
526
    """Cannot commit to branch %(branch)s. It is bound to %(master)s, which is bound to %(remote)s."""
 
527
    def __init__(self, branch, master, remote):
 
528
        BzrNewError.__init__(self)
 
529
        self.branch = branch
 
530
        self.master = master
 
531
        self.remote = remote
 
532
 
 
533
 
 
534
class OverwriteBoundBranch(BzrNewError):
 
535
    """Cannot pull --overwrite to a branch which is bound %(branch)s"""
 
536
    def __init__(self, branch):
 
537
        BzrNewError.__init__(self)
 
538
        self.branch = branch
 
539
 
 
540
 
 
541
class BoundBranchConnectionFailure(BzrNewError):
 
542
    """Unable to connect to target of bound branch %(branch)s => %(target)s: %(error)s"""
 
543
    def __init__(self, branch, target, error):
 
544
        BzrNewError.__init__(self)
 
545
        self.branch = branch
 
546
        self.target = target
 
547
        self.error = error
 
548
 
 
549
 
 
550
class WeaveError(BzrNewError):
 
551
    """Error in processing weave: %(message)s"""
 
552
 
 
553
    def __init__(self, message=None):
 
554
        BzrNewError.__init__(self)
 
555
        self.message = message
 
556
 
 
557
 
 
558
class WeaveRevisionAlreadyPresent(WeaveError):
 
559
    """Revision {%(revision_id)s} already present in %(weave)s"""
 
560
    def __init__(self, revision_id, weave):
 
561
 
 
562
        WeaveError.__init__(self)
 
563
        self.revision_id = revision_id
 
564
        self.weave = weave
 
565
 
 
566
 
 
567
class WeaveRevisionNotPresent(WeaveError):
 
568
    """Revision {%(revision_id)s} not present in %(weave)s"""
 
569
 
 
570
    def __init__(self, revision_id, weave):
 
571
        WeaveError.__init__(self)
 
572
        self.revision_id = revision_id
 
573
        self.weave = weave
 
574
 
 
575
 
 
576
class WeaveFormatError(WeaveError):
 
577
    """Weave invariant violated: %(what)s"""
 
578
 
 
579
    def __init__(self, what):
 
580
        WeaveError.__init__(self)
 
581
        self.what = what
 
582
 
 
583
 
 
584
class WeaveParentMismatch(WeaveError):
 
585
    """Parents are mismatched between two revisions."""
 
586
    
 
587
 
 
588
class WeaveInvalidChecksum(WeaveError):
 
589
    """Text did not match it's checksum: %(message)s"""
 
590
 
 
591
 
 
592
class WeaveTextDiffers(WeaveError):
 
593
    """Weaves differ on text content. Revision: {%(revision_id)s}, %(weave_a)s, %(weave_b)s"""
 
594
 
 
595
    def __init__(self, revision_id, weave_a, weave_b):
 
596
        WeaveError.__init__(self)
 
597
        self.revision_id = revision_id
 
598
        self.weave_a = weave_a
 
599
        self.weave_b = weave_b
 
600
 
 
601
 
 
602
class WeaveTextDiffers(WeaveError):
 
603
    """Weaves differ on text content. Revision: {%(revision_id)s}, %(weave_a)s, %(weave_b)s"""
 
604
 
 
605
    def __init__(self, revision_id, weave_a, weave_b):
 
606
        WeaveError.__init__(self)
 
607
        self.revision_id = revision_id
 
608
        self.weave_a = weave_a
 
609
        self.weave_b = weave_b
 
610
 
 
611
 
 
612
class VersionedFileError(BzrNewError):
 
613
    """Versioned file error."""
 
614
 
 
615
 
 
616
class RevisionNotPresent(VersionedFileError):
 
617
    """Revision {%(revision_id)s} not present in %(file_id)s."""
 
618
 
 
619
    def __init__(self, revision_id, file_id):
 
620
        VersionedFileError.__init__(self)
 
621
        self.revision_id = revision_id
 
622
        self.file_id = file_id
 
623
 
 
624
 
 
625
class RevisionAlreadyPresent(VersionedFileError):
 
626
    """Revision {%(revision_id)s} already present in %(file_id)s."""
 
627
 
 
628
    def __init__(self, revision_id, file_id):
 
629
        VersionedFileError.__init__(self)
 
630
        self.revision_id = revision_id
 
631
        self.file_id = file_id
 
632
 
 
633
 
 
634
class KnitError(BzrNewError):
 
635
    """Knit error"""
 
636
 
 
637
 
 
638
class KnitHeaderError(KnitError):
 
639
    """Knit header error: %(badline)r unexpected"""
 
640
 
 
641
    def __init__(self, badline):
 
642
        KnitError.__init__(self)
 
643
        self.badline = badline
 
644
 
 
645
 
 
646
class KnitCorrupt(KnitError):
 
647
    """Knit %(filename)s corrupt: %(how)s"""
 
648
 
 
649
    def __init__(self, filename, how):
 
650
        KnitError.__init__(self)
 
651
        self.filename = filename
 
652
        self.how = how
 
653
 
 
654
 
 
655
class NoSuchExportFormat(BzrNewError):
 
656
    """Export format %(format)r not supported"""
 
657
    def __init__(self, format):
 
658
        BzrNewError.__init__(self)
 
659
        self.format = format
 
660
 
 
661
 
 
662
class TransportError(BzrError):
 
663
    """All errors thrown by Transport implementations should derive
 
664
    from this class.
 
665
    """
 
666
    def __init__(self, msg=None, orig_error=None):
 
667
        if msg is None and orig_error is not None:
 
668
            msg = str(orig_error)
 
669
        BzrError.__init__(self, msg)
 
670
        self.msg = msg
 
671
        self.orig_error = orig_error
 
672
 
 
673
 
 
674
# A set of semi-meaningful errors which can be thrown
 
675
class TransportNotPossible(TransportError):
 
676
    """This is for transports where a specific function is explicitly not
 
677
    possible. Such as pushing files to an HTTP server.
 
678
    """
 
679
    pass
 
680
 
 
681
 
 
682
class ConnectionError(TransportError):
 
683
    """A connection problem prevents file retrieval.
 
684
    This does not indicate whether the file exists or not; it indicates that a
 
685
    precondition for requesting the file was not met.
 
686
    """
 
687
    def __init__(self, msg=None, orig_error=None):
 
688
        TransportError.__init__(self, msg=msg, orig_error=orig_error)
 
689
 
 
690
 
 
691
class ConnectionReset(TransportError):
 
692
    """The connection has been closed."""
 
693
    pass
 
694
 
 
695
 
 
696
class ConflictsInTree(BzrError):
 
697
    def __init__(self):
 
698
        BzrError.__init__(self, "Working tree has conflicts.")
 
699
 
 
700
 
 
701
class ParseConfigError(BzrError):
 
702
    def __init__(self, errors, filename):
 
703
        if filename is None:
 
704
            filename = ""
 
705
        message = "Error(s) parsing config file %s:\n%s" % \
 
706
            (filename, ('\n'.join(e.message for e in errors)))
 
707
        BzrError.__init__(self, message)
 
708
 
 
709
 
 
710
class SigningFailed(BzrError):
 
711
    def __init__(self, command_line):
 
712
        BzrError.__init__(self, "Failed to gpg sign data with command '%s'"
 
713
                               % command_line)
 
714
 
 
715
 
 
716
class WorkingTreeNotRevision(BzrError):
 
717
    def __init__(self, tree):
 
718
        BzrError.__init__(self, "The working tree for %s has changed since"
 
719
                          " last commit, but weave merge requires that it be"
 
720
                          " unchanged." % tree.basedir)
 
721
 
 
722
 
 
723
class CantReprocessAndShowBase(BzrNewError):
 
724
    """Can't reprocess and show base.
 
725
Reprocessing obscures relationship of conflicting lines to base."""
 
726
 
 
727
 
 
728
class GraphCycleError(BzrNewError):
 
729
    """Cycle in graph %(graph)r"""
 
730
    def __init__(self, graph):
 
731
        BzrNewError.__init__(self)
 
732
        self.graph = graph
 
733
 
 
734
 
 
735
class NotConflicted(BzrNewError):
 
736
    """File %(filename)s is not conflicted."""
 
737
 
 
738
    def __init__(self, filename):
 
739
        BzrNewError.__init__(self)
 
740
        self.filename = filename
 
741
 
 
742
 
 
743
class MustUseDecorated(Exception):
 
744
    """A decorating function has requested its original command be used.
 
745
    
 
746
    This should never escape bzr, so does not need to be printable.
 
747
    """
 
748
 
 
749
 
 
750
class NoBundleFound(BzrNewError):
 
751
    """No bundle was found in %(filename)s"""
 
752
    def __init__(self, filename):
 
753
        BzrNewError.__init__(self)
 
754
        self.filename = filename
 
755
 
 
756
 
 
757
class BundleNotSupported(BzrNewError):
 
758
    """Unable to handle bundle version %(version)s: %(msg)s"""
 
759
    def __init__(self, version, msg):
 
760
        BzrNewError.__init__(self)
 
761
        self.version = version
 
762
        self.msg = msg
 
763
 
 
764
 
 
765
class MissingText(BzrNewError):
 
766
    """Branch %(base)s is missing revision %(text_revision)s of %(file_id)s"""
 
767
 
 
768
    def __init__(self, branch, text_revision, file_id):
 
769
        BzrNewError.__init__(self)
 
770
        self.branch = branch
 
771
        self.base = branch.base
 
772
        self.text_revision = text_revision
 
773
        self.file_id = file_id
 
774
 
 
775
 
 
776
class DuplicateKey(BzrNewError):
 
777
    """Key %(key)s is already present in map"""
 
778
 
 
779
 
 
780
class MalformedTransform(BzrNewError):
 
781
    """Tree transform is malformed %(conflicts)r"""
 
782
 
 
783
 
 
784
class NoFinalPath(BzrNewError):
 
785
    """No final name for trans_id %(trans_id)r
 
786
    file-id: %(file_id)r 
 
787
    root trans-id: %(root_trans_id)r"""
 
788
    def __init__(self, trans_id, transform):
 
789
        self.trans_id = trans_id
 
790
        self.file_id = transform.final_file_id(trans_id)
 
791
        self.root_trans_id = transform.root
 
792
 
 
793
 
 
794
class BzrBadParameter(BzrNewError):
 
795
    """A bad parameter : %(param)s is not usable.
 
796
    
 
797
    This exception should never be thrown, but it is a base class for all
 
798
    parameter-to-function errors.
 
799
    """
 
800
    def __init__(self, param):
 
801
        BzrNewError.__init__(self)
 
802
        self.param = param
 
803
 
 
804
 
 
805
class BzrBadParameterNotUnicode(BzrBadParameter):
 
806
    """Parameter %(param)s is neither unicode nor utf8."""
 
807
 
 
808
 
 
809
class ReusingTransform(BzrNewError):
 
810
    """Attempt to reuse a transform that has already been applied."""
 
811
 
 
812
 
 
813
class CantMoveRoot(BzrNewError):
 
814
    """Moving the root directory is not supported at this time"""
 
815
 
 
816
 
 
817
class BzrBadParameterNotString(BzrBadParameter):
 
818
    """Parameter %(param)s is not a string or unicode string."""
 
819
 
 
820
 
 
821
class BzrBadParameterMissing(BzrBadParameter):
 
822
    """Parameter $(param)s is required but not present."""
 
823
 
 
824
 
 
825
class BzrBadParameterUnicode(BzrBadParameter):
 
826
    """Parameter %(param)s is unicode but only byte-strings are permitted."""
 
827
 
 
828
 
 
829
class BzrBadParameterContainsNewline(BzrBadParameter):
 
830
    """Parameter %(param)s contains a newline."""
 
831
 
 
832
 
 
833
class DependencyNotPresent(BzrNewError):
 
834
    """Unable to import library "%(library)s": %(error)s"""
 
835
 
 
836
    def __init__(self, library, error):
 
837
        BzrNewError.__init__(self, library=library, error=error)
 
838
 
 
839
 
 
840
class ParamikoNotPresent(DependencyNotPresent):
 
841
    """Unable to import paramiko (required for sftp support): %(error)s"""
 
842
 
 
843
    def __init__(self, error):
 
844
        DependencyNotPresent.__init__(self, 'paramiko', error)
 
845
 
 
846
 
 
847
class UninitializableFormat(BzrNewError):
 
848
    """Format %(format)s cannot be initialised by this version of bzr."""
 
849
 
 
850
    def __init__(self, format):
 
851
        BzrNewError.__init__(self)
 
852
        self.format = format
 
853
 
 
854
 
 
855
class NoDiff3(BzrNewError):
 
856
    """Diff3 is not installed on this machine."""
 
857
 
 
858
 
 
859
class ExistingLimbo(BzrNewError):
 
860
    """This tree contains left-over files from a failed operation.
 
861
    Please examine %(limbo_dir)s to see if it contains any files you wish to
 
862
    keep, and delete it when you are done.
 
863
    """
 
864
    def __init__(self, limbo_dir):
 
865
       BzrNewError.__init__(self)
 
866
       self.limbo_dir = limbo_dir
 
867
 
 
868
 
 
869
class ImmortalLimbo(BzrNewError):
 
870
    """Unable to delete transform temporary directory $(limbo_dir)s.
 
871
    Please examine %(limbo_dir)s to see if it contains any files you wish to
 
872
    keep, and delete it when you are done.
 
873
    """
 
874
    def __init__(self, limbo_dir):
 
875
       BzrNewError.__init__(self)
 
876
       self.limbo_dir = limbo_dir
 
877
 
 
878
 
 
879
class OutOfDateTree(BzrNewError):
 
880
    """Working tree is out of date, please run 'bzr update'."""
 
881
 
 
882
    def __init__(self, tree):
 
883
        BzrNewError.__init__(self)
 
884
        self.tree = tree
 
885
 
 
886
 
 
887
class MergeModifiedFormatError(BzrNewError):
 
888
    """Error in merge modified format"""
 
889
 
 
890
 
 
891
class ConflictFormatError(BzrNewError):
 
892
    """Format error in conflict listings"""
 
893
 
 
894
 
 
895
class CorruptRepository(BzrNewError):
 
896
    """An error has been detected in the repository %(repo_path)s.
 
897
Please run bzr reconcile on this repository."""
 
898
 
 
899
    def __init__(self, repo):
 
900
        BzrNewError.__init__(self)
 
901
        self.repo_path = repo.bzrdir.root_transport.base
 
902
 
 
903
 
 
904
class UpgradeRequired(BzrNewError):
 
905
    """To use this feature you must upgrade your branch at %(path)s."""
 
906
 
 
907
    def __init__(self, path):
 
908
        BzrNewError.__init__(self)
 
909
        self.path = path
 
910
 
 
911
 
 
912
class LocalRequiresBoundBranch(BzrNewError):
 
913
    """Cannot perform local-only commits on unbound branches."""
 
914
 
 
915
 
 
916
class MissingProgressBarFinish(BzrNewError):
 
917
    """A nested progress bar was not 'finished' correctly."""
 
918
 
 
919
 
 
920
class UnsupportedOperation(BzrNewError):
 
921
    """The method %(mname)s is not supported on objects of type %(tname)s."""
 
922
    def __init__(self, method, method_self):
 
923
        self.method = method
 
924
        self.mname = method.__name__
 
925
        self.tname = type(method_self).__name__
 
926
 
 
927
 
 
928
class BinaryFile(BzrNewError):
 
929
    """File is binary but should be text."""
 
930
 
 
931
 
 
932
class IllegalPath(BzrNewError):
 
933
    """The path %(path)s is not permitted on this platform"""
 
934
 
 
935
    def __init__(self, path):
 
936
        BzrNewError.__init__(self)
 
937
        self.path = path
 
938
 
 
939
 
 
940
class TestamentMismatch(BzrNewError):
 
941
    """Testament did not match expected value.  
 
942
       For revision_id {%(revision_id)s}, expected {%(expected)s}, measured 
 
943
       {%(measured)s}
 
944
    """
 
945
    def __init__(self, revision_id, expected, measured):
 
946
        self.revision_id = revision_id
 
947
        self.expected = expected
 
948
        self.measured = measured
 
949
 
 
950
 
 
951
class BadBundle(Exception): pass
 
952
 
 
953
 
 
954
class MalformedHeader(BadBundle): pass
 
955
 
 
956
 
 
957
class MalformedPatches(BadBundle): pass
 
958
 
 
959
 
 
960
class MalformedFooter(BadBundle): pass