~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/errors.py

  • Committer: Aaron Bentley
  • Date: 2007-02-06 14:52:16 UTC
  • mfrom: (2266 +trunk)
  • mto: This revision was merged to the branch mainline in revision 2268.
  • Revision ID: abentley@panoramicfeedback.com-20070206145216-fcpi8o3ufvuzwbp9
Merge bzr.dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005, 2006, 2007, 2008 Canonical Ltd
 
1
# Copyright (C) 2005, 2006 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
44
44
# 'unprintable'.
45
45
 
46
46
 
47
 
# return codes from the bzr program
48
 
EXIT_OK = 0
49
 
EXIT_ERROR = 3
50
 
EXIT_INTERNAL_ERROR = 4
51
 
 
52
 
 
53
47
class BzrError(StandardError):
54
48
    """
55
49
    Base class for errors raised by bzrlib.
56
50
 
57
 
    :cvar internal_error: if True this was probably caused by a bzr bug and
58
 
    should be displayed with a traceback; if False (or absent) this was
 
51
    :cvar internal_error: if true (or absent) this was probably caused by a
 
52
    bzr bug and should be displayed with a traceback; if False this was
59
53
    probably a user or environment error and they don't need the gory details.
60
54
    (That can be overridden by -Derror on the command line.)
61
55
 
93
87
            for key, value in kwds.items():
94
88
                setattr(self, key, value)
95
89
 
96
 
    def _format(self):
 
90
    def __str__(self):
97
91
        s = getattr(self, '_preformatted_string', None)
98
92
        if s is not None:
99
 
            # contains a preformatted message
100
 
            return s
 
93
            # contains a preformatted message; must be cast to plain str
 
94
            return str(s)
101
95
        try:
102
96
            fmt = self._get_format_string()
103
97
            if fmt:
104
 
                d = dict(self.__dict__)
105
 
                # special case: python2.5 puts the 'message' attribute in a
106
 
                # slot, so it isn't seen in __dict__
107
 
                d['message'] = getattr(self, 'message', 'no message')
108
 
                s = fmt % d
 
98
                s = fmt % self.__dict__
109
99
                # __str__() should always return a 'str' object
110
100
                # never a 'unicode' object.
 
101
                if isinstance(s, unicode):
 
102
                    return s.encode('utf8')
111
103
                return s
112
104
        except (AttributeError, TypeError, NameError, ValueError, KeyError), e:
113
 
            return 'Unprintable exception %s: dict=%r, fmt=%r, error=%r' \
 
105
            return 'Unprintable exception %s: dict=%r, fmt=%r, error=%s' \
114
106
                % (self.__class__.__name__,
115
107
                   self.__dict__,
116
108
                   getattr(self, '_fmt', None),
117
 
                   e)
118
 
 
119
 
    def __unicode__(self):
120
 
        u = self._format()
121
 
        if isinstance(u, str):
122
 
            # Try decoding the str using the default encoding.
123
 
            u = unicode(u)
124
 
        elif not isinstance(u, unicode):
125
 
            # Try to make a unicode object from it, because __unicode__ must
126
 
            # return a unicode object.
127
 
            u = unicode(u)
128
 
        return u
129
 
    
130
 
    def __str__(self):
131
 
        s = self._format()
132
 
        if isinstance(s, unicode):
133
 
            s = s.encode('utf8')
134
 
        else:
135
 
            # __str__ must return a str.
136
 
            s = str(s)
137
 
        return s
 
109
                   str(e))
138
110
 
139
111
    def _get_format_string(self):
140
112
        """Return format string for this exception or None"""
153
125
               getattr(self, '_fmt', None),
154
126
               )
155
127
 
156
 
    def __eq__(self, other):
157
 
        if self.__class__ != other.__class__:
158
 
            return NotImplemented
159
 
        return self.__dict__ == other.__dict__
160
 
 
161
 
 
162
 
class InternalBzrError(BzrError):
163
 
    """Base class for errors that are internal in nature.
164
 
 
165
 
    This is a convenience class for errors that are internal. The
166
 
    internal_error attribute can still be altered in subclasses, if needed.
167
 
    Using this class is simply an easy way to get internal errors.
