/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: Canonical.com Patch Queue Manager
  • Date: 2006-08-31 06:06:38 UTC
  • mfrom: (1966.1.2 build-resolver)
  • Revision ID: pqm@pqm.ubuntu.com-20060831060638-bfc0303de36a40a8
Behave reasonably when creating a checkout in a directory with files

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
 
 
509
class StrictCommitFailed(Exception):
 
510
    """Commit refused because there are unknowns in the tree."""
 
511
 
 
512
 
 
513
class NoSuchRevision(BzrNewError):
 
514
    """Branch %(branch)s has no revision %(revision)s"""
 
515
 
 
516
    is_user_error = False
 
517
 
 
518
    def __init__(self, branch, revision):
 
519
        self.branch = branch
 
520
        self.revision = revision
 
521
 
 
522
 
 
523
class HistoryMissing(BzrError):
 
524
    def __init__(self, branch, object_type, object_id):
 
525
        self.branch = branch
 
526
        BzrError.__init__(self,
 
527
                          '%s is missing %s {%s}'
 
528
                          % (branch, object_type, object_id))
 
529
 
 
530
 
 
531
class DivergedBranches(BzrNewError):
 
532
    "These branches have diverged.  Use the merge command to reconcile them."""
 
533
 
 
534
    is_user_error = True
 
535
 
 
536
    def __init__(self, branch1, branch2):
 
537
        self.branch1 = branch1
 
538
        self.branch2 = branch2
 
539
 
 
540
 
 
541
class UnrelatedBranches(BzrNewError):
 
542
    "Branches have no common ancestor, and no merge base revision was specified."
 
543
 
 
544
    is_user_error = True
 
545
 
 
546
 
 
547
class NoCommonAncestor(BzrNewError):
 
548
    "Revisions have no common ancestor: %(revision_a)s %(revision_b)s"
 
549
 
 
550
    def __init__(self, revision_a, revision_b):
 
551
        self.revision_a = revision_a
 
552
        self.revision_b = revision_b
 
553
 
 
554
 
 
555
class NoCommonRoot(BzrError):
 
556
    def __init__(self, revision_a, revision_b):
 
557
        msg = "Revisions are not derived from the same root: %s %s." \
 
558
            % (revision_a, revision_b) 
 
559
        BzrError.__init__(self, msg)
 
560
 
 
561
 
 
562
 
 
563
class NotAncestor(BzrError):
 
564
    def __init__(self, rev_id, not_ancestor_id):
 
565
        msg = "Revision %s is not an ancestor of %s" % (not_ancestor_id, 
 
566
                                                        rev_id)
 
567
        BzrError.__init__(self, msg)
 
568
        self.rev_id = rev_id
 
569
        self.not_ancestor_id = not_ancestor_id
 
570
 
 
571
 
 
572
class InstallFailed(BzrError):
 
573
    def __init__(self, revisions):
 
574
        msg = "Could not install revisions:\n%s" % " ,".join(revisions)
 
575
        BzrError.__init__(self, msg)
 
576
        self.revisions = revisions
 
577
 
 
578
 
 
579
class AmbiguousBase(BzrError):
 
580
    def __init__(self, bases):
 
581
        warn("BzrError AmbiguousBase has been deprecated as of bzrlib 0.8.",
 
582
                DeprecationWarning)
 
583
        msg = "The correct base is unclear, because %s are all equally close" %\
 
584
            ", ".join(bases)
 
585
        BzrError.__init__(self, msg)
 
586
        self.bases = bases
 
587
 
 
588
 
 
589
class NoCommits(BzrError):
 
590
    def __init__(self, branch):
 
591
        msg = "Branch %s has no commits." % branch
 
592
        BzrError.__init__(self, msg)
 
593
 
 
594
 
 
595
class UnlistableStore(BzrError):
 
596
    def __init__(self, store):
 
597
        BzrError.__init__(self, "Store %s is not listable" % store)
 
598
 
 
599
 
 
600
 
 
601
class UnlistableBranch(BzrError):
 
602
    def __init__(self, br):
 
603
        BzrError.__init__(self, "Stores for branch %s are not listable" % br)
 
604
 
 
605
 
 
606
class BoundBranchOutOfDate(BzrNewError):
 