168
 
    """
169
 
 
170
 
    internal_error = True
171
 
 
172
128
 
173
129
class BzrNewError(BzrError):
174
130
    """Deprecated error base class."""
176
132
    # readable explanation
177
133
 
178
134
    def __init__(self, *args, **kwds):
179
 
        # XXX: Use the underlying BzrError to always generate the args
180
 
        # attribute if it doesn't exist.  We can't use super here, because
181
 
        # exceptions are old-style classes in python2.4 (but new in 2.5).
182
 
        # --bmc, 20060426
 
135
        # XXX: Use the underlying BzrError to always generate the args attribute
 
136
        # if it doesn't exist.  We can't use super here, because exceptions are
 
137
        # old-style classes in python2.4 (but new in 2.5).  --bmc, 20060426
183
138
        symbol_versioning.warn('BzrNewError was deprecated in bzr 0.13; '
184
 
             'please convert %s to use BzrError instead'
 
139
             'please convert %s to use BzrError instead' 
185
140
             % self.__class__.__name__,
186
141
             DeprecationWarning,
187
142
             stacklevel=2)
198
153
                return s.encode('utf8')
199
154
            return s
200
155
        except (TypeError, NameError, ValueError, KeyError), e:
201
 
            return 'Unprintable exception %s(%r): %r' \
 
156
            return 'Unprintable exception %s(%r): %s' \
202
157
                % (self.__class__.__name__,
203
 
                   self.__dict__, e)
 
158
                   self.__dict__, str(e))
204
159
 
205
160
 
206
161
class AlreadyBuilding(BzrError):
208
163
    _fmt = "The tree builder is already building a tree."
209
164
 
210
165
 
211
 
class BranchError(BzrError):
212
 
    """Base class for concrete 'errors about a branch'."""
213
 
 
214
 
    def __init__(self, branch):
215
 
        BzrError.__init__(self, branch=branch)
216
 
 
217
 
 
218
 
class BzrCheckError(InternalBzrError):
 
166
class BzrCheckError(BzrError):
219
167
    
220
168
    _fmt = "Internal check failed: %(message)s"
221
169
 
 
170
    internal_error = True
 
171
 
222
172
    def __init__(self, message):
223
173
        BzrError.__init__(self)
224
174
        self.message = message
225
175
 
226
176
 
227
 
class DisabledMethod(InternalBzrError):
228
 
 
229
 
    _fmt = "The smart server method '%(class_name)s' is disabled."
230
 
 
231
 
    def __init__(self, class_name):
232
 
        BzrError.__init__(self)
233
 
        self.class_name = class_name
234
 
 
235
 
 
236
 
class IncompatibleAPI(BzrError):
237
 
 
238
 
    _fmt = 'The API for "%(api)s" is not compatible with "%(wanted)s". '\
239
 
        'It supports versions "%(minimum)s" to "%(current)s".'
240
 
 
241
 
    def __init__(self, api, wanted, minimum, current):
242
 
        self.api = api
243
 
        self.wanted = wanted
244
 
        self.minimum = minimum
245
 
        self.current = current
246
 
 
247
 
 
248
 
class InProcessTransport(BzrError):
249
 
 
250
 
    _fmt = "The transport '%(transport)s' is only accessible within this " \
251
 
        "process."
252
 
 
253
 
    def __init__(self, transport):
254
 
        self.transport = transport
255
 
 
256
 
 
257
 
class InvalidEntryName(InternalBzrError):
 
177
class InvalidEntryName(BzrError):
258
178
    
259
179
    _fmt = "Invalid entry name: %(name)s"
260
180
 
 
181
    internal_error = True
 
182
 
261
183
    def __init__(self, name):
262
184
        BzrError.__init__(self)
263
185
        self.name = name
282
204
        self.revision_id = revision_id
283
205
        self.branch = branch
284
206
 
285
 
 
286
207
class ReservedId(BzrError):
287
208
 
288
209
    _fmt = "Reserved revision-id {%(revision_id)s}"
290
211
    def __init__(self, revision_id):
291
212
        self.revision_id = revision_id
292
213
 
293
 
 
294
 
class RootMissing(InternalBzrError):
295
 
 
296
 
    _fmt = ("The root entry of a tree must be the first entry supplied to "
297
 
        "record_entry_contents.")
298
 
 
299
 
 
300
 
class NoPublicBranch(BzrError):
301
 
 
302
 
    _fmt = 'There is no public branch set for "%(branch_url)s".'
303
 
 
304
 
    def __init__(self, branch):
305
 
        import bzrlib.urlutils as urlutils
306
 
        public_location = urlutils.unescape_for_display(branch.base, 'ascii')
307
 
        BzrError.__init__(self, branch_url=public_location)
308
 
 
309
 
 
310
 
class NoHelpTopic(BzrError):
311
 
 
312
 
    _fmt = ("No help could be found for '%(topic)s'. "
313
 
        "Please use 'bzr help topics' to obtain a list of topics.")
314
 
 
315
 
    def __init__(self, topic):
316
 
        self.topic = topic
317
 
 
318
 
 
319
214
class NoSuchId(BzrError):
320
215
 
321
 
    _fmt = 'The file id "%(file_id)s" is not present in the tree %(tree)s.'
 
216
    _fmt = "The file id %(file_id)s is not present in the tree %(tree)s."
322
217
    
323
218
    def __init__(self, tree, file_id):
324
219
        BzrError.__init__(self)
326
221
        self.tree = tree
327
222
 
328
223
 
329
 
class NoSuchIdInRepository(NoSuchId):
330
 
 
331
 
    _fmt = ('The file id "%(file_id)s" is not present in the repository'
332
 
            ' %(repository)r')
333
 
 
334
 
    def __init__(self, repository, file_id):
335
 
        BzrError.__init__(self, repository=repository, file_id=file_id)
336
 
 
337
 
 
338
 
class NotStacked(BranchError):
339
 
 
340
 
    _fmt = "The branch '%(branch)s' is not stacked."
341
 
 
342
 
 
343
 
class InventoryModified(InternalBzrError):
344
 
 
345
 
    _fmt = ("The current inventory for the tree %(tree)r has been modified,"
346
 
            " so a clean inventory cannot be read without data loss.")
 
224
class InventoryModified(BzrError):
 
225
 
 
226
    _fmt = ("The current inventory for the tree %(tree)r has been modified, "
 
227
            "so a clean inventory cannot be read without data loss.")
 
228
 
 
229
    internal_error = True
347
230
 
348
231
    def __init__(self, tree):
349
232
        self.tree = tree
351
234
 
352
235
class NoWorkingTree(BzrError):
353
236
 
354
 
    _fmt = 'No WorkingTree exists for "%(base)s".'
 
237
    _fmt = "No WorkingTree exists for %(base)s."
355
238
    
356
239
    def __init__(self, base):
357
240
        BzrError.__init__(self)
371
254
        self.url = url
372
255
 
373
256
 
374
 
class WorkingTreeAlreadyPopulated(InternalBzrError):
375
 
 
376
 
    _fmt = 'Working tree already populated in "%(base)s"'
 
257
class WorkingTreeAlreadyPopulated(BzrError):
 
258
 
 
259
    _fmt = """Working tree already populated in %(base)s"""
 
260
 
 
261
    internal_error = True
377
262
 
378
263
    def __init__(self, base):
379
264
        self.base = base
380
265
 
381
 
 
382
266
class BzrCommandError(BzrError):
383
267
    """Error from user command"""
384
268
 
 
269
    internal_error = False
 
270
 
385
271
    # Error from malformed user command; please avoid raising this as a
386
272
    # generic exception not caused by user input.
387
273
    #
389
275
    # are not intended to be caught anyway.  UI code need not subclass
390
276
    # BzrCommandError, and non-UI code should not throw a subclass of
391
277
    # BzrCommandError.  ADHB 20051211
 
278
    def __init__(self, msg):
 
279
        # Object.__str__() must return a real string
 
280
        # returning a Unicode string is a python error.
 
281
        if isinstance(msg, unicode):
 
282
            self.msg = msg.encode('utf8')
 
283
        else:
 
284
            self.msg = msg
 
285
 
 
286
    def __str__(self):
 
287
        return self.msg
392
288
 
393
289
 
394
290
class NotWriteLocked(BzrError):
404
300
    _fmt = "Error in command line options"
405
301
 
406
302
 
407
 
class BadIndexFormatSignature(BzrError):
408
 
 
409
 
    _fmt = "%(value)s is not an index of type %(_type)s."
410
 
 
411
 
    def __init__(self, value, _type):
412
 
        BzrError.__init__(self)
413
 
        self.value = value
414
 
        self._type = _type
415
 
 
416
 
 
417
 
class BadIndexData(BzrError):
418
 
 
419
 
    _fmt = "Error in data for index %(value)s."
420
 
 
421
 
    def __init__(self, value):
422
 
        BzrError.__init__(self)
423
 
        self.value = value
424
 
 
425
 
 
426
 
class BadIndexDuplicateKey(BzrError):
427
 
 
428
 
    _fmt = "The key '%(key)s' is already in index '%(index)s'."
429
 
 
430
 
    def __init__(self, key, index):
431
 
        BzrError.__init__(self)
432
 
        self.key = key
433
 
        self.index = index
434
 
 
435
 
 
436
 
class BadIndexKey(BzrError):
437
 
 
438
 
    _fmt = "The key '%(key)s' is not a valid key."
439
 
 
440
 
    def __init__(self, key):
441
 
        BzrError.__init__(self)
442
 
        self.key = key
443
 
 
444
 
 
445
 
class BadIndexOptions(BzrError):
446
 
 
447
 
    _fmt = "Could not parse options for index %(value)s."
448
 
 
449
 
    def __init__(self, value):
450
 
        BzrError.__init__(self)
451
 
        self.value = value
452
 
 
453
 
 
454
 
class BadIndexValue(BzrError):
455
 
 
456
 
    _fmt = "The value '%(value)s' is not a valid value."
457
 
 
458
 
    def __init__(self, value):
459
 
        BzrError.__init__(self)
460
 
        self.value = value
461
 
 
462
 
 
463
303
class BadOptionValue(BzrError):
464
304
 
465
305
    _fmt = """Bad value "%(value)s" for option "%(name)s"."""
475
315
 
476
316
# XXX: Should be unified with TransportError; they seem to represent the
477
317
# same thing
478
 
# RBC 20060929: I think that unifiying with TransportError would be a mistake
479
 
# - this is finer than a TransportError - and more useful as such. It 
480
 
# differentiates between 'transport has failed' and 'operation on a transport
481
 
# has failed.'
482
318
class PathError(BzrError):
483
319
    
484
320
    _fmt = "Generic path error: %(path)r%(extra)s)"
506
342
    """Used when renaming and both source and dest exist."""
507
343
 
508
344
    _fmt = ("Could not rename %(source)s => %(dest)s because both files exist."
509
 
            " (Use --after to tell bzr about a rename that has already"
510
 
            " happened)%(extra)s")
 
345
         "%(extra)s")
511
346
 
512
347
    def __init__(self, source, dest, extra=None):
513
348
        BzrError.__init__(self)
521
356
 
522
357
class NotADirectory(PathError):
523
358
 
524
 
    _fmt = '"%(path)s" is not a directory %(extra)s'
 
359
    _fmt = "%(path)r is not a directory %(extra)s"
525
360
 
526
361
 
527
362
class NotInWorkingDirectory(PathError):
528
363
 
529
 
    _fmt = '"%(path)s" is not in the working directory %(extra)s'
 
364
    _fmt = "%(path)r is not in the working directory %(extra)s"
530
365
 
531
366
 
532
367
class DirectoryNotEmpty(PathError):
533
368
 
534
 
    _fmt = 'Directory not empty: "%(path)s"%(extra)s'
535
 
 
536
 
 
537
 
class HardLinkNotSupported(PathError):
538
 
 
539
 
    _fmt = 'Hard-linking "%(path)s" is not supported'
540
 
 
541
 
 
542
 
class ReadingCompleted(InternalBzrError):
 
369
    _fmt = "Directory not empty: %(path)r%(extra)s"
 
370
 
 
371
 
 
372
class ReadingCompleted(BzrError):
543
373
    
544
374
    _fmt = ("The MediumRequest '%(request)s' has already had finish_reading "
545
375
            "called upon it - the request has been completed and no more "
546
376
            "data may be read.")
547
377
 
 
378
    internal_error = True
 
379
 
548
380
    def __init__(self, request):
549
381
        self.request = request
550
382
 
551
383
 
552
384
class ResourceBusy(PathError):
553
385
 
554
 
    _fmt = 'Device or resource busy: "%(path)s"%(extra)s'
 
386
    _fmt = "Device or resource busy: %(path)r%(extra)s"
555
387
 
556
388
 
557
389
class PermissionDenied(PathError):
558
390
 
559
 
    _fmt = 'Permission denied: "%(path)s"%(extra)s'
 
391
    _fmt = "Permission denied: %(path)r%(extra)s"
560
392
 
561
393
 
562
394
class InvalidURL(PathError):
563
395
 
564
 
    _fmt = 'Invalid url supplied to transport: "%(path)s"%(extra)s'
 
396
    _fmt = "Invalid url supplied to transport: %(path)r%(extra)s"
565
397
 
566
398
 
567
399
class InvalidURLJoin(PathError):
568
400
 
569
 
    _fmt = "Invalid URL join request: %(reason)s: %(base)r + %(join_args)r"
570
 
 
571
 
    def __init__(self, reason, base, join_args):
572
 
        self.reason = reason
573
 
        self.base = base
574
 
        self.join_args = join_args
575
 
        PathError.__init__(self, base, reason)
576
 
 
577
 
 
578
 
class InvalidRebaseURLs(PathError):
579
 
 
580
 
    _fmt = "URLs differ by more than path: %(from_)r and %(to)r"
581
 
 
582
 
    def __init__(self, from_, to):
583
 
        self.from_ = from_
584
 
        self.to = to
585
 
        PathError.__init__(self, from_, 'URLs differ by more than path.')
586
 
 
587
 
 
588
 
class UnavailableRepresentation(InternalBzrError):
589
 
 
590
 
    _fmt = ("The encoding '%(wanted)s' is not available for key %(key)s which "
591
 
        "is encoded as '%(native)s'.")
592
 
 
593
 
    def __init__(self, key, wanted, native):
594
 
        InternalBzrError.__init__(self)
595
 
        self.wanted = wanted
596
 
        self.native = native
597
 
        self.key = key
 
401
    _fmt = "Invalid URL join request: %(args)s%(extra)s"
 
402
 
 
403
    def __init__(self, msg, base, args):
 
404
        PathError.__init__(self, base, msg)
 
405
        self.args = [base] + list(args)
598
406
 
599
407
 
600
408
class UnknownHook(BzrError):
615
423
        PathError.__init__(self, url, extra=extra)
616
424
 
617
425
 
618
 
class UnstackableBranchFormat(BzrError):
619
 
 
620
 
    _fmt = ("The branch '%(url)s'(%(format)s) is not a stackable format. "
621
 
        "You will need to upgrade the branch to permit branch stacking.")
622
 
 
623
 
    def __init__(self, format, url):
624
 
        BzrError.__init__(self)
625
 
        self.format = format
626
 
        self.url = url
627
 
 
628
 
 
629
 
class UnstackableRepositoryFormat(BzrError):
630
 
 
631
 
    _fmt = ("The repository '%(url)s'(%(format)s) is not a stackable format. "
632
 
        "You will need to upgrade the repository to permit branch stacking.")
633
 
 
634
 
    def __init__(self, format, url):
635
 
        BzrError.__init__(self)
636
 
        self.format = format
637
 
        self.url = url
638
 
 
639
 
 
640
 
class ReadError(PathError):
641
 
    
642
 
    _fmt = """Error reading from %(path)r."""
643
 
 
644
 
 
645
426
class ShortReadvError(PathError):
646
427
 
647
 
    _fmt = ('readv() read %(actual)s bytes rather than %(length)s bytes'
648
 
            ' at %(offset)s for "%(path)s"%(extra)s')
 
428
    _fmt = "readv() read %(actual)s bytes rather than %(length)s bytes at %(offset)s for %(path)s%(extra)s"
649
429
 
650
430
    internal_error = True
651
431
 
656
436
        self.actual = actual
657
437
 
658
438
 
659
 
class PathNotChild(PathError):
 
439
class PathNotChild(BzrError):
660
440
 
661
 
    _fmt = 'Path "%(path)s" is not a child of path "%(base)s"%(extra)s'
 
441
    _fmt = "Path %(path)r is not a child of path %(base)r%(extra)s"
662
442
 
663
443
    internal_error = True
664
444
 
674
454
 
675
455
class InvalidNormalization(PathError):
676
456
 
677
 
    _fmt = 'Path "%(path)s" is not unicode normalized'
 
457
    _fmt = "Path %(path)r is not unicode normalized"
678
458
 
679
459
 
680
460
# TODO: This is given a URL; we try to unescape it but doing that from inside
682
462
# TODO: Probably this behavior of should be a common superclass 
683
463
class NotBranchError(PathError):
684
464
 
685
 
    _fmt = 'Not a branch: "%(path)s".'
 
465
    _fmt = "Not a branch: %(path)s"
686
466
 
687
467
    def __init__(self, path):
688
468
       import bzrlib.urlutils as urlutils
689
469
       self.path = urlutils.unescape_for_display(path, 'ascii')
690
470
 
691
471
 
692
 
class NoSubmitBranch(PathError):
693
 
 
694
 
    _fmt = 'No submit branch available for branch "%(path)s"'
695
 
 
696
 
    def __init__(self, branch):
697
 
       import bzrlib.urlutils as urlutils
698
 
       self.path = urlutils.unescape_for_display(branch.base, 'ascii')
699
 
 
700
 
 
701
472
class AlreadyBranchError(PathError):
702
473
 
703
 
    _fmt = 'Already a branch: "%(path)s".'
 
474
    _fmt = "Already a branch: %(path)s."
704
475
 
705
476
 
706
477
class BranchExistsWithoutWorkingTree(PathError):
707
478
 
708
 
    _fmt = 'Directory contains a branch, but no working tree \
709
 
(use bzr checkout if you wish to build a working tree): "%(path)s"'
 
479
    _fmt = "Directory contains a branch, but no working tree \
 
480
(use bzr checkout if you wish to build a working tree): %(path)s"
710
481
 
711
482
 
712
483
class AtomicFileAlreadyClosed(PathError):
713
484
 
714
 
    _fmt = ('"%(function)s" called on an AtomicFile after it was closed:'
715
 
            ' "%(path)s"')
 
485
    _fmt = "'%(function)s' called on an AtomicFile after it was closed: %(path)s"
716
486
 
717
487
    def __init__(self, path, function):
718
488
        PathError.__init__(self, path=path, extra=None)
721
491
 
722
492
class InaccessibleParent(PathError):
723
493
 
724
 
    _fmt = ('Parent not accessible given base "%(base)s" and'
725
 
            ' relative path "%(path)s"')
 
494
    _fmt = "Parent not accessible given base %(base)s and relative path %(path)s"
726
495
 
727
496
    def __init__(self, path, base):
728
497
        PathError.__init__(self, path)
731
500
 
732
501
class NoRepositoryPresent(BzrError):
733
502
 
734
 
    _fmt = 'No repository present: "%(path)s"'
 
503
    _fmt = "No repository present: %(path)r"
735
504
    def __init__(self, bzrdir):
736
505
        BzrError.__init__(self)
737
506
        self.path = bzrdir.transport.clone('..').base
739
508
 
740
509
class FileInWrongBranch(BzrError):
741
510
 
742
 
    _fmt = 'File "%(path)s" is not in branch %(branch_base)s.'
 
511
    _fmt = "File %(path)s in not in branch %(branch_base)s."
743
512
 
744
513
    def __init__(self, branch, path):
745
514
        BzrError.__init__(self)
749
518
 
750
519
 
751
520
class UnsupportedFormatError(BzrError):
752
 
 
753
 
    _fmt = "Unsupported branch format: %(format)s\nPlease run 'bzr upgrade'"
 
521
    
 
522
    _fmt = "Unsupported branch format: %(format)s"
754
523
 
755
524
 
756
525
class UnknownFormatError(BzrError):
757
526
    
758
 
    _fmt = "Unknown %(kind)s format: %(format)r"
759
 
 
760
 
    def __init__(self, format, kind='branch'):
761
 
        self.kind = kind
762
 
        self.format = format
 
527
    _fmt = "Unknown branch format: %(format)r"
763
528
 
764
529
 
765
530
class IncompatibleFormat(BzrError):
772
537
        self.bzrdir = bzrdir_format
773
538
 
774
539
 
775
 
class IncompatibleRepositories(BzrError):
776
 
 
777
 
    _fmt = "%(target)s\n" \
778
 
            "is not compatible with\n" \
779
 
            "%(source)s\n" \
780
 
            "%(details)s"
781
 
 
782
 
    def __init__(self, source, target, details=None):
783
 
        if details is None:
784
 
            details = "(no details)"
785
 
        BzrError.__init__(self, target=target, source=source, details=details)
786
 
 
787
 
 
788
540
class IncompatibleRevision(BzrError):
789
541
    
790
542
    _fmt = "Revision is not compatible with %(repo_format)s"
797
549
class AlreadyVersionedError(BzrError):
798
550
    """Used when a path is expected not to be versioned, but it is."""
799
551
 
800
 
    _fmt = "%(context_info)s%(path)s is already versioned."
 
552
    _fmt = "%(context_info)s%(path)s is already versioned"
801
553
 
802
554
    def __init__(self, path, context_info=None):
803
 
        """Construct a new AlreadyVersionedError.
 
555
        """Construct a new NotVersionedError.
804
556
 
805
557
        :param path: This is the path which is versioned,
806
558
        which should be in a user friendly form.
818
570
class NotVersionedError(BzrError):
819
571
    """Used when a path is expected to be versioned, but it is not."""
820
572
 
821
 
    _fmt = "%(context_info)s%(path)s is not versioned."
 
573
    _fmt = "%(context_info)s%(path)s is not versioned"
822
574
 
823
575
    def __init__(self, path, context_info=None):
824
576
        """Construct a new NotVersionedError.
869
621
 
870
622
class BadFileKindError(BzrError):
871
623
 
872
 
    _fmt = 'Cannot operate on "%(filename)s" of unsupported kind "%(kind)s"'
873
 
 
874
 
    def __init__(self, filename, kind):
875
 
        BzrError.__init__(self, filename=filename, kind=kind)
876
 
 
877
 
 
878
 
class BadFilenameEncoding(BzrError):
879
 
 
880
 
    _fmt = ('Filename %(filename)r is not valid in your current filesystem'
881
 
            ' encoding %(fs_encoding)s')
882
 
 
883
 
    def __init__(self, filename, fs_encoding):
884
 
        BzrError.__init__(self)
885
 
        self.filename = filename
886
 
        self.fs_encoding = fs_encoding
 
624
    _fmt = "Cannot operate on %(filename)s of unsupported kind %(kind)s"
887
625
 
888
626
 
889
627
class ForbiddenControlFileError(BzrError):
890
628
 
891
 
    _fmt = 'Cannot operate on "%(filename)s" because it is a control file'
892
 
 
893
 
 
894
 
class LockError(InternalBzrError):
895
 
 
896
 
    _fmt = "Lock error: %(msg)s"
 
629
    _fmt = "Cannot operate on %(filename)s because it is a control file"
 
630
 
 
631
 
 
632
class LockError(BzrError):
 
633
 
 
634
    _fmt = "Lock error: %(message)s"
 
635
 
 
636
    internal_error = True
897
637
 
898
638
    # All exceptions from the lock/unlock functions should be from
899
639
    # this exception class.  They will be translated as necessary. The
901
641
    #
902
642
    # New code should prefer to raise specific subclasses
903
643
    def __init__(self, message):
904
 
        # Python 2.5 uses a slot for StandardError.message,
905
 
        # so use a different variable name.  We now work around this in
906
 
        # BzrError.__str__, but this member name is kept for compatability.
907
 
        self.msg = message
908
 
 
909
 
 
910
 
class LockActive(LockError):
911
 
 
912
 
    _fmt = "The lock for '%(lock_description)s' is in use and cannot be broken."
913
 
 
914
 
    internal_error = False
915
 
 
916
 
    def __init__(self, lock_description):
917
 
        self.lock_description = lock_description
 
644
        self.message = message
918
645
 
919
646
 
920
647
class CommitNotPossible(LockError):
937
664
 
938
665
    _fmt = "A write attempt was made in a read only transaction on %(obj)s"
939
666
 
940
 
    # TODO: There should also be an error indicating that you need a write
941
 
    # lock and don't have any lock at all... mbp 20070226
942
 
 
943
667
    def __init__(self, obj):
944
668
        self.obj = obj
945
669
 
946
670
 
947
 
class LockFailed(LockError):
948
 
 
949
 
    internal_error = False
950
 
 
951
 
    _fmt = "Cannot lock %(lock)s: %(why)s"
952
 
 
953
 
    def __init__(self, lock, why):
954
 
        LockError.__init__(self, '')
955
 
        self.lock = lock
956
 
        self.why = why
957
 
 
958
 
 
959
671
class OutSideTransaction(BzrError):
960
672
 
961
 
    _fmt = ("A transaction related operation was attempted after"
962
 
            " the transaction finished.")
 
673
    _fmt = "A transaction related operation was attempted after the transaction finished."
963
674
 
964
675
 
965
676
class ObjectNotLocked(LockError):
983
694
 
984
695
class UnlockableTransport(LockError):
985
696
 
986
 
    internal_error = False
987
 
 
988
697
    _fmt = "Cannot lock: transport is read only: %(transport)s"
989
698
 
990
699
    def __init__(self, transport):
993
702
 
994
703
class LockContention(LockError):
995
704
 
996
 
    _fmt = 'Could not acquire lock "%(lock)s"'
 
705
    _fmt = "Could not acquire lock %(lock)s"
997
706
    # TODO: show full url for lock, combining the transport and relative
998
707
    # bits?
999
708
 
1000
709
    internal_error = False
1001
 
 
 
710
    
1002
711
    def __init__(self, lock):
1003
712
        self.lock = lock
1004
713
 
1005
714
 
1006
715
class LockBroken(LockError):
1007
716
 
1008
 
    _fmt = ("Lock was broken while still open: %(lock)s"
1009
 
            " - check storage consistency!")
 
717
    _fmt = "Lock was broken while still open: %(lock)s - check storage consistency!"
1010
718
 
1011
719
    internal_error = False
1012
720
 
1016
724
 
1017
725
class LockBreakMismatch(LockError):
1018
726
 
1019
 
    _fmt = ("Lock was released and re-acquired before being broken:"
1020
 
            " %(lock)s: held by %(holder)r, wanted to break %(target)r")
 
727
    _fmt = "Lock was released and re-acquired before being broken: %(lock)s: held by %(holder)r, wanted to break %(target)r"
1021
728
 
1022
729
    internal_error = False
1023
730
 
1037
744
        self.lock = lock
1038
745
 
1039
746
 
1040
 
class TokenLockingNotSupported(LockError):
1041
 
 
1042
 
    _fmt = "The object %(obj)s does not support token specifying a token when locking."
1043
 
 
1044
 
    def __init__(self, obj):
1045
 
        self.obj = obj
1046
 
 
1047
 
 
1048
 
class TokenMismatch(LockBroken):
1049
 
 
1050
 
    _fmt = "The lock token %(given_token)r does not match lock token %(lock_token)r."
1051
 
 
1052
 
    internal_error = True
1053
 
 
1054
 
    def __init__(self, given_token, lock_token):
1055
 
        self.given_token = given_token
1056
 
        self.lock_token = lock_token
1057
 
 
1058
 
 
1059
747
class PointlessCommit(BzrError):
1060
748
 
1061
749
    _fmt = "No changes to commit"
1062
750
 
1063
751
 
1064
 
class CannotCommitSelectedFileMerge(BzrError):
1065
 
 
1066
 
    _fmt = 'Selected-file commit of merges is not supported yet:'\
1067
 
        ' files %(files_str)s'
1068
 
 
1069
 
    def __init__(self, files):
1070
 
        files_str = ', '.join(files)
1071
 
        BzrError.__init__(self, files=files, files_str=files_str)
1072
 
 
1073
 
 
1074
 
class BadCommitMessageEncoding(BzrError):
1075
 
 
1076
 
    _fmt = 'The specified commit message contains characters unsupported by '\
1077
 
        'the current encoding.'
1078
 
 
1079
 
 
1080
752
class UpgradeReadonly(BzrError):
1081
753
 
1082
754
    _fmt = "Upgrade URL cannot work with readonly URLs."
1096
768
    _fmt = "Commit refused because there are unknowns in the tree."
1097
769
 
1098
770
 
1099
 