607
    """Bound branch %(branch)s is out of date with master branch %(master)s."""
 
608
    def __init__(self, branch, master):
 
609
        BzrNewError.__init__(self)
 
610
        self.branch = branch
 
611
        self.master = master
 
612
 
 
613
        
 
614
class CommitToDoubleBoundBranch(BzrNewError):
 
615
    """Cannot commit to branch %(branch)s. It is bound to %(master)s, which is bound to %(remote)s."""
 
616
    def __init__(self, branch, master, remote):
 
617
        BzrNewError.__init__(self)
 
618
        self.branch = branch
 
619
        self.master = master
 
620
        self.remote = remote
 
621
 
 
622
 
 
623
class OverwriteBoundBranch(BzrNewError):
 
624
    """Cannot pull --overwrite to a branch which is bound %(branch)s"""
 
625
    def __init__(self, branch):
 
626
        BzrNewError.__init__(self)
 
627
        self.branch = branch
 
628
 
 
629
 
 
630
class BoundBranchConnectionFailure(BzrNewError):
 
631
    """Unable to connect to target of bound branch %(branch)s => %(target)s: %(error)s"""
 
632
    def __init__(self, branch, target, error):
 
633
        BzrNewError.__init__(self)
 
634
        self.branch = branch
 
635
        self.target = target
 
636
        self.error = error
 
637
 
 
638
 
 
639
class WeaveError(BzrNewError):
 
640
    """Error in processing weave: %(message)s"""
 
641
 
 
642
    def __init__(self, message=None):
 
643
        BzrNewError.__init__(self)
 
644
        self.message = message
 
645
 
 
646
 
 
647
class WeaveRevisionAlreadyPresent(WeaveError):
 
648
    """Revision {%(revision_id)s} already present in %(weave)s"""
 
649
    def __init__(self, revision_id, weave):
 
650
 
 
651
        WeaveError.__init__(self)
 
652
        self.revision_id = revision_id
 
653
        self.weave = weave
 
654
 
 
655
 
 
656
class WeaveRevisionNotPresent(WeaveError):
 
657
    """Revision {%(revision_id)s} not present in %(weave)s"""
 
658
 
 
659
    def __init__(self, revision_id, weave):
 
660
        WeaveError.__init__(self)
 
661
        self.revision_id = revision_id
 
662
        self.weave = weave
 
663
 
 
664
 
 
665
class WeaveFormatError(WeaveError):
 
666
    """Weave invariant violated: %(what)s"""
 
667
 
 
668
    def __init__(self, what):
 
669
        WeaveError.__init__(self)
 
670
        self.what = what
 
671
 
 
672
 
 
673
class WeaveParentMismatch(WeaveError):
 
674
    """Parents are mismatched between two revisions."""
 
675
    
 
676
 
 
677
class WeaveInvalidChecksum(WeaveError):
 
678
    """Text did not match it's checksum: %(message)s"""
 
679
 
 
680
 
 
681
class WeaveTextDiffers(WeaveError):
 
682
    """Weaves differ on text content. Revision: {%(revision_id)s}, %(weave_a)s, %(weave_b)s"""
 
683
 
 
684
    def __init__(self, revision_id, weave_a, weave_b):
 
685
        WeaveError.__init__(self)
 
686
        self.revision_id = revision_id
 
687
        self.weave_a = weave_a
 
688
        self.weave_b = weave_b
 
689
 
 
690
 
 
691
class WeaveTextDiffers(WeaveError):
 
692
    """Weaves differ on text content. Revision: {%(revision_id)s}, %(weave_a)s, %(weave_b)s"""
 
693
 
 
694
    def __init__(self, revision_id, weave_a, weave_b):
 
695
        WeaveError.__init__(self)
 
696
        self.revision_id = revision_id
 
697
        self.weave_a = weave_a
 
698
        self.weave_b = weave_b
 
699
 
 
700
 
 
701
class VersionedFileError(BzrNewError):
 
702
    """Versioned file error."""
 
703
 
 
704
 
 
705
class RevisionNotPresent(VersionedFileError):
 
706
    """Revision {%(revision_id)s} not present in %(file_id)s."""
 
707
 
 
708
    def __init__(self, revision_id, file_id):
 