class NoSuchRevision(InternalBzrError):
1100
 
 
1101
 
    _fmt = "%(branch)s has no revision %(revision)s"
 
771
class NoSuchRevision(BzrError):
 
772
 
 
773
    _fmt = "Branch %(branch)s has no revision %(revision)s"
 
774
 
 
775
    internal_error = True
1102
776
 
1103
777
    def __init__(self, branch, revision):
1104
 
        # 'branch' may sometimes be an internal object like a KnitRevisionStore
1105
778
        BzrError.__init__(self, branch=branch, revision=revision)
1106
779
 
1107
780
 
1108
 
class RangeInChangeOption(BzrError):
1109
 
 
1110
 
    _fmt = "Option --change does not accept revision ranges"
1111
 
 
1112
 
 
1113
781
class NoSuchRevisionSpec(BzrError):
1114
782
 
1115
783
    _fmt = "No namespace registered for string: %(spec)r"
1118
786
        BzrError.__init__(self, spec=spec)
1119
787
 
1120
788
 
1121
 
class NoSuchRevisionInTree(NoSuchRevision):
1122
 
    """When using Tree.revision_tree, and the revision is not accessible."""
1123
 
    
1124
 
    _fmt = "The revision id {%(revision_id)s} is not present in the tree %(tree)s."
1125
 
 
1126
 
    def __init__(self, tree, revision_id):
1127
 
        BzrError.__init__(self)
1128
 
        self.tree = tree
1129
 
        self.revision_id = revision_id
1130
 
 
1131
 
 
1132
789
class InvalidRevisionSpec(BzrError):
1133
790
 
1134
 
    _fmt = ("Requested revision: %(spec)r does not exist in branch:"
1135
 
            " %(branch)s%(extra)s")
 
791
    _fmt = "Requested revision: %(spec)r does not exist in branch: %(branch)s%(extra)s"
1136
792
 
1137
793
    def __init__(self, spec, branch, extra=None):
1138
794
        BzrError.__init__(self, branch=branch, spec=spec)
1147
803
    _fmt = "%(branch)s is missing %(object_type)s {%(object_id)s}"
1148
804
 
1149
805
 
1150
 
class AppendRevisionsOnlyViolation(BzrError):
1151
 
 
1152
 
    _fmt = ('Operation denied because it would change the main history,'
1153
 
           ' which is not permitted by the append_revisions_only setting on'
1154
 
           ' branch "%(location)s".')
1155
 
 
1156
 
    def __init__(self, location):
1157
 
       import bzrlib.urlutils as urlutils
1158
 
       location = urlutils.unescape_for_display(location, 'ascii')
1159
 
       BzrError.__init__(self, location=location)
1160
 
 
1161
 
 
1162
806
class DivergedBranches(BzrError):
 
807
    
 
808
    _fmt = "These branches have diverged.  Use the merge command to reconcile them."""
1163
809
 
1164
 
    _fmt = ("These branches have diverged."
1165
 
            " Use the merge command to reconcile them.")
 
810
    internal_error = False
1166
811
 
1167
812
    def __init__(self, branch1, branch2):
1168
813
        self.branch1 = branch1
1169
814
        self.branch2 = branch2
1170
815
 
1171
816
 
1172
 
class NotLefthandHistory(InternalBzrError):
1173
 
 
1174
 
    _fmt = "Supplied history does not follow left-hand parents"
1175
 
 
1176
 
    def __init__(self, history):
1177
 
        BzrError.__init__(self, history=history)
1178
 
 
1179
 
 
1180
817
class UnrelatedBranches(BzrError):
1181
818
 
1182
 
    _fmt = ("Branches have no common ancestor, and"
1183
 
            " no merge base revision was specified.")
1184
 
 
1185
 
 
1186
 
class CannotReverseCherrypick(BzrError):
1187
 
 
1188
 
    _fmt = ('Selected merge cannot perform reverse cherrypicks.  Try merge3'
1189
 
            ' or diff3.')
 
819
    _fmt = "Branches have no common ancestor, and no merge base revision was specified."
 
820
 
 
821
    internal_error = False
1190
822
 
1191
823
 
1192
824
class NoCommonAncestor(BzrError):
1200
832
 
1201
833
class NoCommonRoot(BzrError):
1202
834
 
1203
 
    _fmt = ("Revisions are not derived from the same root: "
1204
 
           "%(revision_a)s %(revision_b)s.")
 
835
    _fmt = "Revisions are not derived from the same root: " \
 
836
           "%(revision_a)s %(revision_b)s."
1205
837
 
1206
838
    def __init__(self, revision_a, revision_b):
1207
839
        BzrError.__init__(self, revision_a=revision_a, revision_b=revision_b)
1230
862
    def __init__(self, bases):
1231
863
        warn("BzrError AmbiguousBase has been deprecated as of bzrlib 0.8.",
1232
864
                DeprecationWarning)
1233
 
        msg = ("The correct base is unclear, because %s are all equally close"
1234
 
                % ", ".join(bases))
 
865
        msg = "The correct base is unclear, because %s are all equally close" %\
 
866
            ", ".join(bases)
1235
867
        BzrError.__init__(self, msg)
1236
868
        self.bases = bases
1237
869
 
1238
870
 
1239
 
class NoCommits(BranchError):
 
871
class NoCommits(BzrError):
1240
872
 
1241
873
    _fmt = "Branch %(branch)s has no commits."
1242
874
 
 
875
    def __init__(self, branch):
 
876
        BzrError.__init__(self, branch=branch)
 
877
 
1243
878
 
1244
879
class UnlistableStore(BzrError):
1245
880
 
1256
891
 
1257
892
class BoundBranchOutOfDate(BzrError):
1258
893
 
1259
 
    _fmt = ("Bound branch %(branch)s is out of date with master branch"
1260
 
            " %(master)s.")
 
894
    _fmt = "Bound branch %(branch)s is out of date with master branch %(master)s."
1261
895
 
1262
896
    def __init__(self, branch, master):
1263
897
        BzrError.__init__(self)
1267
901
        
1268
902
class CommitToDoubleBoundBranch(BzrError):
1269
903
 
1270
 
    _fmt = ("Cannot commit to branch %(branch)s."
1271
 
            " It is bound to %(master)s, which is bound to %(remote)s.")
 
904
    _fmt = "Cannot commit to branch %(branch)s. It is bound to %(master)s, which is bound to %(remote)s."
1272
905
 
1273
906
    def __init__(self, branch, master, remote):
1274
907
        BzrError.__init__(self)
1288
921
 
1289
922
class BoundBranchConnectionFailure(BzrError):
1290
923
 
1291
 
    _fmt = ("Unable to connect to target of bound branch %(branch)s"
1292
 
            " => %(target)s: %(error)s")
 
924
    _fmt = "Unable to connect to target of bound branch %(branch)s => %(target)s: %(error)s"
1293
925
 
1294
926
    def __init__(self, branch, target, error):
1295
927
        BzrError.__init__(self)
1339
971
 
1340
972
class WeaveParentMismatch(WeaveError):
1341
973
 
1342
 
    _fmt = "Parents are mismatched between two revisions. %(message)s"
 
974
    _fmt = "Parents are mismatched between two revisions."
1343
975
    
1344
976
 
1345
977
class WeaveInvalidChecksum(WeaveError):
1349
981
 
1350
982
class WeaveTextDiffers(WeaveError):
1351
983
 
1352
 
    _fmt = ("Weaves differ on text content. Revision:"
1353
 
            " {%(revision_id)s}, %(weave_a)s, %(weave_b)s")
 
984
    _fmt = "Weaves differ on text content. Revision: {%(revision_id)s}, %(weave_a)s, %(weave_b)s"
1354
985
 
1355
986
    def __init__(self, revision_id, weave_a, weave_b):
1356
987
        WeaveError.__init__(self)
1361
992
 
1362
993
class WeaveTextDiffers(WeaveError):
1363
994
 
1364
 
    _fmt = ("Weaves differ on text content. Revision:"
1365
 
            " {%(revision_id)s}, %(weave_a)s, %(weave_b)s")
 
995
    _fmt = "Weaves differ on text content. Revision: {%(revision_id)s}, %(weave_a)s, %(weave_b)s"
1366
996
 
1367
997
    def __init__(self, revision_id, weave_a, weave_b):
1368
998
        WeaveError.__init__(self)
1378
1008
 
1379
1009
class RevisionNotPresent(VersionedFileError):
1380
1010
    
1381
 
    _fmt = 'Revision {%(revision_id)s} not present in "%(file_id)s".'
 
1011
    _fmt = "Revision {%(revision_id)s} not present in %(file_id)s."
1382
1012
 
1383
1013
    def __init__(self, revision_id, file_id):
1384
1014
        VersionedFileError.__init__(self)
1388
1018
 
1389
1019
class RevisionAlreadyPresent(VersionedFileError):
1390
1020
    
1391
 
    _fmt = 'Revision {%(revision_id)s} already present in "%(file_id)s".'
 
1021
    _fmt = "Revision {%(revision_id)s} already present in %(file_id)s."
1392
1022
 
1393
1023
    def __init__(self, revision_id, file_id):
1394
1024
        VersionedFileError.__init__(self)
1396
1026
        self.file_id = file_id
1397
1027
 
1398
1028
 
1399
 
class VersionedFileInvalidChecksum(VersionedFileError):
1400
 
 
1401
 
    _fmt = "Text did not match its checksum: %(message)s"
1402
 
 
1403
 
 
1404
 
class KnitError(InternalBzrError):
 
1029
class KnitError(BzrError):
1405
1030
    
1406
1031
    _fmt = "Knit error"
1407
1032
 
 
1033
    internal_error = True
 
1034
 
 
1035
 
 
1036
class KnitHeaderError(KnitError):
 
1037
 
 
1038
    _fmt = "Knit header error: %(badline)r unexpected for file %(filename)s"
 
1039
 
 
1040
    def __init__(self, badline, filename):
 
1041
        KnitError.__init__(self)
 
1042
        self.badline = badline
 
1043
        self.filename = filename
 
1044
 
1408
1045
 
1409
1046
class KnitCorrupt(KnitError):
1410
1047
 
1416
1053
        self.how = how
1417
1054
 
1418
1055
 
1419
 
class KnitDataStreamIncompatible(KnitError):
1420
 
    # Not raised anymore, as we can convert data streams.  In future we may
1421
 
    # need it again for more exotic cases, so we're keeping it around for now.
1422
 
 
1423
 
    _fmt = "Cannot insert knit data stream of format \"%(stream_format)s\" into knit of format \"%(target_format)s\"."
1424
 
 
1425
 
    def __init__(self, stream_format, target_format):
1426
 
        self.stream_format = stream_format
1427
 
        self.target_format = target_format
1428
 
        
1429
 
 
1430
 
class KnitDataStreamUnknown(KnitError):
1431
 
    # Indicates a data stream we don't know how to handle.
1432
 
 
1433
 
    _fmt = "Cannot parse knit data stream of format \"%(stream_format)s\"."
1434
 
 
1435
 
    def __init__(self, stream_format):
1436
 
        self.stream_format = stream_format
1437
 
        
1438
 
 
1439
 
class KnitHeaderError(KnitError):
1440
 
 
1441
 
    _fmt = 'Knit header error: %(badline)r unexpected for file "%(filename)s".'
1442
 
 
1443
 
    def __init__(self, badline, filename):
1444
 
        KnitError.__init__(self)
1445
 
        self.badline = badline
1446
 
        self.filename = filename
1447
 
 
1448
1056
class KnitIndexUnknownMethod(KnitError):
1449
1057
    """Raised when we don't understand the storage method.
1450
1058
 
1485
1093
        BzrError.__init__(self)
1486
1094
 
1487
1095
 
1488
 
class TooManyConcurrentRequests(InternalBzrError):
1489
 
 
1490
 
    _fmt = ("The medium '%(medium)s' has reached its concurrent request limit."
1491
 
            " Be sure to finish_writing and finish_reading on the"
1492
 
            " currently open request.")
 
1096
class TooManyConcurrentRequests(BzrError):
 
1097
 
 
1098
    _fmt = ("The medium '%(medium)s' has reached its concurrent request limit. "
 
1099
            "Be sure to finish_writing and finish_reading on the "
 
1100
            "current request that is open.")
 
1101
 
 
1102
    internal_error = True
1493
1103
 
1494
1104
    def __init__(self, medium):
1495
1105
        self.medium = medium
1503
1113
        self.details = details
1504
1114
 
1505
1115
 
1506
 
class UnexpectedProtocolVersionMarker(TransportError):
1507
 
 
1508
 
    _fmt = "Received bad protocol version marker: %(marker)r"
1509
 
 
1510
 
    def __init__(self, marker):
1511
 
        self.marker = marker
1512
 
 
1513
 
 
1514
 
class UnknownSmartMethod(InternalBzrError):
1515
 
 
1516
 
    _fmt = "The server does not recognise the '%(verb)s' request."
1517
 
 
1518
 
    def __init__(self, verb):
1519
 
        self.verb = verb
1520
 
 
1521
 
 
1522
 
class SmartMessageHandlerError(InternalBzrError):
1523
 
 
1524
 
    _fmt = "The message handler raised an exception: %(exc_value)s."
1525
 
 
1526
 
    def __init__(self, exc_info):
1527
 
        self.exc_type, self.exc_value, self.tb = exc_info
1528
 
        
1529
 
 
1530
1116
# A set of semi-meaningful errors which can be thrown
1531
1117
class TransportNotPossible(TransportError):
1532
1118
 
1564
1150
 
1565
1151
class InvalidRange(TransportError):
1566
1152
 
1567
 
    _fmt = "Invalid range access in %(path)s at %(offset)s: %(msg)s"
1568
 
 
1569
 
    def __init__(self, path, offset, msg=None):
1570
 
        TransportError.__init__(self, msg)
 
1153
    _fmt = "Invalid range access in %(path)s at %(offset)s."
 
1154
    
 
1155
    def __init__(self, path, offset):
 
1156
        TransportError.__init__(self, ("Invalid range access in %s at %d"
 
1157
                                       % (path, offset)))
1571
1158
        self.path = path
1572
1159
        self.offset = offset
1573
1160
 
1584
1171
class InvalidHttpRange(InvalidHttpResponse):
1585
1172
 
1586
1173
    _fmt = "Invalid http range %(range)r for %(path)s: %(msg)s"
1587
 
 
 
1174
    
1588
1175
    def __init__(self, path, range, msg):
1589
1176
        self.range = range
1590
1177
        InvalidHttpResponse.__init__(self, path, msg)
1593
1180
class InvalidHttpContentType(InvalidHttpResponse):
1594
1181
 
1595
1182
    _fmt = 'Invalid http Content-type "%(ctype)s" for %(path)s: %(msg)s'
1596
 
 
 
1183
    
1597
1184
    def __init__(self, path, ctype, msg):
1598
1185
        self.ctype = ctype
1599
1186
        InvalidHttpResponse.__init__(self, path, msg)
1600
1187
 
1601
1188
 
1602
 
class RedirectRequested(TransportError):
1603
 
 
1604
 
    _fmt = '%(source)s is%(permanently)s redirected to %(target)s'
1605
 
 
1606
 
    def __init__(self, source, target, is_permanent=False, qual_proto=None):
1607
 
        self.source = source
1608
 
        self.target = target
1609
 
        if is_permanent:
1610
 
            self.permanently = ' permanently'
1611
 
        else:
1612
 
            self.permanently = ''
1613
 
        self._qualified_proto = qual_proto
1614
 
        TransportError.__init__(self)
1615
 
 
1616
 
    def _requalify_url(self, url):
1617
 
        """Restore the qualified proto in front of the url"""
1618
 
        # When this exception is raised, source and target are in
1619
 
        # user readable format. But some transports may use a
1620
 
        # different proto (http+urllib:// will present http:// to
1621
 
        # the user. If a qualified proto is specified, the code
1622
 
        # trapping the exception can get the qualified urls to
1623
 
        # properly handle the redirection themself (creating a
1624
 
        # new transport object from the target url for example).
1625
 
        # But checking that the scheme of the original and
1626
 
        # redirected urls are the same can be tricky. (see the
1627
 
        # FIXME in BzrDir.open_from_transport for the unique use
1628
 
        # case so far).
1629
 
        if self._qualified_proto is None:
1630
 
            return url
1631
 
 
1632
 
        # The TODO related to NotBranchError mention that doing
1633
 
        # that kind of manipulation on the urls may not be the
1634
 
        # exception object job. On the other hand, this object is
1635
 
        # the interface between the code and the user so
1636
 
        # presenting the urls in different ways is indeed its
1637
 
        # job...
1638
 
        import urlparse
1639
 
        proto, netloc, path, query, fragment = urlparse.urlsplit(url)
1640
 
        return urlparse.urlunsplit((self._qualified_proto, netloc, path,
1641
 
                                   query, fragment))
1642
 
 
1643
 
    def get_source_url(self):
1644
 
        return self._requalify_url(self.source)
1645
 
 
1646
 
    def get_target_url(self):
1647
 
        return self._requalify_url(self.target)
1648
 
 
1649
 
 
1650
 
class TooManyRedirections(TransportError):
1651
 
 
1652
 
    _fmt = "Too many redirections"
1653
 
 
1654
 
 
1655
1189
class ConflictsInTree(BzrError):
1656
1190
 
1657
1191
    _fmt = "Working tree has conflicts."
1678
1212
 
1679
1213
class SigningFailed(BzrError):
1680
1214
 
1681
 
    _fmt = 'Failed to gpg sign data with command "%(command_line)s"'
 
1215
    _fmt = "Failed to gpg sign data with command %(command_line)r"
1682
1216
 
1683
1217
    def __init__(self, command_line):
1684
1218
        BzrError.__init__(self, command_line=command_line)
1696
1230
 
1697
1231
class CantReprocessAndShowBase(BzrError):
1698
1232
 
1699
 
    _fmt = ("Can't reprocess and show base, because reprocessing obscures "
1700
 
           "the relationship of conflicting lines to the base")
 
1233
    _fmt = "Can't reprocess and show base, because reprocessing obscures " \
 
1234
           "the relationship of conflicting lines to the base"
1701
1235
 
1702
1236
 
1703
1237
class GraphCycleError(BzrError):
1709
1243
        self.graph = graph
1710
1244
 
1711
1245
 
1712
 
class WritingCompleted(InternalBzrError):
 
1246
class WritingCompleted(BzrError):
1713
1247
 
1714
1248
    _fmt = ("The MediumRequest '%(request)s' has already had finish_writing "
1715
1249
            "called upon it - accept bytes may not be called anymore.")
1716
1250
 
 
1251
    internal_error = True
 
1252
 
1717
1253
    def __init__(self, request):
1718
1254
        self.request = request
1719
1255
 
1720
1256
 
1721
 
class WritingNotComplete(InternalBzrError):
 
1257
class WritingNotComplete(BzrError):
1722
1258
 
1723
1259
    _fmt = ("The MediumRequest '%(request)s' has not has finish_writing "
1724
1260
            "called upon it - until the write phase is complete no "
1725
1261
            "data may be read.")
1726
1262
 
 
1263
    internal_error = True
 
1264
 
1727
1265
    def __init__(self, request):
1728
1266
        self.request = request
1729
1267
 
1737
1275
        self.filename = filename
1738
1276
 
1739
1277
 
1740
 
class MediumNotConnected(InternalBzrError):
 
1278
class MediumNotConnected(BzrError):
1741
1279
 
1742
1280
    _fmt = """The medium '%(medium)s' is not connected."""
1743
1281
 
 
1282
    internal_error = True
 
1283
 
1744
1284
    def __init__(self, medium):
1745
1285
        self.medium = medium
1746
1286
 
1747
1287
 
1748
1288
class MustUseDecorated(Exception):
1749
 
 
1750
 
    _fmt = "A decorating function has requested its original command be used."
1751
 
 
 
1289
    
 
1290
    _fmt = """A decorating function has requested its original command be used."""
 
1291
    
1752
1292
 
1753
1293
class NoBundleFound(BzrError):
1754
1294
 
1755
 
    _fmt = 'No bundle was found in "%(filename)s".'
 
1295
    _fmt = "No bundle was found in %(filename)s"
1756
1296
 
1757
1297
    def __init__(self, filename):
1758
1298
        BzrError.__init__(self)
1771
1311
 
1772
1312
class MissingText(BzrError):
1773
1313
 
1774
 
    _fmt = ("Branch %(base)s is missing revision"
1775
 
            " %(text_revision)s of %(file_id)s")
 
1314
    _fmt = "Branch %(base)s is missing revision %(text_revision)s of %(file_id)s"
1776
1315
 
1777
1316
    def __init__(self, branch, text_revision, file_id):
1778
1317
        BzrError.__init__(self)
1782
1321
        self.file_id = file_id
1783
1322
 
1784
1323
 
1785
 
class DuplicateFileId(BzrError):
1786
 
 
1787
 
    _fmt = "File id {%(file_id)s} already exists in inventory as %(entry)s"
1788
 
 
1789
 
    def __init__(self, file_id, entry):
1790
 
        BzrError.__init__(self)
1791
 
        self.file_id = file_id
1792
 
        self.entry = entry
1793
 
 
1794
 
 
1795
1324
class DuplicateKey(BzrError):
1796
1325
 
1797
1326
    _fmt = "Key %(key)s is already present in map"
1798
1327
 
1799
1328
 
1800
 
class DuplicateHelpPrefix(BzrError):
1801
 
 
1802
 
    _fmt = "The prefix %(prefix)s is in the help search path twice."
1803
 
 
1804
 
    def __init__(self, prefix):
1805
 
        self.prefix = prefix
1806
 
 
1807
 
 
1808
1329
class MalformedTransform(BzrError):
1809
1330
 
1810
1331
    _fmt = "Tree transform is malformed %(conflicts)r"
1822
1343
        self.root_trans_id = transform.root
1823
1344
 
1824
1345
 
1825
 
class BzrBadParameter(InternalBzrError):
 
1346
class BzrBadParameter(BzrError):
1826
1347
 
1827
1348
    _fmt = "Bad parameter: %(param)r"
1828
1349
 
1890
1411
    def __init__(self, from_path, to_path, extra=None):
1891
1412
        BzrMoveFailedError.__init__(self, from_path, to_path, extra)
1892
1413
 
1893
 
class BzrRemoveChangedFilesError(BzrError):
1894
 
    """Used when user is trying to remove changed files."""
1895
 
 
1896
 
    _fmt = ("Can't safely remove modified or unknown files:\n"
1897
 
        "%(changes_as_text)s"
1898
 
        "Use --keep to not delete them, or --force to delete them regardless.")
1899
 
 
1900
 
    def __init__(self, tree_delta):
1901
 
        BzrError.__init__(self)
1902
 
        self.changes_as_text = tree_delta.get_changes_as_text()
1903
 
        #self.paths_as_string = '\n'.join(changed_files)
1904
 
        #self.paths_as_string = '\n'.join([quotefn(p) for p in changed_files])
1905
 
 
1906
1414
 
1907
1415
class BzrBadParameterNotString(BzrBadParameter):
1908
1416
 
1916
1424
 
1917
1425
class BzrBadParameterUnicode(BzrBadParameter):
1918
1426
 
1919
 
    _fmt = ("Parameter %(param)s is unicode but"
1920
 
            " only byte-strings are permitted.")
 
1427
    _fmt = "Parameter %(param)s is unicode but only byte-strings are permitted."
1921
1428
 
1922
1429
 
1923
1430
class BzrBadParameterContainsNewline(BzrBadParameter):
1965
1472
        self.format = format
1966
1473
 
1967
1474
 
1968
 
class NoDiffFound(BzrError):
1969
 
 
1970
 
    _fmt = 'Could not find an appropriate Differ for file "%(path)s"'
1971
 
 
1972
 
    def __init__(self, path):
1973
 
        BzrError.__init__(self, path)
1974
 
 
1975
 
 
1976
 
class ExecutableMissing(BzrError):
1977
 
 
1978
 
    _fmt = "%(exe_name)s could not be found on this machine"
1979
 
 
1980
 
    def __init__(self, exe_name):
1981
 
        BzrError.__init__(self, exe_name=exe_name)
1982
 
 
1983
 
 
1984
1475
class NoDiff(BzrError):
1985
1476
 
1986
1477
    _fmt = "Diff is not installed on this machine: %(msg)s"
1994
1485
    _fmt = "Diff3 is not installed on this machine."
1995
1486
 
1996
1487
 
1997
 
class ExistingContent(BzrError):
1998
 
    # Added in bzrlib 0.92, used by VersionedFile.add_lines.
1999
 
 
2000
 
    _fmt = "The content being inserted is already present."
2001
 
 
2002
 
 
2003
1488
class ExistingLimbo(BzrError):
2004
1489
 
2005
1490
    _fmt = """This tree contains left-over files from a failed operation.