709
        VersionedFileError.__init__(self)
 
710
        self.revision_id = revision_id
 
711
        self.file_id = file_id
 
712
 
 
713
 
 
714
class RevisionAlreadyPresent(VersionedFileError):
 
715
    """Revision {%(revision_id)s} already present in %(file_id)s."""
 
716
 
 
717
    def __init__(self, revision_id, file_id):
 
718
        VersionedFileError.__init__(self)
 
719
        self.revision_id = revision_id
 
720
        self.file_id = file_id
 
721
 
 
722
 
 
723
class KnitError(BzrNewError):
 
724
    """Knit error"""
 
725
 
 
726
 
 
727
class KnitHeaderError(KnitError):
 
728
    """Knit header error: %(badline)r unexpected"""
 
729
 
 
730
    def __init__(self, badline):
 
731
        KnitError.__init__(self)
 
732
        self.badline = badline
 
733
 
 
734
 
 
735
class KnitCorrupt(KnitError):
 
736
    """Knit %(filename)s corrupt: %(how)s"""
 
737
 
 
738
    def __init__(self, filename, how):
 
739
        KnitError.__init__(self)
 
740
        self.filename = filename
 
741
        self.how = how
 
742
 
 
743
 
 
744
class NoSuchExportFormat(BzrNewError):
 
745
    """Export format %(format)r not supported"""
 
746
    def __init__(self, format):
 
747
        BzrNewError.__init__(self)
 
748
        self.format = format
 
749
 
 
750
 
 
751
class TransportError(BzrNewError):
 
752
    """Transport error: %(msg)s %(orig_error)s"""
 
753
 
 
754
    def __init__(self, msg=None, orig_error=None):
 
755
        if msg is None and orig_error is not None:
 
756
            msg = str(orig_error)
 
757
        if orig_error is None:
 
758
            orig_error = ''
 
759
        if msg is None:
 
760
            msg =  ''
 
761
        self.msg = msg
 
762
        self.orig_error = orig_error
 
763
        BzrNewError.__init__(self)
 
764
 
 
765
 
 
766
# A set of semi-meaningful errors which can be thrown
 
767
class TransportNotPossible(TransportError):
 
768
    """Transport operation not possible: %(msg)s %(orig_error)%"""
 
769
 
 
770
 
 
771
class ConnectionError(TransportError):
 
772
    """Connection error: %(msg)s %(orig_error)s"""
 
773
 
 
774
 
 
775
class ConnectionReset(TransportError):
 
776
    """Connection closed: %(msg)s %(orig_error)s"""
 
777
 
 
778
 
 
779
class InvalidRange(TransportError):
 
780
    """Invalid range access."""
 
781
    
 
782
    def __init__(self, path, offset):
 
783
        TransportError.__init__(self, ("Invalid range access in %s at %d"
 
784
                                       % (path, offset)))
 
785
 
 
786
 
 
787
class InvalidHttpResponse(TransportError):
 
788
    """Invalid http response for %(path)s: %(msg)s"""
 
789
 
 
790
    def __init__(self, path, msg, orig_error=None):
 
791
        self.path = path
 
792
        TransportError.__init__(self, msg, orig_error=orig_error)
 
793
 
 
794
 
 
795
class InvalidHttpRange(InvalidHttpResponse):
 
796
    """Invalid http range "%(range)s" for %(path)s: %(msg)s"""
 
797
    
 
798
    def __init__(self, path, range, msg):
 
799
        self.range = range
 
800
        InvalidHttpResponse.__init__(self, path, msg)
 
801
 
 
802
 
 
803
class InvalidHttpContentType(InvalidHttpResponse):
 
804
    """Invalid http Content-type "%(ctype)s" for %(path)s: %(msg)s"""
 
805
    
 
806
    def __init__(self, path, ctype, msg):
 
807
        self.ctype = ctype
 
808
        InvalidHttpResponse.__init__(self, path, msg)
 
809
 
 
810
 
 
811
class ConflictsInTree(BzrError):
 
812
    def __init__(self):
 
813
        BzrError.__init__(self, "Working tree has conflicts.")
 
814
 
 
815
 
 
816
class ParseConfigError(BzrError):
 
817
    def __init__(self, errors, filename):
 
818
        if filename is None:
 
819
            filename = ""
 
820
        message = "Error(s) parsing config file %s:\n%s" % \
 
821
            (filename, ('\n'.join(e.message for e in errors)))
 
822
        BzrError.__init__(self, message)
 
823
 
 
824
 
 
825
class SigningFailed(BzrError):
 
826
    def __init__(self, command_line):
 
827
        BzrError.__init__(self, "Failed to gpg sign data with command '%s'"
 
828
                               % command_line)
 
829
 
 
830
 
 
831
class WorkingTreeNotRevision(BzrError):
 
832
    def __init__(self, tree):
 
833
        BzrError.__init__(self, "The working tree for %s has changed since"
 
834
                          " last commit, but weave merge requires that it be"
 
835
                          " unchanged." % tree.basedir)
 
836
 
 
837
 
 
838
class CantReprocessAndShowBase(BzrNewError):
 
839
    """Can't reprocess and show base.
 
840
Reprocessing obscures relationship of conflicting lines to base."""
 
841
 
 
842
 
 
843
class GraphCycleError(BzrNewError):
 
844
    """Cycle in graph %(graph)r"""
 
845
    def __init__(self, graph):
 
846
        BzrNewError.__init__(self)
 
847
        self.graph = graph
 
848
 
 
849
 
 
850
class NotConflicted(BzrNewError):
 
851
    """File %(filename)s is not conflicted."""
 
852
 
 
853
    def __init__(self, filename):
 
854
        BzrNewError.__init__(self)
 
855
        self.filename = filename
 
856
 
 
857
 
 
858
class MustUseDecorated(Exception):
 
859
    """A decorating function has requested its original command be used.
 
860
    
 
861
    This should never escape bzr, so does not need to be printable.
 
862
    """
 
863
 
 
864
 
 
865
class NoBundleFound(BzrNewError):
 
866
    """No bundle was found in %(filename)s"""
 
867
    def __init__(self, filename):
 
868
        BzrNewError.__init__(self)
 
869
        self.filename = filename
 
870
 
 
871
 
 
872
class BundleNotSupported(BzrNewError):
 
873
    """Unable to handle bundle version %(version)s: %(msg)s"""
 
874
    def __init__(self, version, msg):
 
875
        BzrNewError.__init__(self)
 
876
        self.version = version
 
877
        self.msg = msg
 
878
 
 
879
 
 
880
class MissingText(BzrNewError):
 
881
    """Branch %(base)s is missing revision %(text_revision)s of %(file_id)s"""
 
882
 
 
883
    def __init__(self, branch, text_revision, file_id):
 
884
        BzrNewError.__init__(self)
 
885
        self.branch = branch
 
886
        self.base = branch.base
 
887
        self.text_revision = text_revision
 
888
        self.file_id = file_id
 
889
 
 
890
 
 
891
class DuplicateKey(BzrNewError):
 
892
    """Key %(key)s is already present in map"""
 
893
 
 
894
 
 
895
class MalformedTransform(BzrNewError):
 
896
    """Tree transform is malformed %(conflicts)r"""
 
897
 
 
898
 
 
899
class BzrBadParameter(BzrNewError):
 
900
    """A bad parameter : %(param)s is not usable.
 
901
    
 
902
    This exception should never be thrown, but it is a base class for all
 
903
    parameter-to-function errors.
 
904
    """
 
905
    def __init__(self, param):
 
906
        BzrNewError.__init__(self)
 
907
        self.param = param
 
908
 
 
909
 
 
910
class BzrBadParameterNotUnicode(BzrBadParameter):
 
911
    """Parameter %(param)s is neither unicode nor utf8."""
 
912
 
 
913
 
 
914
class ReusingTransform(BzrNewError):
 
915
    """Attempt to reuse a transform that has already been applied."""
 
916
 
 
917
 
 
918
class CantMoveRoot(BzrNewError):
 
919
    """Moving the root directory is not supported at this time"""
 
920
 
 
921
 
 
922
class BzrBadParameterNotString(BzrBadParameter):
 
923
    """Parameter %(param)s is not a string or unicode string."""
 
924
 
 
925
 
 
926
class BzrBadParameterMissing(BzrBadParameter):
 