2011
1496
       self.limbo_dir = limbo_dir
2012
1497
 
2013
1498
 
2014
 
class ExistingPendingDeletion(BzrError):
2015
 
 
2016
 
    _fmt = """This tree contains left-over files from a failed operation.
2017
 
    Please examine %(pending_deletion)s to see if it contains any files you
2018
 
    wish to keep, and delete it when you are done."""
2019
 
 
2020
 
    def __init__(self, pending_deletion):
2021
 
       BzrError.__init__(self, pending_deletion=pending_deletion)
2022
 
 
2023
 
 
2024
1499
class ImmortalLimbo(BzrError):
2025
1500
 
2026
 
    _fmt = """Unable to delete transform temporary directory %(limbo_dir)s.
 
1501
    _fmt = """Unable to delete transform temporary directory $(limbo_dir)s.
2027
1502
    Please examine %(limbo_dir)s to see if it contains any files you wish to
2028
1503
    keep, and delete it when you are done."""
2029
1504
 
2032
1507
       self.limbo_dir = limbo_dir
2033
1508
 
2034
1509
 
2035
 
class ImmortalPendingDeletion(BzrError):
2036
 
 
2037
 
    _fmt = ("Unable to delete transform temporary directory "
2038
 
    "%(pending_deletion)s.  Please examine %(pending_deletion)s to see if it "
2039
 
    "contains any files you wish to keep, and delete it when you are done.")
2040
 
 
2041
 
    def __init__(self, pending_deletion):
2042
 
       BzrError.__init__(self, pending_deletion=pending_deletion)
2043
 
 
2044
 
 
2045
1510
class OutOfDateTree(BzrError):
2046
1511
 
2047
1512
    _fmt = "Working tree is out of date, please run 'bzr update'."
2051
1516
        self.tree = tree
2052
1517
 
2053
1518
 
2054
 
class PublicBranchOutOfDate(BzrError):
2055
 
 
2056
 
    _fmt = 'Public branch "%(public_location)s" lacks revision '\
2057
 
        '"%(revstring)s".'
2058
 
 
2059
 
    def __init__(self, public_location, revstring):
2060
 
        import bzrlib.urlutils as urlutils
2061
 
        public_location = urlutils.unescape_for_display(public_location,
2062
 
                                                        'ascii')
2063
 
        BzrError.__init__(self, public_location=public_location,
2064
 
                          revstring=revstring)
2065
 
 
2066
 
 
2067
1519
class MergeModifiedFormatError(BzrError):
2068
1520
 
2069
1521
    _fmt = "Error in merge modified format"
2074
1526
    _fmt = "Format error in conflict listings"
2075
1527
 
2076
1528
 
2077
 
class CorruptDirstate(BzrError):
2078
 
 
2079
 
    _fmt = ("Inconsistency in dirstate file %(dirstate_path)s.\n"
2080
 
            "Error: %(description)s")
2081
 
 
2082
 
    def __init__(self, dirstate_path, description):
2083
 
        BzrError.__init__(self)
2084
 
        self.dirstate_path = dirstate_path
2085
 
        self.description = description
2086
 
 
2087
 
 
2088
1529
class CorruptRepository(BzrError):
2089
1530
 
2090
 
    _fmt = ("An error has been detected in the repository %(repo_path)s.\n"
2091
 
            "Please run bzr reconcile on this repository.")
 
1531
    _fmt = """An error has been detected in the repository %(repo_path)s.
 
1532
Please run bzr reconcile on this repository."""
2092
1533
 
2093
1534
    def __init__(self, repo):
2094
1535
        BzrError.__init__(self)
2095
1536
        self.repo_path = repo.bzrdir.root_transport.base
2096
1537
 
2097
1538
 
2098
 
class InconsistentDelta(BzrError):
2099
 
    """Used when we get a delta that is not valid."""
2100
 
 
2101
 
    _fmt = ("An inconsistent delta was supplied involving %(path)r,"
2102
 
            " %(file_id)r\nreason: %(reason)s")
2103
 
 
2104
 
    def __init__(self, path, file_id, reason):
2105
 
        BzrError.__init__(self)
2106
 
        self.path = path
2107
 
        self.file_id = file_id
2108
 
        self.reason = reason
2109
 
 
2110
 
 
2111
1539
class UpgradeRequired(BzrError):
2112
1540
 
2113
1541
    _fmt = "To use this feature you must upgrade your branch at %(path)s."
2117
1545
        self.path = path
2118
1546
 
2119
1547
 
2120
 
class RepositoryUpgradeRequired(UpgradeRequired):
2121
 
 
2122
 
    _fmt = "To use this feature you must upgrade your repository at %(path)s."
2123
 
 
2124
 
 
2125
1548
class LocalRequiresBoundBranch(BzrError):
2126
1549
 
2127
1550
    _fmt = "Cannot perform local-only commits on unbound branches."
2134
1557
 
2135
1558
class InvalidProgressBarType(BzrError):
2136
1559
 
2137
 
    _fmt = ("Environment variable BZR_PROGRESS_BAR='%(bar_type)s"
2138
 
            " is not a supported type Select one of: %(valid_types)s")
 
1560
    _fmt = """Environment variable BZR_PROGRESS_BAR='%(bar_type)s is not a supported type
 
1561
Select one of: %(valid_types)s"""
2139
1562
 
2140
1563
    def __init__(self, bar_type, valid_types):
2141
1564
        BzrError.__init__(self, bar_type=bar_type, valid_types=valid_types)
2143
1566
 
2144
1567
class UnsupportedOperation(BzrError):
2145
1568
 
2146
 
    _fmt = ("The method %(mname)s is not supported on"
2147
 
            " objects of type %(tname)s.")
 
1569
    _fmt = "The method %(mname)s is not supported on objects of type %(tname)s."
2148
1570
 
2149
1571
    def __init__(self, method, method_self):
2150
1572
        self.method = method
2157
1579
 
2158
1580
 
2159
1581
class NonAsciiRevisionId(UnsupportedOperation):
2160
 
    """Raised when a commit is attempting to set a non-ascii revision id
2161
 
       but cant.
2162
 
    """
 
1582
    """Raised when a commit is attempting to set a non-ascii revision id but cant."""
2163
1583
 
2164
1584
 
2165
1585
class BinaryFile(BzrError):
2178
1598
 
2179
1599
class TestamentMismatch(BzrError):
2180
1600
 
2181
 
    _fmt = """Testament did not match expected value.
2182
 
       For revision_id {%(revision_id)s}, expected {%(expected)s}, measured
 
1601
    _fmt = """Testament did not match expected value.  
 
1602
       For revision_id {%(revision_id)s}, expected {%(expected)s}, measured 
2183
1603
       {%(measured)s}"""
2184
1604
 
2185
1605
    def __init__(self, revision_id, expected, measured):
2254
1674
        BadInventoryFormat.__init__(self, msg=msg)
2255
1675
 
2256
1676
 
2257
 
class RootNotRich(BzrError):
2258
 
 
2259
 
    _fmt = """This operation requires rich root data storage"""
2260
 
 
2261
 
 
2262
 
class NoSmartMedium(InternalBzrError):
 
1677
class NoSmartMedium(BzrError):
2263
1678
 
2264
1679
    _fmt = "The transport '%(transport)s' cannot tunnel the smart protocol."
 
1680
    internal_error = True
2265
1681
 
2266
1682
    def __init__(self, transport):
2267
1683
        self.transport = transport
2271
1687
 
2272
1688
    _fmt = "No smart server available at %(url)s"
2273
1689
 
2274
 
    @symbol_versioning.deprecated_method(symbol_versioning.one_four)
2275
1690
    def __init__(self, url):
2276
1691
        self.url = url
2277
1692
 
2285
1700
        self.vendor = vendor
2286
1701
 
2287
1702
 
2288
 
class SSHVendorNotFound(BzrError):
2289
 
 
2290
 
    _fmt = ("Don't know how to handle SSH connections."
2291
 
            " Please set BZR_SSH environment variable.")
2292
 
 
2293
 
 
2294
 
class GhostRevisionsHaveNoRevno(BzrError):
2295
 
    """When searching for revnos, if we encounter a ghost, we are stuck"""