927
    """Parameter $(param)s is required but not present."""
 
928
 
 
929
 
 
930
class BzrBadParameterUnicode(BzrBadParameter):
 
931
    """Parameter %(param)s is unicode but only byte-strings are permitted."""
 
932
 
 
933
 
 
934
class BzrBadParameterContainsNewline(BzrBadParameter):
 
935
    """Parameter %(param)s contains a newline."""
 
936
 
 
937
 
 
938
class DependencyNotPresent(BzrNewError):
 
939
    """Unable to import library "%(library)s": %(error)s"""
 
940
 
 
941
    def __init__(self, library, error):
 
942
        BzrNewError.__init__(self, library=library, error=error)
 
943
 
 
944
 
 
945
class ParamikoNotPresent(DependencyNotPresent):
 
946
    """Unable to import paramiko (required for sftp support): %(error)s"""
 
947
 
 
948
    def __init__(self, error):
 
949
        DependencyNotPresent.__init__(self, 'paramiko', error)
 
950
 
 
951
 
 
952
class UninitializableFormat(BzrNewError):
 
953
    """Format %(format)s cannot be initialised by this version of bzr."""
 
954
 
 
955
    def __init__(self, format):
 
956
        BzrNewError.__init__(self)
 
957
        self.format = format
 
958
 
 
959
 
 
960
class NoDiff(BzrNewError):
 
961
    """Diff is not installed on this machine: %(msg)s"""
 
962
 
 
963
    def __init__(self, msg):
 
964
        BzrNewError.__init__(self, msg=msg)
 
965
 
 
966
 
 
967
class NoDiff3(BzrNewError):
 
968
    """Diff3 is not installed on this machine."""
 
969
 
 
970
 
 
971
class ExistingLimbo(BzrNewError):
 
972
    """This tree contains left-over files from a failed operation.
 
973
    Please examine %(limbo_dir)s to see if it contains any files you wish to
 
974
    keep, and delete it when you are done.
 
975
    """
 
976
    def __init__(self, limbo_dir):
 
977
       BzrNewError.__init__(self)
 
978
       self.limbo_dir = limbo_dir
 
979
 
 
980
 
 
981
class ImmortalLimbo(BzrNewError):
 
982
    """Unable to delete transform temporary directory $(limbo_dir)s.
 
983
    Please examine %(limbo_dir)s to see if it contains any files you wish to
 
984
    keep, and delete it when you are done.
 
985
    """
 
986
    def __init__(self, limbo_dir):
 
987
       BzrNewError.__init__(self)
 
988
       self.limbo_dir = limbo_dir
 
989
 
 
990
 
 
991
class OutOfDateTree(BzrNewError):
 
992
    """Working tree is out of date, please run 'bzr update'."""
 
993
 
 
994
    def __init__(self, tree):
 
995
        BzrNewError.__init__(self)
 
996
        self.tree = tree
 
997
 
 
998
 
 
999
class MergeModifiedFormatError(BzrNewError):
 
1000
    """Error in merge modified format"""
 
1001
 
 
1002
 
 
1003
class ConflictFormatError(BzrNewError):
 
1004
    """Format error in conflict listings"""
 
1005
 
 
1006
 
 
1007
class CorruptRepository(BzrNewError):
 
1008
    """An error has been detected in the repository %(repo_path)s.
 
1009
Please run bzr reconcile on this repository."""
 
1010
 
 
1011
    def __init__(self, repo):
 
1012
        BzrNewError.__init__(self)
 
1013
        self.repo_path = repo.bzrdir.root_transport.base
 
1014
 
 
1015
 
 
1016
class UpgradeRequired(BzrNewError):
 
1017
    """To use this feature you must upgrade your branch at %(path)s."""
 
1018
 
 
1019
    def __init__(self, path):
 
1020
        BzrNewError.__init__(self)
 
1021
        self.path = path
 
1022
 
 
1023
 
 
1024
class LocalRequiresBoundBranch(BzrNewError):
 
1025
    """Cannot perform local-only commits on unbound branches."""
 
1026
 
 
1027
 
 
1028
class MissingProgressBarFinish(BzrNewError):
 