2296
 
 
2297
 
    _fmt = ("Could not determine revno for {%(revision_id)s} because"
2298
 
            " its ancestry shows a ghost at {%(ghost_revision_id)s}")
2299
 
 
2300
 
    def __init__(self, revision_id, ghost_revision_id):
2301
 
        self.revision_id = revision_id
2302
 
        self.ghost_revision_id = ghost_revision_id
2303
 
 
2304
 
        
2305
1703
class GhostRevisionUnusableHere(BzrError):
2306
1704
 
2307
1705
    _fmt = "Ghost revision {%(revision_id)s} cannot be used here."
2311
1709
        self.revision_id = revision_id
2312
1710
 
2313
1711
 
2314
 
class IllegalUseOfScopeReplacer(InternalBzrError):
2315
 
 
2316
 
    _fmt = ("ScopeReplacer object %(name)r was used incorrectly:"
2317
 
            " %(msg)s%(extra)s")
 
1712
class IllegalUseOfScopeReplacer(BzrError):
 
1713
 
 
1714
    _fmt = "ScopeReplacer object %(name)r was used incorrectly: %(msg)s%(extra)s"
 
1715
 
 
1716
    internal_error = True
2318
1717
 
2319
1718
    def __init__(self, name, msg, extra=None):
2320
1719
        BzrError.__init__(self)
2326
1725
            self.extra = ''
2327
1726
 
2328
1727
 
2329
 
class InvalidImportLine(InternalBzrError):
 
1728
class InvalidImportLine(BzrError):
2330
1729
 
2331
1730
    _fmt = "Not a valid import statement: %(msg)\n%(text)s"
2332
1731
 
 
1732
    internal_error = True
 
1733
 
2333
1734
    def __init__(self, text, msg):
2334
1735
        BzrError.__init__(self)
2335
1736
        self.text = text
2336
1737
        self.msg = msg
2337
1738
 
2338
1739
 
2339
 
class ImportNameCollision(InternalBzrError):
2340
 
 
2341
 
    _fmt = ("Tried to import an object to the same name as"
2342
 
            " an existing object. %(name)s")
2343
 
 
2344
 
    def __init__(self, name):
2345
 
        BzrError.__init__(self)
2346
 
        self.name = name
2347
 
 
2348
 
 
2349
 
class NotAMergeDirective(BzrError):
2350
 
    """File starting with %(firstline)r is not a merge directive"""
2351
 
    def __init__(self, firstline):
2352
 
        BzrError.__init__(self, firstline=firstline)
2353
 
 
2354
 
 
2355
 
class NoMergeSource(BzrError):
2356
 
    """Raise if no merge source was specified for a merge directive"""
2357
 
 
2358
 
    _fmt = "A merge directive must provide either a bundle or a public"\
2359
 
        " branch location."
2360
 
 
2361
 
 
2362
 
class IllegalMergeDirectivePayload(BzrError):
2363
 
    """A merge directive contained something other than a patch or bundle"""
2364
 
 
2365
 
    _fmt = "Bad merge directive payload %(start)r"
2366
 
 
2367
 
    def __init__(self, start):
2368
 
        BzrError(self)
2369
 
        self.start = start
2370
 
 
2371
 
 
2372
 
class PatchVerificationFailed(BzrError):
2373
 
    """A patch from a merge directive could not be verified"""
2374
 
 
2375
 
    _fmt = "Preview patch does not match requested changes."
2376
 
 
2377
 
 
2378
 
class PatchMissing(BzrError):
2379
 
    """Raise a patch type was specified but no patch supplied"""
2380
 
 
2381
 
    _fmt = "Patch_type was %(patch_type)s, but no patch was supplied."
2382
 
 
2383
 
    def __init__(self, patch_type):
2384
 
        BzrError.__init__(self)
2385
 
        self.patch_type = patch_type
2386
 
 
2387
 
 
2388
 
class TargetNotBranch(BzrError):
2389
 
    """A merge directive's target branch is required, but isn't a branch"""
2390
 
 
2391
 
    _fmt = ("Your branch does not have all of the revisions required in "
2392
 
            "order to merge this merge directive and the target "
2393
 
            "location specified in the merge directive is not a branch: "
2394
 
            "%(location)s.")
2395
 
 
2396
 
    def __init__(self, location):
2397
 
        BzrError.__init__(self)
2398
 
        self.location = location
2399
 
 
2400
 
 
2401
 
class UnsupportedInventoryKind(BzrError):
2402
 
    
2403
 
    _fmt = """Unsupported entry kind %(kind)s"""
2404
 
 
2405
 
    def __init__(self, kind):
2406
 
        self.kind = kind
2407
 
 
2408
 
 
2409
 
class BadSubsumeSource(BzrError):
2410
 
 
2411
 
    _fmt = "Can't subsume %(other_tree)s into %(tree)s. %(reason)s"
2412
 
 
2413
 
    def __init__(self, tree, other_tree, reason):
2414
 
        self.tree = tree
2415
 
        self.other_tree = other_tree
2416
 
        self.reason = reason
2417
 
 
2418
 
 
2419
 
class SubsumeTargetNeedsUpgrade(BzrError):
2420
 
    
2421
 
    _fmt = """Subsume target %(other_tree)s needs to be upgraded."""
2422
 
 
2423
 
    def __init__(self, other_tree):
2424
 
        self.other_tree = other_tree
2425
 
 
2426
 
 
2427
 
class BadReferenceTarget(InternalBzrError):
2428
 
 
2429
 
    _fmt = "Can't add reference to %(other_tree)s into %(tree)s." \
2430
 
           "%(reason)s"
2431
 
 
2432
 
    def __init__(self, tree, other_tree, reason):
2433
 
        self.tree = tree
2434
 
        self.other_tree = other_tree
2435
 
        self.reason = reason
2436
 
 
2437
 
 
2438
 
class NoSuchTag(BzrError):
2439
 
 
2440
 
    _fmt = "No such tag: %(tag_name)s"
2441
 
 
2442
 
    def __init__(self, tag_name):
2443
 
        self.tag_name = tag_name
2444
 
 
2445
 
 
2446
 
class TagsNotSupported(BzrError):
2447
 
 
2448
 
    _fmt = ("Tags not supported by %(branch)s;"
2449
 
            " you may be able to use bzr upgrade --dirstate-tags.")
2450
 
 
2451
 
    def __init__(self, branch):
2452
 
        self.branch = branch
2453
 
 
2454
 
        
2455
 
class TagAlreadyExists(BzrError):
2456
 
 
2457
 
    _fmt = "Tag %(tag_name)s already exists."
2458
 
 
2459
 
    def __init__(self, tag_name):
2460
 
        self.tag_name = tag_name
2461
 
 
2462
 
 
2463
 
class MalformedBugIdentifier(BzrError):
2464
 
 
2465
 
    _fmt = "Did not understand bug identifier %(bug_id)s: %(reason)s"
2466
 
 
2467
 
    def __init__(self, bug_id, reason):
2468
 
        self.bug_id = bug_id
2469
 
        self.reason = reason
2470
 
 
2471
 
 
2472
 
class InvalidBugTrackerURL(BzrError):
2473
 
 
2474
 
    _fmt = ("The URL for bug tracker \"%(abbreviation)s\" doesn't "
2475
 
            "contain {id}: %(url)s")
2476
 
 
2477
 
    def __init__(self, abbreviation, url):
2478
 
        self.abbreviation = abbreviation
2479
 
        self.url = url
2480
 
 
2481
 
 
2482
 
class UnknownBugTrackerAbbreviation(BzrError):
2483
 
 
2484
 
    _fmt = ("Cannot find registered bug tracker called %(abbreviation)s "
2485
 
            "on %(branch)s")
2486
 
 
2487
 
    def __init__(self, abbreviation, branch):
2488
 
        self.abbreviation = abbreviation
2489
 
        self.branch = branch
2490
 
 
2491
 
 
2492
 
class UnexpectedSmartServerResponse(BzrError):
2493
 
 
2494
 
    _fmt = "Could not understand response from smart server: %(response_tuple)r"
2495
 
 
2496
 
    def __init__(self, response_tuple):
2497
 
        self.response_tuple = response_tuple
2498
 
 
2499
 
 
2500
 
class ErrorFromSmartServer(BzrError):
2501
 
 
2502
 
    _fmt = "Error received from smart server: %(error_tuple)r"
 
1740
class ImportNameCollision(BzrError):
 
1741
 
 
1742
    _fmt = "Tried to import an object to the same name as an existing object. %(name)s"
2503
1743
 
2504
1744
    internal_error = True
2505
1745
 
2506
 
    def __init__(self, error_tuple):
2507
 
        self.error_tuple = error_tuple
2508
 
        try:
2509
 
            self.error_verb = error_tuple[0]
2510
 
        except IndexError:
2511
 
            self.error_verb = None
2512
 
        self.error_args = error_tuple[1:]
2513
 
 
2514
 
 
2515
 
class ContainerError(BzrError):
2516
 
    """Base class of container errors."""
2517
 
 
2518
 
 
2519
 
class UnknownContainerFormatError(ContainerError):
2520
 
 
2521
 
    _fmt = "Unrecognised container format: %(container_format)r"
2522
 
    
2523
 
    def __init__(self, container_format):
2524
 
        self.container_format = container_format
2525
 
 
2526
 
 
2527
 
class UnexpectedEndOfContainerError(ContainerError):
2528
 
 
2529
 
    _fmt = "Unexpected end of container stream"
2530
 
 
2531
 
 
2532
 
class UnknownRecordTypeError(ContainerError):
2533
 
 
2534
 
    _fmt = "Unknown record type: %(record_type)r"
2535
 
 
2536
 
    def __init__(self, record_type):
2537
 
        self.record_type = record_type
2538
 
 
2539
 
 
2540
 
class InvalidRecordError(ContainerError):
2541
 
 
2542
 
    _fmt = "Invalid record: %(reason)s"
2543
 
 
2544
 
    def __init__(self, reason):
2545
 
        self.reason = reason
2546
 
 
2547
 
 
2548
 
class ContainerHasExcessDataError(ContainerError):
2549
 
 
2550
 
    _fmt = "Container has data after end marker: %(excess)r"
2551
 
 
2552
 
    def __init__(self, excess):
2553
 
        self.excess = excess
2554
 
 
2555
 
 
2556
 
class DuplicateRecordNameError(ContainerError):
2557
 
 
2558
 
    _fmt = "Container has multiple records with the same name: %(name)s"
2559
 
 
2560
 
    def __init__(self, name):
2561
 
        self.name = name
2562
 
 
2563
 
 
2564
 
class NoDestinationAddress(InternalBzrError):
2565
 
 
2566
 
    _fmt = "Message does not have a destination address."
2567
 
 
2568
 
 
2569
 
class RepositoryDataStreamError(BzrError):
2570
 
 
2571
 
    _fmt = "Corrupt or incompatible data stream: %(reason)s"
2572
 
 
2573
 
    def __init__(self, reason):
2574
 
        self.reason = reason
2575
 
 
2576
 
 
2577
 
class SMTPError(BzrError):
2578
 
 
2579
 
    _fmt = "SMTP error: %(error)s"