1029
    """A nested progress bar was not 'finished' correctly."""
 
1030
 
 
1031
 
 
1032
class InvalidProgressBarType(BzrNewError):
 
1033
    """Environment variable BZR_PROGRESS_BAR='%(bar_type)s is not a supported type
 
1034
Select one of: %(valid_types)s"""
 
1035
 
 
1036
    def __init__(self, bar_type, valid_types):
 
1037
        BzrNewError.__init__(self, bar_type=bar_type, valid_types=valid_types)
 
1038
 
 
1039
 
 
1040
class UnsupportedOperation(BzrNewError):
 
1041
    """The method %(mname)s is not supported on objects of type %(tname)s."""
 
1042
    def __init__(self, method, method_self):
 
1043
        self.method = method
 
1044
        self.mname = method.__name__
 
1045
        self.tname = type(method_self).__name__
 
1046
 
 
1047
 
 
1048
class BinaryFile(BzrNewError):
 
1049
    """File is binary but should be text."""
 
1050
 
 
1051
 
 
1052
class IllegalPath(BzrNewError):
 
1053
    """The path %(path)s is not permitted on this platform"""
 
1054
 
 
1055
    def __init__(self, path):
 
1056
        BzrNewError.__init__(self)
 
1057
        self.path = path
 
1058
 
 
1059
 
 
1060
class TestamentMismatch(BzrNewError):
 
1061
    """Testament did not match expected value.  
 
1062
       For revision_id {%(revision_id)s}, expected {%(expected)s}, measured 
 
1063
       {%(measured)s}
 
1064
    """
 
1065
    def __init__(self, revision_id, expected, measured):
 
1066
        self.revision_id = revision_id
 
1067
        self.expected = expected
 
1068
        self.measured = measured
 
1069
 
 
1070
 
 
1071
class NotABundle(BzrNewError):
 
1072
    """Not a bzr revision-bundle: %(text)r"""
 
1073
 
 
1074
    def __init__(self, text):
 
1075
        BzrNewError.__init__(self)
 
1076
        self.text = text
 
1077
 
 
1078
 
 
1079
class BadBundle(BzrNewError): 
 
1080
    """Bad bzr revision-bundle: %(text)r"""
 
1081
 
 
1082
    def __init__(self, text):
 
1083
        BzrNewError.__init__(self)
 
1084
        self.text = text
 
1085
 
 
1086
 
 
1087
class MalformedHeader(BadBundle): 
 
1088
    """Malformed bzr revision-bundle header: %(text)r"""
 
1089
 
 
1090
    def __init__(self, text):
 
1091
        BzrNewError.__init__(self)
 
1092
        self.text = text
 
1093
 
 
1094
 
 
1095
class MalformedPatches(BadBundle): 
 
1096
    """Malformed patches in bzr revision-bundle: %(text)r"""
 
1097
 
 
1098
    def __init__(self, text):
 
1099
        BzrNewError.__init__(self)
 
1100
        self.text = text
 
1101
 
 
1102
 
 
1103
class MalformedFooter(BadBundle): 
 
1104
    """Malformed footer in bzr revision-bundle: %(text)r"""
 
1105
 
 
1106
    def __init__(self, text):
 
1107
        BzrNewError.__init__(self)
 
1108
        self.text = text
 
1109
 
 
1110
 
 
1111
class UnsupportedEOLMarker(BadBundle):
 
1112
    """End of line marker was not \\n in bzr revision-bundle"""    
 
1113
 
 
1114
    def __init__(self):
 
1115
        BzrNewError.__init__(self)
 
1116
 
 
1117
 
 
1118
class UnknownSSH(BzrNewError):
 
1119
    """Unrecognised value for BZR_SSH environment variable: %(vendor)s"""
 
1120
 
 
1121
    def __init__(self, vendor):
 
1122
        BzrNewError.__init__(self)
 
1123
        self.vendor = vendor
 
1124
 
 
1125
 
 
1126
class GhostRevisionUnusableHere(BzrNewError):
 
1127
    """Ghost revision {%(revision_id)s} cannot be used here."""
 
1128
 
 
1129
    def __init__(self, revision_id):
 
1130
        BzrNewError.__init__(self)
 
1131
        self.revision_id = revision_id