2580
 
 
2581
 
    def __init__(self, error):
2582
 
        self.error = error
2583
 
 
2584
 
 
2585
 
class NoMessageSupplied(BzrError):
2586
 
 
2587
 
    _fmt = "No message supplied."
2588
 
 
2589
 
 
2590
 
class NoMailAddressSpecified(BzrError):
2591
 
 
2592
 
    _fmt = "No mail-to address specified."
2593
 
 
2594
 
 
2595
 
class UnknownMailClient(BzrError):
2596
 
 
2597
 
    _fmt = "Unknown mail client: %(mail_client)s"
2598
 
 
2599
 
    def __init__(self, mail_client):
2600
 
        BzrError.__init__(self, mail_client=mail_client)
2601
 
 
2602
 
 
2603
 
class MailClientNotFound(BzrError):
2604
 
 
2605
 
    _fmt = "Unable to find mail client with the following names:"\
2606
 
        " %(mail_command_list_string)s"
2607
 
 
2608
 
    def __init__(self, mail_command_list):
2609
 
        mail_command_list_string = ', '.join(mail_command_list)
2610
 
        BzrError.__init__(self, mail_command_list=mail_command_list,
2611
 
                          mail_command_list_string=mail_command_list_string)
2612
 
 
2613
 
class SMTPConnectionRefused(SMTPError):
2614
 
 
2615
 
    _fmt = "SMTP connection to %(host)s refused"
2616
 
 
2617
 
    def __init__(self, error, host):
2618
 
        self.error = error
2619
 
        self.host = host
2620
 
 
2621
 
 
2622
 
class DefaultSMTPConnectionRefused(SMTPConnectionRefused):
2623
 
 
2624
 
    _fmt = "Please specify smtp_server.  No server at default %(host)s."
2625
 
 
2626
 
 
2627
 
class BzrDirError(BzrError):
2628
 
 
2629
 
    def __init__(self, bzrdir):
2630
 
        import bzrlib.urlutils as urlutils
2631
 
        display_url = urlutils.unescape_for_display(bzrdir.root_transport.base,
2632
 
                                                    'ascii')
2633
 
        BzrError.__init__(self, bzrdir=bzrdir, display_url=display_url)
2634
 
 
2635
 
 
2636
 
class UnsyncedBranches(BzrDirError):
2637
 
 
2638
 
    _fmt = ("'%(display_url)s' is not in sync with %(target_url)s.  See"
2639
 
            " bzr help sync-for-reconfigure.")
2640
 
 
2641
 
    def __init__(self, bzrdir, target_branch):
2642
 
        BzrDirError.__init__(self, bzrdir)
2643
 
        import bzrlib.urlutils as urlutils
2644
 
        self.target_url = urlutils.unescape_for_display(target_branch.base,
2645
 
                                                        'ascii')
2646
 
 
2647
 
 
2648
 
class AlreadyBranch(BzrDirError):
2649
 
 
2650
 
    _fmt = "'%(display_url)s' is already a branch."
2651
 
 
2652
 
 
2653
 
class AlreadyTree(BzrDirError):
2654
 
 
2655
 
    _fmt = "'%(display_url)s' is already a tree."
2656
 
 
2657
 
 
2658
 
class AlreadyCheckout(BzrDirError):
2659
 
 
2660
 
    _fmt = "'%(display_url)s' is already a checkout."
2661
 
 
2662
 
 
2663
 
class AlreadyLightweightCheckout(BzrDirError):
2664
 
 
2665
 
    _fmt = "'%(display_url)s' is already a lightweight checkout."
2666
 
 
2667
 
 
2668
 
class AlreadyUsingShared(BzrDirError):
2669
 
 
2670
 
    _fmt = "'%(display_url)s' is already using a shared repository."
2671
 
 
2672
 
 
2673
 
class AlreadyStandalone(BzrDirError):
2674
 
 
2675
 
    _fmt = "'%(display_url)s' is already standalone."
2676
 
 
2677
 
 
2678
 
class ReconfigurationNotSupported(BzrDirError):
2679
 
 
2680
 
    _fmt = "Requested reconfiguration of '%(display_url)s' is not supported."
2681
 
 
2682
 
 
2683
 
class NoBindLocation(BzrDirError):
2684
 
 
2685
 
    _fmt = "No location could be found to bind to at %(display_url)s."
2686
 
 
2687
 
 
2688
 
class UncommittedChanges(BzrError):
2689
 
 
2690
 
    _fmt = 'Working tree "%(display_url)s" has uncommitted changes.'
2691
 
 
2692
 
    def __init__(self, tree):
2693
 
        import bzrlib.urlutils as urlutils
2694
 
        display_url = urlutils.unescape_for_display(
2695
 
            tree.bzrdir.root_transport.base, 'ascii')
2696
 
        BzrError.__init__(self, tree=tree, display_url=display_url)
2697
 
 
2698
 
 
2699
 
class MissingTemplateVariable(BzrError):
2700
 
 
2701
 
    _fmt = 'Variable {%(name)s} is not available.'
2702
 
 
2703
 
    def __init__(self, name):
2704
 
        self.name = name
2705
 
 
2706
 
 
2707
 
class NoTemplate(BzrError):
2708
 
 
2709
 
    _fmt = 'No template specified.'
2710
 
 
2711
 
 
2712
 
class UnableCreateSymlink(BzrError):
2713
 
 
2714
 
    _fmt = 'Unable to create symlink %(path_str)son this platform'
2715
 
 
2716
 
    def __init__(self, path=None):
2717
 
        path_str = ''
2718
 
        if path:
2719
 
            try:
2720
 
                path_str = repr(str(path))
2721
 
            except UnicodeEncodeError:
2722
 
                path_str = repr(path)
2723
 
            path_str += ' '
2724
 
        self.path_str = path_str
2725
 
 
2726
 
 
2727
 
class UnsupportedTimezoneFormat(BzrError):
2728
 
 
2729
 
    _fmt = ('Unsupported timezone format "%(timezone)s", '
2730
 
            'options are "utc", "original", "local".')
2731
 
 
2732
 
    def __init__(self, timezone):
2733
 
        self.timezone = timezone
2734
 
 
2735
 
 
2736
 
class CommandAvailableInPlugin(StandardError):
2737
 
    
2738
 
    internal_error = False
2739
 
 
2740
 
    def __init__(self, cmd_name, plugin_metadata, provider):
2741
 
        
2742
 
        self.plugin_metadata = plugin_metadata
2743
 
        self.cmd_name = cmd_name
2744
 
        self.provider = provider
2745
 
 
2746
 
    def __str__(self):
2747
 
 
2748
 
        _fmt = ('"%s" is not a standard bzr command. \n' 
2749
 
                'However, the following official plugin provides this command: %s\n'
2750
 
                'You can install it by going to: %s'
2751
 
                % (self.cmd_name, self.plugin_metadata['name'], 
2752
 
                    self.plugin_metadata['url']))
2753
 
 
2754
 
        return _fmt
2755
 
 
2756
 
 
2757
 
class NoPluginAvailable(BzrError):
2758
 
    pass    
2759
 
 
2760
 
 
2761
 
class NotATerminal(BzrError):
2762
 
 
2763
 
    _fmt = 'Unable to ask for a password without real terminal.'
2764
 
 
2765
 
 
2766
 
class UnableEncodePath(BzrError):
2767
 
 
2768
 
    _fmt = ('Unable to encode %(kind)s path %(path)r in '
2769
 
            'user encoding %(user_encoding)s')
2770
 
 
2771
 
    def __init__(self, path, kind):
2772
 
        self.path = path
2773
 
        self.kind = kind
2774
 
        self.user_encoding = osutils.get_user_encoding()
2775
 
 
2776
 
 
2777
 
class NoSuchAlias(BzrError):
2778
 
 
2779
 
    _fmt = ('The alias "%(alias_name)s" does not exist.')
2780
 
 
2781
 
    def __init__(self, alias_name):
2782
 
        BzrError.__init__(self, alias_name=alias_name)
2783
 
 
2784
 
 
2785
 
class DirectoryLookupFailure(BzrError):
2786
 
    """Base type for lookup errors."""
2787
 
 
2788
 
    pass
2789
 
 
2790
 
 
2791
 
class InvalidLocationAlias(DirectoryLookupFailure):
2792
 
 
2793
 
    _fmt = '"%(alias_name)s" is not a valid location alias.'
2794
 
 
2795
 
    def __init__(self, alias_name):
2796
 
        DirectoryLookupFailure.__init__(self, alias_name=alias_name)
2797
 
 
2798
 
 
2799
 
class UnsetLocationAlias(DirectoryLookupFailure):
2800
 
 
2801
 
    _fmt = 'No %(alias_name)s location assigned.'
2802
 
 
2803
 
    def __init__(self, alias_name):
2804
 
        DirectoryLookupFailure.__init__(self, alias_name=alias_name[1:])
2805
 
 
2806
 
 
2807
 
class CannotBindAddress(BzrError):
2808
 
 
2809
 
    _fmt = 'Cannot bind address "%(host)s:%(port)i": %(orig_error)s.'
2810
 
 
2811
 
    def __init__(self, host, port, orig_error):
2812
 
        BzrError.__init__(self, host=host, port=port,
2813
 
            orig_error=orig_error[1])
2814
 
 
2815
 
 
2816
 
class UnknownRules(BzrError):
2817
 
 
2818
 
    _fmt = ('Unknown rules detected: %(unknowns_str)s.')
2819
 
 
2820
 
    def __init__(self, unknowns):
2821
 
        BzrError.__init__(self, unknowns_str=", ".join(unknowns))
2822
 
 
2823
 
 
2824
 
class HookFailed(BzrError):
2825
 
    """Raised when a pre_change_branch_tip hook function fails anything other
2826
 
    than TipChangeRejected.
2827
 
    """
2828
 
 
2829
 
    _fmt = ("Hook '%(hook_name)s' during %(hook_stage)s failed:\n"
2830
 
            "%(traceback_text)s%(exc_value)s")
2831
 
 
2832
 
    def __init__(self, hook_stage, hook_name, exc_info):
2833
 
        import traceback
2834
 
        self.hook_stage = hook_stage
2835
 
        self.hook_name = hook_name
2836
 
        self.exc_info = exc_info
2837
 
        self.exc_type = exc_info[0]
2838
 
        self.exc_value = exc_info[1]
2839
 
        self.exc_tb = exc_info[2]
2840
 
        self.traceback_text = ''.join(traceback.format_tb(self.exc_tb))
2841
 
 
2842
 
 
2843
 
class TipChangeRejected(BzrError):
2844
 
    """A pre_change_branch_tip hook function may raise this to cleanly and
2845
 
    explicitly abort a change to a branch tip.
2846
 
    """
2847
 
    
2848
 
    _fmt = u"Tip change rejected: %(msg)s"
2849
 
 
2850
 
    def __init__(self, msg):
2851
 
        self.msg = msg
2852
 
 
 
1746
    def __init__(self, name):
 
1747
        BzrError.__init__(self)
 
1748
        self.name = name