~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/errors.py

  • Committer: Martin Pool
  • Date: 2008-04-30 08:04:11 UTC
  • mto: This revision was merged to the branch mainline in revision 3396.
  • Revision ID: mbp@sourcefrog.net-20080430080411-imrex2wtwpb9eivj
_format_version_tuple can take a 3-tuple

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005, 2006 Canonical Ltd
 
1
# Copyright (C) 2005, 2006, 2007, 2008 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
 
47
53
class BzrError(StandardError):
48
54
    """
49
55
    Base class for errors raised by bzrlib.
50
56
 
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
 
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
53
59
    probably a user or environment error and they don't need the gory details.
54
60
    (That can be overridden by -Derror on the command line.)
55
61
 
95
101
        try:
96
102
            fmt = self._get_format_string()
97
103
            if fmt:
98
 
                s = fmt % self.__dict__
 
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
99
109
                # __str__() should always return a 'str' object
100
110
                # never a 'unicode' object.
101
111
                if isinstance(s, unicode):
102
112
                    return s.encode('utf8')
103
113
                return s
104
114
        except (AttributeError, TypeError, NameError, ValueError, KeyError), e:
105
 
            return 'Unprintable exception %s: dict=%r, fmt=%r, error=%s' \
 
115
            return 'Unprintable exception %s: dict=%r, fmt=%r, error=%r' \
106
116
                % (self.__class__.__name__,
107
117
                   self.__dict__,
108
118
                   getattr(self, '_fmt', None),
109
 
                   str(e))
 
119
                   e)
110
120
 
111
121
    def _get_format_string(self):
112
122
        """Return format string for this exception or None"""
126
136
               )
127
137
 
128
138
 
 
139
class InternalBzrError(BzrError):
 
140
    """Base class for errors that are internal in nature.
 
141
 
 
142
    This is a convenience class for errors that are internal. The
 
143
    internal_error attribute can still be altered in subclasses, if needed.
 
144
    Using this class is simply an easy way to get internal errors.
 
145
    """
 
146
 
 
147
    internal_error = True
 
148
 
 
149
 
129
150
class BzrNewError(BzrError):
130
151
    """Deprecated error base class."""
131
152
    # base classes should override the docstring with their human-
132
153
    # readable explanation
133
154
 
134
155
    def __init__(self, *args, **kwds):
135
 
        # XXX: Use the underlying BzrError to always generate the args attribute
136
 
        # if it doesn't exist.  We can't use super here, because exceptions are
137
 
        # old-style classes in python2.4 (but new in 2.5).  --bmc, 20060426
 
156
        # XXX: Use the underlying BzrError to always generate the args
 
157
        # attribute if it doesn't exist.  We can't use super here, because
 
158
        # exceptions are old-style classes in python2.4 (but new in 2.5).
 
159
        # --bmc, 20060426
138
160
        symbol_versioning.warn('BzrNewError was deprecated in bzr 0.13; '
139
 
             'please convert %s to use BzrError instead' 
 
161
             'please convert %s to use BzrError instead'
140
162
             % self.__class__.__name__,
141
163
             DeprecationWarning,
142
164
             stacklevel=2)
153
175
                return s.encode('utf8')
154
176
            return s
155
177
        except (TypeError, NameError, ValueError, KeyError), e:
156
 
            return 'Unprintable exception %s(%r): %s' \
 
178
            return 'Unprintable exception %s(%r): %r' \
157
179
                % (self.__class__.__name__,
158
 
                   self.__dict__, str(e))
 
180
                   self.__dict__, e)
159
181
 
160
182
 
161
183
class AlreadyBuilding(BzrError):
163
185
    _fmt = "The tree builder is already building a tree."
164
186
 
165
187
 
166
 
class BzrCheckError(BzrError):
 
188
class BranchError(BzrError):
 
189
    """Base class for concrete 'errors about a branch'."""
 
190
 
 
191
    def __init__(self, branch):
 
192
        BzrError.__init__(self, branch=branch)
 
193
 
 
194
 
 
195
class BzrCheckError(InternalBzrError):
167
196
    
168
197
    _fmt = "Internal check failed: %(message)s"
169
198
 
170
 
    internal_error = True
171
 
 
172
199
    def __init__(self, message):
173
200
        BzrError.__init__(self)
174
201
        self.message = message
175
202
 
176
203
 
177
 
class InvalidEntryName(BzrError):
 
204
class DisabledMethod(InternalBzrError):
 
205
 
 
206
    _fmt = "The smart server method '%(class_name)s' is disabled."
 
207
 
 
208
    def __init__(self, class_name):
 
209
        BzrError.__init__(self)
 
210
        self.class_name = class_name
 
211
 
 
212
 
 
213
class IncompatibleAPI(BzrError):
 
214
 
 
215
    _fmt = 'The API for "%(api)s" is not compatible with "%(wanted)s". '\
 
216
        'It supports versions "%(minimum)s" to "%(current)s".'
 
217
 
 
218
    def __init__(self, api, wanted, minimum, current):
 
219
        self.api = api
 
220
        self.wanted = wanted
 
221
        self.minimum = minimum
 
222
        self.current = current
 
223
 
 
224
 
 
225
class InProcessTransport(BzrError):
 
226
 
 
227
    _fmt = "The transport '%(transport)s' is only accessible within this " \
 
228
        "process."
 
229
 
 
230
    def __init__(self, transport):
 
231
        self.transport = transport
 
232
 
 
233
 
 
234
class InvalidEntryName(InternalBzrError):
178
235
    
179
236
    _fmt = "Invalid entry name: %(name)s"
180
237
 
181
 
    internal_error = True
182
 
 
183
238
    def __init__(self, name):
184
239
        BzrError.__init__(self)
185
240
        self.name = name
204
259
        self.revision_id = revision_id
205
260
        self.branch = branch
206
261
 
 
262
 
207
263
class ReservedId(BzrError):
208
264
 
209
265
    _fmt = "Reserved revision-id {%(revision_id)s}"
211
267
    def __init__(self, revision_id):
212
268
        self.revision_id = revision_id
213
269
 
 
270
 
 
271
class RootMissing(InternalBzrError):
 
272
 
 
273
    _fmt = ("The root entry of a tree must be the first entry supplied to "
 
274
        "record_entry_contents.")
 
275
 
 
276
 
 
277
class NoPublicBranch(BzrError):
 
278
 
 
279
    _fmt = 'There is no public branch set for "%(branch_url)s".'
 
280
 
 
281
    def __init__(self, branch):
 
282
        import bzrlib.urlutils as urlutils
 
283
        public_location = urlutils.unescape_for_display(branch.base, 'ascii')
 
284
        BzrError.__init__(self, branch_url=public_location)
 
285
 
 
286
 
 
287
class NoHelpTopic(BzrError):
 
288
 
 
289
    _fmt = ("No help could be found for '%(topic)s'. "
 
290
        "Please use 'bzr help topics' to obtain a list of topics.")
 
291
 
 
292
    def __init__(self, topic):
 
293
        self.topic = topic
 
294
 
 
295
 
214
296
class NoSuchId(BzrError):
215
297
 
216
 
    _fmt = "The file id %(file_id)s is not present in the tree %(tree)s."
 
298
    _fmt = 'The file id "%(file_id)s" is not present in the tree %(tree)s.'
217
299
    
218
300
    def __init__(self, tree, file_id):
219
301
        BzrError.__init__(self)
221
303
        self.tree = tree
222
304
 
223
305
 
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
 
306
class NoSuchIdInRepository(NoSuchId):
 
307
 
 
308
    _fmt = ('The file id "%(file_id)s" is not present in the repository'
 
309
            ' %(repository)r')
 
310
 
 
311
    def __init__(self, repository, file_id):
 
312
        BzrError.__init__(self, repository=repository, file_id=file_id)
 
313
 
 
314
 
 
315
class NotStacked(BranchError):
 
316
 
 
317
    _fmt = "The branch '%(branch)s' is not stacked."
 
318
 
 
319
 
 
320
class InventoryModified(InternalBzrError):
 
321
 
 
322
    _fmt = ("The current inventory for the tree %(tree)r has been modified,"
 
323
            " so a clean inventory cannot be read without data loss.")
230
324
 
231
325
    def __init__(self, tree):
232
326
        self.tree = tree
234
328
 
235
329
class NoWorkingTree(BzrError):
236
330
 
237
 
    _fmt = "No WorkingTree exists for %(base)s."
 
331
    _fmt = 'No WorkingTree exists for "%(base)s".'
238
332
    
239
333
    def __init__(self, base):
240
334
        BzrError.__init__(self)
254
348
        self.url = url
255
349
 
256
350
 
257
 
class WorkingTreeAlreadyPopulated(BzrError):
258
 
 
259
 
    _fmt = """Working tree already populated in %(base)s"""
260
 
 
261
 
    internal_error = True
 
351
class WorkingTreeAlreadyPopulated(InternalBzrError):
 
352
 
 
353
    _fmt = 'Working tree already populated in "%(base)s"'
262
354
 
263
355
    def __init__(self, base):
264
356
        self.base = base
265
357
 
 
358
 
266
359
class BzrCommandError(BzrError):
267
360
    """Error from user command"""
268
361
 
269
 
    internal_error = False
270
 
 
271
362
    # Error from malformed user command; please avoid raising this as a
272
363
    # generic exception not caused by user input.
273
364
    #
300
391
    _fmt = "Error in command line options"
301
392
 
302
393
 
 
394
class BadIndexFormatSignature(BzrError):
 
395
 
 
396
    _fmt = "%(value)s is not an index of type %(_type)s."
 
397
 
 
398
    def __init__(self, value, _type):
 
399
        BzrError.__init__(self)
 
400
        self.value = value
 
401
        self._type = _type
 
402
 
 
403
 
 
404
class BadIndexData(BzrError):
 
405
 
 
406
    _fmt = "Error in data for index %(value)s."
 
407
 
 
408
    def __init__(self, value):
 
409
        BzrError.__init__(self)
 
410
        self.value = value
 
411
 
 
412
 
 
413
class BadIndexDuplicateKey(BzrError):
 
414
 
 
415
    _fmt = "The key '%(key)s' is already in index '%(index)s'."
 
416
 
 
417
    def __init__(self, key, index):
 
418
        BzrError.__init__(self)
 
419
        self.key = key
 
420
        self.index = index
 
421
 
 
422
 
 
423
class BadIndexKey(BzrError):
 
424
 
 
425
    _fmt = "The key '%(key)s' is not a valid key."
 
426
 
 
427
    def __init__(self, key):
 
428
        BzrError.__init__(self)
 
429
        self.key = key
 
430
 
 
431
 
 
432
class BadIndexOptions(BzrError):
 
433
 
 
434
    _fmt = "Could not parse options for index %(value)s."
 
435
 
 
436
    def __init__(self, value):
 
437
        BzrError.__init__(self)
 
438
        self.value = value
 
439
 
 
440
 
 
441
class BadIndexValue(BzrError):
 
442
 
 
443
    _fmt = "The value '%(value)s' is not a valid value."
 
444
 
 
445
    def __init__(self, value):
 
446
        BzrError.__init__(self)
 
447
        self.value = value
 
448
 
 
449
 
303
450
class BadOptionValue(BzrError):
304
451
 
305
452
    _fmt = """Bad value "%(value)s" for option "%(name)s"."""
315
462
 
316
463
# XXX: Should be unified with TransportError; they seem to represent the
317
464
# same thing
 
465
# RBC 20060929: I think that unifiying with TransportError would be a mistake
 
466
# - this is finer than a TransportError - and more useful as such. It 
 
467
# differentiates between 'transport has failed' and 'operation on a transport
 
468
# has failed.'
318
469
class PathError(BzrError):
319
470
    
320
471
    _fmt = "Generic path error: %(path)r%(extra)s)"
342
493
    """Used when renaming and both source and dest exist."""
343
494
 
344
495
    _fmt = ("Could not rename %(source)s => %(dest)s because both files exist."
345
 
         "%(extra)s")
 
496
            " (Use --after to tell bzr about a rename that has already"
 
497
            " happened)%(extra)s")
346
498
 
347
499
    def __init__(self, source, dest, extra=None):
348
500
        BzrError.__init__(self)
356
508
 
357
509
class NotADirectory(PathError):
358
510
 
359
 
    _fmt = "%(path)r is not a directory %(extra)s"
 
511
    _fmt = '"%(path)s" is not a directory %(extra)s'
360
512
 
361
513
 
362
514
class NotInWorkingDirectory(PathError):
363
515
 
364
 
    _fmt = "%(path)r is not in the working directory %(extra)s"
 
516
    _fmt = '"%(path)s" is not in the working directory %(extra)s'
365
517
 
366
518
 
367
519
class DirectoryNotEmpty(PathError):
368
520
 
369
 
    _fmt = "Directory not empty: %(path)r%(extra)s"
370
 
 
371
 
 
372
 
class ReadingCompleted(BzrError):
 
521
    _fmt = 'Directory not empty: "%(path)s"%(extra)s'
 
522
 
 
523
 
 
524
class HardLinkNotSupported(PathError):
 
525
 
 
526
    _fmt = 'Hard-linking "%(path)s" is not supported'
 
527
 
 
528
 
 
529
class ReadingCompleted(InternalBzrError):
373
530
    
374
531
    _fmt = ("The MediumRequest '%(request)s' has already had finish_reading "
375
532
            "called upon it - the request has been completed and no more "
376
533
            "data may be read.")
377
534
 
378
 
    internal_error = True
379
 
 
380
535
    def __init__(self, request):
381
536
        self.request = request
382
537
 
383
538
 
384
539
class ResourceBusy(PathError):
385
540
 
386
 
    _fmt = "Device or resource busy: %(path)r%(extra)s"
 
541
    _fmt = 'Device or resource busy: "%(path)s"%(extra)s'
387
542
 
388
543
 
389
544
class PermissionDenied(PathError):
390
545
 
391
 
    _fmt = "Permission denied: %(path)r%(extra)s"
 
546
    _fmt = 'Permission denied: "%(path)s"%(extra)s'
392
547
 
393
548
 
394
549
class InvalidURL(PathError):
395
550
 
396
 
    _fmt = "Invalid url supplied to transport: %(path)r%(extra)s"
 
551
    _fmt = 'Invalid url supplied to transport: "%(path)s"%(extra)s'
397
552
 
398
553
 
399
554
class InvalidURLJoin(PathError):
400
555
 
401
 
    _fmt = "Invalid URL join request: %(args)s%(extra)s"
 
556
    _fmt = "Invalid URL join request: %(reason)s: %(base)r + %(join_args)r"
402
557
 
403
 
    def __init__(self, msg, base, args):
404
 
        PathError.__init__(self, base, msg)
405
 
        self.args = [base] + list(args)
 
558
    def __init__(self, reason, base, join_args):
 
559
        self.reason = reason
 
560
        self.base = base
 
561
        self.join_args = join_args
 
562
        PathError.__init__(self, base, reason)
406
563
 
407
564
 
408
565
class UnknownHook(BzrError):
423
580
        PathError.__init__(self, url, extra=extra)
424
581
 
425
582
 
 
583
class UnstackableBranchFormat(BzrError):
 
584
 
 
585
    _fmt = ("The branch '%(url)s'(%(format)s) is not a stackable format. "
 
586
        "You will need to upgrade the branch to permit branch stacking.")
 
587
 
 
588
    def __init__(self, format, url):
 
589
        BzrError.__init__(self)
 
590
        self.format = format
 
591
        self.url = url
 
592
 
 
593
 
 
594
class UnstackableRepositoryFormat(BzrError):
 
595
 
 
596
    _fmt = ("The repository '%(url)s'(%(format)s) is not a stackable format. "
 
597
        "You will need to upgrade the repository to permit branch stacking.")
 
598
 
 
599
    def __init__(self, format, url):
 
600
        BzrError.__init__(self)
 
601
        self.format = format
 
602
        self.url = url
 
603
 
 
604
 
 
605
class ReadError(PathError):
 
606
    
 
607
    _fmt = """Error reading from %(path)r."""
 
608
 
 
609
 
426
610
class ShortReadvError(PathError):
427
611
 
428
 
    _fmt = "readv() read %(actual)s bytes rather than %(length)s bytes at %(offset)s for %(path)s%(extra)s"
 
612
    _fmt = ('readv() read %(actual)s bytes rather than %(length)s bytes'
 
613
            ' at %(offset)s for "%(path)s"%(extra)s')
429
614
 
430
615
    internal_error = True
431
616
 
436
621
        self.actual = actual
437
622
 
438
623
 
439
 
class PathNotChild(BzrError):
 
624
class PathNotChild(PathError):
440
625
 
441
 
    _fmt = "Path %(path)r is not a child of path %(base)r%(extra)s"
 
626
    _fmt = 'Path "%(path)s" is not a child of path "%(base)s"%(extra)s'
442
627
 
443
628
    internal_error = True
444
629
 
454
639
 
455
640
class InvalidNormalization(PathError):
456
641
 
457
 
    _fmt = "Path %(path)r is not unicode normalized"
 
642
    _fmt = 'Path "%(path)s" is not unicode normalized'
458
643
 
459
644
 
460
645
# TODO: This is given a URL; we try to unescape it but doing that from inside
462
647
# TODO: Probably this behavior of should be a common superclass 
463
648
class NotBranchError(PathError):
464
649
 
465
 
    _fmt = "Not a branch: %(path)s"
 
650
    _fmt = 'Not a branch: "%(path)s".'
466
651
 
467
652
    def __init__(self, path):
468
653
       import bzrlib.urlutils as urlutils
469
654
       self.path = urlutils.unescape_for_display(path, 'ascii')
470
655
 
471
656
 
 
657
class NoSubmitBranch(PathError):
 
658
 
 
659
    _fmt = 'No submit branch available for branch "%(path)s"'
 
660
 
 
661
    def __init__(self, branch):
 
662
       import bzrlib.urlutils as urlutils
 
663
       self.path = urlutils.unescape_for_display(branch.base, 'ascii')
 
664
 
 
665
 
472
666
class AlreadyBranchError(PathError):
473
667
 
474
 
    _fmt = "Already a branch: %(path)s."
 
668
    _fmt = 'Already a branch: "%(path)s".'
475
669
 
476
670
 
477
671
class BranchExistsWithoutWorkingTree(PathError):
478
672
 
479
 
    _fmt = "Directory contains a branch, but no working tree \
480
 
(use bzr checkout if you wish to build a working tree): %(path)s"
 
673
    _fmt = 'Directory contains a branch, but no working tree \
 
674
(use bzr checkout if you wish to build a working tree): "%(path)s"'
481
675
 
482
676
 
483
677
class AtomicFileAlreadyClosed(PathError):
484
678
 
485
 
    _fmt = "'%(function)s' called on an AtomicFile after it was closed: %(path)s"
 
679
    _fmt = ('"%(function)s" called on an AtomicFile after it was closed:'
 
680
            ' "%(path)s"')
486
681
 
487
682
    def __init__(self, path, function):
488
683
        PathError.__init__(self, path=path, extra=None)
491
686
 
492
687
class InaccessibleParent(PathError):
493
688
 
494
 
    _fmt = "Parent not accessible given base %(base)s and relative path %(path)s"
 
689
    _fmt = ('Parent not accessible given base "%(base)s" and'
 
690
            ' relative path "%(path)s"')
495
691
 
496
692
    def __init__(self, path, base):
497
693
        PathError.__init__(self, path)
500
696
 
501
697
class NoRepositoryPresent(BzrError):
502
698
 
503
 
    _fmt = "No repository present: %(path)r"
 
699
    _fmt = 'No repository present: "%(path)s"'
504
700
    def __init__(self, bzrdir):
505
701
        BzrError.__init__(self)
506
702
        self.path = bzrdir.transport.clone('..').base
508
704
 
509
705
class FileInWrongBranch(BzrError):
510
706
 
511
 
    _fmt = "File %(path)s in not in branch %(branch_base)s."
 
707
    _fmt = 'File "%(path)s" is not in branch %(branch_base)s.'
512
708
 
513
709
    def __init__(self, branch, path):
514
710
        BzrError.__init__(self)
518
714
 
519
715
 
520
716
class UnsupportedFormatError(BzrError):
521
 
    
522
 
    _fmt = "Unsupported branch format: %(format)s"
 
717
 
 
718
    _fmt = "Unsupported branch format: %(format)s\nPlease run 'bzr upgrade'"
523
719
 
524
720
 
525
721
class UnknownFormatError(BzrError):
526
722
    
527
 
    _fmt = "Unknown branch format: %(format)r"
 
723
    _fmt = "Unknown %(kind)s format: %(format)r"
 
724
 
 
725
    def __init__(self, format, kind='branch'):
 
726
        self.kind = kind
 
727
        self.format = format
528
728
 
529
729
 
530
730
class IncompatibleFormat(BzrError):
537
737
        self.bzrdir = bzrdir_format
538
738
 
539
739
 
 
740
class IncompatibleRepositories(BzrError):
 
741
 
 
742
    _fmt = "Repository %(target)s is not compatible with repository"\
 
743
        " %(source)s"
 
744
 
 
745
    def __init__(self, source, target):
 
746
        BzrError.__init__(self, target=target, source=source)
 
747
 
 
748
 
540
749
class IncompatibleRevision(BzrError):
541
750
    
542
751
    _fmt = "Revision is not compatible with %(repo_format)s"
549
758
class AlreadyVersionedError(BzrError):
550
759
    """Used when a path is expected not to be versioned, but it is."""
551
760
 
552
 
    _fmt = "%(context_info)s%(path)s is already versioned"
 
761
    _fmt = "%(context_info)s%(path)s is already versioned."
553
762
 
554
763
    def __init__(self, path, context_info=None):
555
764
        """Construct a new AlreadyVersionedError.
570
779
class NotVersionedError(BzrError):
571
780
    """Used when a path is expected to be versioned, but it is not."""
572
781
 
573
 
    _fmt = "%(context_info)s%(path)s is not versioned"
 
782
    _fmt = "%(context_info)s%(path)s is not versioned."
574
783
 
575
784
    def __init__(self, path, context_info=None):
576
785
        """Construct a new NotVersionedError.
621
830
 
622
831
class BadFileKindError(BzrError):
623
832
 
624
 
    _fmt = "Cannot operate on %(filename)s of unsupported kind %(kind)s"
 
833
    _fmt = 'Cannot operate on "%(filename)s" of unsupported kind "%(kind)s"'
 
834
 
 
835
    def __init__(self, filename, kind):
 
836
        BzrError.__init__(self, filename=filename, kind=kind)
625
837
 
626
838
 
627
839
class ForbiddenControlFileError(BzrError):
628
840
 
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
 
841
    _fmt = 'Cannot operate on "%(filename)s" because it is a control file'
 
842
 
 
843
 
 
844
class LockError(InternalBzrError):
 
845
 
 
846
    _fmt = "Lock error: %(msg)s"
637
847
 
638
848
    # All exceptions from the lock/unlock functions should be from
639
849
    # this exception class.  They will be translated as necessary. The
641
851
    #
642
852
    # New code should prefer to raise specific subclasses
643
853
    def __init__(self, message):
644
 
        self.message = message
 
854
        # Python 2.5 uses a slot for StandardError.message,
 
855
        # so use a different variable name.  We now work around this in
 
856
        # BzrError.__str__, but this member name is kept for compatability.
 
857
        self.msg = message
 
858
 
 
859
 
 
860
class LockActive(LockError):
 
861
 
 
862
    _fmt = "The lock for '%(lock_description)s' is in use and cannot be broken."
 
863
 
 
864
    internal_error = False
 
865
 
 
866
    def __init__(self, lock_description):
 
867
        self.lock_description = lock_description
645
868
 
646
869
 
647
870
class CommitNotPossible(LockError):
664
887
 
665
888
    _fmt = "A write attempt was made in a read only transaction on %(obj)s"
666
889
 
 
890
    # TODO: There should also be an error indicating that you need a write
 
891
    # lock and don't have any lock at all... mbp 20070226
 
892
 
667
893
    def __init__(self, obj):
668
894
        self.obj = obj
669
895
 
670
896
 
 
897
class ReadOnlyLockError(LockError):
 
898
 
 
899
    _fmt = "Cannot acquire write lock on %(fname)s. %(msg)s"
 
900
 
 
901
    @symbol_versioning.deprecated_method(symbol_versioning.zero_ninetytwo)
 
902
    def __init__(self, fname, msg):
 
903
        LockError.__init__(self, '')
 
904
        self.fname = fname
 
905
        self.msg = msg
 
906
 
 
907
 
 
908
class LockFailed(LockError):
 
909
 
 
910
    internal_error = False
 
911
 
 
912
    _fmt = "Cannot lock %(lock)s: %(why)s"
 
913
 
 
914
    def __init__(self, lock, why):
 
915
        LockError.__init__(self, '')
 
916
        self.lock = lock
 
917
        self.why = why
 
918
 
 
919
 
671
920
class OutSideTransaction(BzrError):
672
921
 
673
 
    _fmt = "A transaction related operation was attempted after the transaction finished."
 
922
    _fmt = ("A transaction related operation was attempted after"
 
923
            " the transaction finished.")
674
924
 
675
925
 
676
926
class ObjectNotLocked(LockError):
694
944
 
695
945
class UnlockableTransport(LockError):
696
946
 
 
947
    internal_error = False
 
948
 
697
949
    _fmt = "Cannot lock: transport is read only: %(transport)s"
698
950
 
699
951
    def __init__(self, transport):
702
954
 
703
955
class LockContention(LockError):
704
956
 
705
 
    _fmt = "Could not acquire lock %(lock)s"
 
957
    _fmt = 'Could not acquire lock "%(lock)s"'
706
958
    # TODO: show full url for lock, combining the transport and relative
707
959
    # bits?
708
960
 
709
961
    internal_error = False
710
 
    
 
962
 
711
963
    def __init__(self, lock):
712
964
        self.lock = lock
713
965
 
714
966
 
715
967
class LockBroken(LockError):
716
968
 
717
 
    _fmt = "Lock was broken while still open: %(lock)s - check storage consistency!"
 
969
    _fmt = ("Lock was broken while still open: %(lock)s"
 
970
            " - check storage consistency!")
718
971
 
719
972
    internal_error = False
720
973
 
724
977
 
725
978
class LockBreakMismatch(LockError):
726
979
 
727
 
    _fmt = "Lock was released and re-acquired before being broken: %(lock)s: held by %(holder)r, wanted to break %(target)r"
 
980
    _fmt = ("Lock was released and re-acquired before being broken:"
 
981
            " %(lock)s: held by %(holder)r, wanted to break %(target)r")
728
982
 
729
983
    internal_error = False
730
984
 
744
998
        self.lock = lock
745
999
 
746
1000
 
 
1001
class TokenLockingNotSupported(LockError):
 
1002
 
 
1003
    _fmt = "The object %(obj)s does not support token specifying a token when locking."
 
1004
 
 
1005
    def __init__(self, obj):
 
1006
        self.obj = obj
 
1007
 
 
1008
 
 
1009
class TokenMismatch(LockBroken):
 
1010
 
 
1011
    _fmt = "The lock token %(given_token)r does not match lock token %(lock_token)r."
 
1012
 
 
1013
    internal_error = True
 
1014
 
 
1015
    def __init__(self, given_token, lock_token):
 
1016
        self.given_token = given_token
 
1017
        self.lock_token = lock_token
 
1018
 
 
1019
 
747
1020
class PointlessCommit(BzrError):
748
1021
 
749
1022
    _fmt = "No changes to commit"
750
1023
 
751
1024
 
 
1025
class CannotCommitSelectedFileMerge(BzrError):
 
1026
 
 
1027
    _fmt = 'Selected-file commit of merges is not supported yet:'\
 
1028
        ' files %(files_str)s'
 
1029
 
 
1030
    def __init__(self, files):
 
1031
        files_str = ', '.join(files)
 
1032
        BzrError.__init__(self, files=files, files_str=files_str)
 
1033
 
 
1034
 
 
1035
class BadCommitMessageEncoding(BzrError):
 
1036
 
 
1037
    _fmt = 'The specified commit message contains characters unsupported by '\
 
1038
        'the current encoding.'
 
1039
 
 
1040
 
752
1041
class UpgradeReadonly(BzrError):
753
1042
 
754
1043
    _fmt = "Upgrade URL cannot work with readonly URLs."
768
1057
    _fmt = "Commit refused because there are unknowns in the tree."
769
1058
 
770
1059
 
771
 
class NoSuchRevision(BzrError):
772
 
 
773
 
    _fmt = "Branch %(branch)s has no revision %(revision)s"
774
 
 
775
 
    internal_error = True
 
1060
class NoSuchRevision(InternalBzrError):
 
1061
 
 
1062
    _fmt = "%(branch)s has no revision %(revision)s"
776
1063
 
777
1064
    def __init__(self, branch, revision):
 
1065
        # 'branch' may sometimes be an internal object like a KnitRevisionStore
778
1066
        BzrError.__init__(self, branch=branch, revision=revision)
779
1067
 
780
1068
 
781
 
class NotLeftParentDescendant(BzrError):
782
 
 
783
 
    _fmt = "Revision %(old_revision)s is not the left parent of"\
784
 
        " %(new_revision)s, but branch %(branch_location)s expects this"
785
 
 
786
 
    internal_error = True
 
1069
# zero_ninetyone: this exception is no longer raised and should be removed
 
1070
class NotLeftParentDescendant(InternalBzrError):
 
1071
 
 
1072
    _fmt = ("Revision %(old_revision)s is not the left parent of"
 
1073
            " %(new_revision)s, but branch %(branch_location)s expects this")
787
1074
 
788
1075
    def __init__(self, branch, old_revision, new_revision):
789
1076
        BzrError.__init__(self, branch_location=branch.base,
791
1078
                          new_revision=new_revision)
792
1079
 
793
1080
 
 
1081
class RangeInChangeOption(BzrError):
 
1082
 
 
1083
    _fmt = "Option --change does not accept revision ranges"
 
1084
 
 
1085
 
794
1086
class NoSuchRevisionSpec(BzrError):
795
1087
 
796
1088
    _fmt = "No namespace registered for string: %(spec)r"
802
1094
class NoSuchRevisionInTree(NoSuchRevision):
803
1095
    """When using Tree.revision_tree, and the revision is not accessible."""
804
1096
    
805
 
    _fmt = "The revision id %(revision_id)s is not present in the tree %(tree)s."
 
1097
    _fmt = "The revision id {%(revision_id)s} is not present in the tree %(tree)s."
806
1098
 
807
1099
    def __init__(self, tree, revision_id):
808
1100
        BzrError.__init__(self)
812
1104
 
813
1105
class InvalidRevisionSpec(BzrError):
814
1106
 
815
 
    _fmt = "Requested revision: %(spec)r does not exist in branch: %(branch)s%(extra)s"
 
1107
    _fmt = ("Requested revision: %(spec)r does not exist in branch:"
 
1108
            " %(branch)s%(extra)s")
816
1109
 
817
1110
    def __init__(self, spec, branch, extra=None):
818
1111
        BzrError.__init__(self, branch=branch, spec=spec)
829
1122
 
830
1123
class AppendRevisionsOnlyViolation(BzrError):
831
1124
 
832
 
    _fmt = 'Operation denied because it would change the main history, '\
833
 
           'which is not permitted by the append_revisions_only setting on'\
834
 
           ' branch "%(location)s".'
 
1125
    _fmt = ('Operation denied because it would change the main history,'
 
1126
           ' which is not permitted by the append_revisions_only setting on'
 
1127
           ' branch "%(location)s".')
835
1128
 
836
1129
    def __init__(self, location):
837
1130
       import bzrlib.urlutils as urlutils
840
1133
 
841
1134
 
842
1135
class DivergedBranches(BzrError):
843
 
    
844
 
    _fmt = "These branches have diverged.  Use the merge command to reconcile them."""
845
1136
 
846
 
    internal_error = False
 
1137
    _fmt = ("These branches have diverged."
 
1138
            " Use the merge command to reconcile them.")
847
1139
 
848
1140
    def __init__(self, branch1, branch2):
849
1141
        self.branch1 = branch1
850
1142
        self.branch2 = branch2
851
1143
 
852
1144
 
853
 
class NotLefthandHistory(BzrError):
 
1145
class NotLefthandHistory(InternalBzrError):
854
1146
 
855
1147
    _fmt = "Supplied history does not follow left-hand parents"
856
1148
 
857
 
    internal_error = True
858
 
 
859
1149
    def __init__(self, history):
860
1150
        BzrError.__init__(self, history=history)
861
1151
 
862
1152
 
863
1153
class UnrelatedBranches(BzrError):
864
1154
 
865
 
    _fmt = "Branches have no common ancestor, and no merge base revision was specified."
866
 
 
867
 
    internal_error = False
 
1155
    _fmt = ("Branches have no common ancestor, and"
 
1156
            " no merge base revision was specified.")
 
1157
 
 
1158
 
 
1159
class CannotReverseCherrypick(BzrError):
 
1160
 
 
1161
    _fmt = ('Selected merge cannot perform reverse cherrypicks.  Try merge3'
 
1162
            ' or diff3.')
868
1163
 
869
1164
 
870
1165
class NoCommonAncestor(BzrError):
878
1173
 
879
1174
class NoCommonRoot(BzrError):
880
1175
 
881
 
    _fmt = "Revisions are not derived from the same root: " \
882
 
           "%(revision_a)s %(revision_b)s."
 
1176
    _fmt = ("Revisions are not derived from the same root: "
 
1177
           "%(revision_a)s %(revision_b)s.")
883
1178
 
884
1179
    def __init__(self, revision_a, revision_b):
885
1180
        BzrError.__init__(self, revision_a=revision_a, revision_b=revision_b)
908
1203
    def __init__(self, bases):
909
1204
        warn("BzrError AmbiguousBase has been deprecated as of bzrlib 0.8.",
910
1205
                DeprecationWarning)
911
 
        msg = "The correct base is unclear, because %s are all equally close" %\
912
 
            ", ".join(bases)
 
1206
        msg = ("The correct base is unclear, because %s are all equally close"
 
1207
                % ", ".join(bases))
913
1208
        BzrError.__init__(self, msg)
914
1209
        self.bases = bases
915
1210
 
916
1211
 
917
 
class NoCommits(BzrError):
 
1212
class NoCommits(BranchError):
918
1213
 
919
1214
    _fmt = "Branch %(branch)s has no commits."
920
1215
 
921
 
    def __init__(self, branch):
922
 
        BzrError.__init__(self, branch=branch)
923
 
 
924
1216
 
925
1217
class UnlistableStore(BzrError):
926
1218
 
937
1229
 
938
1230
class BoundBranchOutOfDate(BzrError):
939
1231
 
940
 
    _fmt = "Bound branch %(branch)s is out of date with master branch %(master)s."
 
1232
    _fmt = ("Bound branch %(branch)s is out of date with master branch"
 
1233
            " %(master)s.")
941
1234
 
942
1235
    def __init__(self, branch, master):
943
1236
        BzrError.__init__(self)
947
1240
        
948
1241
class CommitToDoubleBoundBranch(BzrError):
949
1242
 
950
 
    _fmt = "Cannot commit to branch %(branch)s. It is bound to %(master)s, which is bound to %(remote)s."
 
1243
    _fmt = ("Cannot commit to branch %(branch)s."
 
1244
            " It is bound to %(master)s, which is bound to %(remote)s.")
951
1245
 
952
1246
    def __init__(self, branch, master, remote):
953
1247
        BzrError.__init__(self)
967
1261
 
968
1262
class BoundBranchConnectionFailure(BzrError):
969
1263
 
970
 
    _fmt = "Unable to connect to target of bound branch %(branch)s => %(target)s: %(error)s"
 
1264
    _fmt = ("Unable to connect to target of bound branch %(branch)s"
 
1265
            " => %(target)s: %(error)s")
971
1266
 
972
1267
    def __init__(self, branch, target, error):
973
1268
        BzrError.__init__(self)
1017
1312
 
1018
1313
class WeaveParentMismatch(WeaveError):
1019
1314
 
1020
 
    _fmt = "Parents are mismatched between two revisions."
 
1315
    _fmt = "Parents are mismatched between two revisions. %(message)s"
1021
1316
    
1022
1317
 
1023
1318
class WeaveInvalidChecksum(WeaveError):
1027
1322
 
1028
1323
class WeaveTextDiffers(WeaveError):
1029
1324
 
1030
 
    _fmt = "Weaves differ on text content. Revision: {%(revision_id)s}, %(weave_a)s, %(weave_b)s"
 
1325
    _fmt = ("Weaves differ on text content. Revision:"
 
1326
            " {%(revision_id)s}, %(weave_a)s, %(weave_b)s")
1031
1327
 
1032
1328
    def __init__(self, revision_id, weave_a, weave_b):
1033
1329
        WeaveError.__init__(self)
1038
1334
 
1039
1335
class WeaveTextDiffers(WeaveError):
1040
1336
 
1041
 
    _fmt = "Weaves differ on text content. Revision: {%(revision_id)s}, %(weave_a)s, %(weave_b)s"
 
1337
    _fmt = ("Weaves differ on text content. Revision:"
 
1338
            " {%(revision_id)s}, %(weave_a)s, %(weave_b)s")
1042
1339
 
1043
1340
    def __init__(self, revision_id, weave_a, weave_b):
1044
1341
        WeaveError.__init__(self)
1054
1351
 
1055
1352
class RevisionNotPresent(VersionedFileError):
1056
1353
    
1057
 
    _fmt = "Revision {%(revision_id)s} not present in %(file_id)s."
 
1354
    _fmt = 'Revision {%(revision_id)s} not present in "%(file_id)s".'
1058
1355
 
1059
1356
    def __init__(self, revision_id, file_id):
1060
1357
        VersionedFileError.__init__(self)
1064
1361
 
1065
1362
class RevisionAlreadyPresent(VersionedFileError):
1066
1363
    
1067
 
    _fmt = "Revision {%(revision_id)s} already present in %(file_id)s."
 
1364
    _fmt = 'Revision {%(revision_id)s} already present in "%(file_id)s".'
1068
1365
 
1069
1366
    def __init__(self, revision_id, file_id):
1070
1367
        VersionedFileError.__init__(self)
1072
1369
        self.file_id = file_id
1073
1370
 
1074
1371
 
1075
 
class KnitError(BzrError):
 
1372
class VersionedFileInvalidChecksum(VersionedFileError):
 
1373
 
 
1374
    _fmt = "Text did not match its checksum: %(message)s"
 
1375
 
 
1376
 
 
1377
class KnitError(InternalBzrError):
1076
1378
    
1077
1379
    _fmt = "Knit error"
1078
1380
 
1079
 
    internal_error = True
1080
 
 
1081
 
 
1082
 
class KnitHeaderError(KnitError):
1083
 
 
1084
 
    _fmt = "Knit header error: %(badline)r unexpected for file %(filename)s"
1085
 
 
1086
 
    def __init__(self, badline, filename):
1087
 
        KnitError.__init__(self)
1088
 
        self.badline = badline
1089
 
        self.filename = filename
1090
 
 
1091
1381
 
1092
1382
class KnitCorrupt(KnitError):
1093
1383
 
1099
1389
        self.how = how
1100
1390
 
1101
1391
 
 
1392
class KnitDataStreamIncompatible(KnitError):
 
1393
    # Not raised anymore, as we can convert data streams.  In future we may
 
1394
    # need it again for more exotic cases, so we're keeping it around for now.
 
1395
 
 
1396
    _fmt = "Cannot insert knit data stream of format \"%(stream_format)s\" into knit of format \"%(target_format)s\"."
 
1397
 
 
1398
    def __init__(self, stream_format, target_format):
 
1399
        self.stream_format = stream_format
 
1400
        self.target_format = target_format
 
1401
        
 
1402
 
 
1403
class KnitDataStreamUnknown(KnitError):
 
1404
    # Indicates a data stream we don't know how to handle.
 
1405
 
 
1406
    _fmt = "Cannot parse knit data stream of format \"%(stream_format)s\"."
 
1407
 
 
1408
    def __init__(self, stream_format):
 
1409
        self.stream_format = stream_format
 
1410
        
 
1411
 
 
1412
class KnitHeaderError(KnitError):
 
1413
 
 
1414
    _fmt = 'Knit header error: %(badline)r unexpected for file "%(filename)s".'
 
1415
 
 
1416
    def __init__(self, badline, filename):
 
1417
        KnitError.__init__(self)
 
1418
        self.badline = badline
 
1419
        self.filename = filename
 
1420
 
1102
1421
class KnitIndexUnknownMethod(KnitError):
1103
1422
    """Raised when we don't understand the storage method.
1104
1423
 
1139
1458
        BzrError.__init__(self)
1140
1459
 
1141
1460
 
1142
 
class TooManyConcurrentRequests(BzrError):
1143
 
 
1144
 
    _fmt = ("The medium '%(medium)s' has reached its concurrent request limit. "
1145
 
            "Be sure to finish_writing and finish_reading on the "
1146
 
            "current request that is open.")
1147
 
 
1148
 
    internal_error = True
 
1461
class TooManyConcurrentRequests(InternalBzrError):
 
1462
 
 
1463
    _fmt = ("The medium '%(medium)s' has reached its concurrent request limit."
 
1464
            " Be sure to finish_writing and finish_reading on the"
 
1465
            " currently open request.")
1149
1466
 
1150
1467
    def __init__(self, medium):
1151
1468
        self.medium = medium
1159
1476
        self.details = details
1160
1477
 
1161
1478
 
 
1479
class UnknownSmartMethod(InternalBzrError):
 
1480
 
 
1481
    _fmt = "The server does not recognise the '%(verb)s' request."
 
1482
 
 
1483
    def __init__(self, verb):
 
1484
        self.verb = verb
 
1485
 
 
1486
 
1162
1487
# A set of semi-meaningful errors which can be thrown
1163
1488
class TransportNotPossible(TransportError):
1164
1489
 
1196
1521
 
1197
1522
class InvalidRange(TransportError):
1198
1523
 
1199
 
    _fmt = "Invalid range access in %(path)s at %(offset)s."
1200
 
    
1201
 
    def __init__(self, path, offset):
1202
 
        TransportError.__init__(self, ("Invalid range access in %s at %d"
1203
 
                                       % (path, offset)))
 
1524
    _fmt = "Invalid range access in %(path)s at %(offset)s: %(msg)s"
 
1525
 
 
1526
    def __init__(self, path, offset, msg=None):
 
1527
        TransportError.__init__(self, msg)
1204
1528
        self.path = path
1205
1529
        self.offset = offset
1206
1530
 
1217
1541
class InvalidHttpRange(InvalidHttpResponse):
1218
1542
 
1219
1543
    _fmt = "Invalid http range %(range)r for %(path)s: %(msg)s"
1220
 
    
 
1544
 
1221
1545
    def __init__(self, path, range, msg):
1222
1546
        self.range = range
1223
1547
        InvalidHttpResponse.__init__(self, path, msg)
1226
1550
class InvalidHttpContentType(InvalidHttpResponse):
1227
1551
 
1228
1552
    _fmt = 'Invalid http Content-type "%(ctype)s" for %(path)s: %(msg)s'
1229
 
    
 
1553
 
1230
1554
    def __init__(self, path, ctype, msg):
1231
1555
        self.ctype = ctype
1232
1556
        InvalidHttpResponse.__init__(self, path, msg)
1233
1557
 
1234
1558
 
 
1559
class RedirectRequested(TransportError):
 
1560
 
 
1561
    _fmt = '%(source)s is%(permanently)s redirected to %(target)s'
 
1562
 
 
1563
    def __init__(self, source, target, is_permanent=False, qual_proto=None):
 
1564
        self.source = source
 
1565
        self.target = target
 
1566
        if is_permanent:
 
1567
            self.permanently = ' permanently'
 
1568
        else:
 
1569
            self.permanently = ''
 
1570
        self._qualified_proto = qual_proto
 
1571
        TransportError.__init__(self)
 
1572
 
 
1573
    def _requalify_url(self, url):
 
1574
        """Restore the qualified proto in front of the url"""
 
1575
        # When this exception is raised, source and target are in
 
1576
        # user readable format. But some transports may use a
 
1577
        # different proto (http+urllib:// will present http:// to
 
1578
        # the user. If a qualified proto is specified, the code
 
1579
        # trapping the exception can get the qualified urls to
 
1580
        # properly handle the redirection themself (creating a
 
1581
        # new transport object from the target url for example).
 
1582
        # But checking that the scheme of the original and
 
1583
        # redirected urls are the same can be tricky. (see the
 
1584
        # FIXME in BzrDir.open_from_transport for the unique use
 
1585
        # case so far).
 
1586
        if self._qualified_proto is None:
 
1587
            return url
 
1588
 
 
1589
        # The TODO related to NotBranchError mention that doing
 
1590
        # that kind of manipulation on the urls may not be the
 
1591
        # exception object job. On the other hand, this object is
 
1592
        # the interface between the code and the user so
 
1593
        # presenting the urls in different ways is indeed its
 
1594
        # job...
 
1595
        import urlparse
 
1596
        proto, netloc, path, query, fragment = urlparse.urlsplit(url)
 
1597
        return urlparse.urlunsplit((self._qualified_proto, netloc, path,
 
1598
                                   query, fragment))
 
1599
 
 
1600
    def get_source_url(self):
 
1601
        return self._requalify_url(self.source)
 
1602
 
 
1603
    def get_target_url(self):
 
1604
        return self._requalify_url(self.target)
 
1605
 
 
1606
 
 
1607
class TooManyRedirections(TransportError):
 
1608
 
 
1609
    _fmt = "Too many redirections"
 
1610
 
 
1611
 
1235
1612
class ConflictsInTree(BzrError):
1236
1613
 
1237
1614
    _fmt = "Working tree has conflicts."
1258
1635
 
1259
1636
class SigningFailed(BzrError):
1260
1637
 
1261
 
    _fmt = "Failed to gpg sign data with command %(command_line)r"
 
1638
    _fmt = 'Failed to gpg sign data with command "%(command_line)s"'
1262
1639
 
1263
1640
    def __init__(self, command_line):
1264
1641
        BzrError.__init__(self, command_line=command_line)
1276
1653
 
1277
1654
class CantReprocessAndShowBase(BzrError):
1278
1655
 
1279
 
    _fmt = "Can't reprocess and show base, because reprocessing obscures " \
1280
 
           "the relationship of conflicting lines to the base"
 
1656
    _fmt = ("Can't reprocess and show base, because reprocessing obscures "
 
1657
           "the relationship of conflicting lines to the base")
1281
1658
 
1282
1659
 
1283
1660
class GraphCycleError(BzrError):
1289
1666
        self.graph = graph
1290
1667
 
1291
1668
 
1292
 
class WritingCompleted(BzrError):
 
1669
class WritingCompleted(InternalBzrError):
1293
1670
 
1294
1671
    _fmt = ("The MediumRequest '%(request)s' has already had finish_writing "
1295
1672
            "called upon it - accept bytes may not be called anymore.")
1296
1673
 
1297
 
    internal_error = True
1298
 
 
1299
1674
    def __init__(self, request):
1300
1675
        self.request = request
1301
1676
 
1302
1677
 
1303
 
class WritingNotComplete(BzrError):
 
1678
class WritingNotComplete(InternalBzrError):
1304
1679
 
1305
1680
    _fmt = ("The MediumRequest '%(request)s' has not has finish_writing "
1306
1681
            "called upon it - until the write phase is complete no "
1307
1682
            "data may be read.")
1308
1683
 
1309
 
    internal_error = True
1310
 
 
1311
1684
    def __init__(self, request):
1312
1685
        self.request = request
1313
1686
 
1321
1694
        self.filename = filename
1322
1695
 
1323
1696
 
1324
 
class MediumNotConnected(BzrError):
 
1697
class MediumNotConnected(InternalBzrError):
1325
1698
 
1326
1699
    _fmt = """The medium '%(medium)s' is not connected."""
1327
1700
 
1328
 
    internal_error = True
1329
 
 
1330
1701
    def __init__(self, medium):
1331
1702
        self.medium = medium
1332
1703
 
1333
1704
 
1334
1705
class MustUseDecorated(Exception):
1335
 
    
1336
 
    _fmt = """A decorating function has requested its original command be used."""
1337
 
    
 
1706
 
 
1707
    _fmt = "A decorating function has requested its original command be used."
 
1708
 
1338
1709
 
1339
1710
class NoBundleFound(BzrError):
1340
1711
 
1341
 
    _fmt = "No bundle was found in %(filename)s"
 
1712
    _fmt = 'No bundle was found in "%(filename)s".'
1342
1713
 
1343
1714
    def __init__(self, filename):
1344
1715
        BzrError.__init__(self)
1357
1728
 
1358
1729
class MissingText(BzrError):
1359
1730
 
1360
 
    _fmt = "Branch %(base)s is missing revision %(text_revision)s of %(file_id)s"
 
1731
    _fmt = ("Branch %(base)s is missing revision"
 
1732
            " %(text_revision)s of %(file_id)s")
1361
1733
 
1362
1734
    def __init__(self, branch, text_revision, file_id):
1363
1735
        BzrError.__init__(self)
1367
1739
        self.file_id = file_id
1368
1740
 
1369
1741
 
 
1742
class DuplicateFileId(BzrError):
 
1743
 
 
1744
    _fmt = "File id {%(file_id)s} already exists in inventory as %(entry)s"
 
1745
 
 
1746
    def __init__(self, file_id, entry):
 
1747
        BzrError.__init__(self)
 
1748
        self.file_id = file_id
 
1749
        self.entry = entry
 
1750
 
 
1751
 
1370
1752
class DuplicateKey(BzrError):
1371
1753
 
1372
1754
    _fmt = "Key %(key)s is already present in map"
1373
1755
 
1374
1756
 
 
1757
class DuplicateHelpPrefix(BzrError):
 
1758
 
 
1759
    _fmt = "The prefix %(prefix)s is in the help search path twice."
 
1760
 
 
1761
    def __init__(self, prefix):
 
1762
        self.prefix = prefix
 
1763
 
 
1764
 
1375
1765
class MalformedTransform(BzrError):
1376
1766
 
1377
1767
    _fmt = "Tree transform is malformed %(conflicts)r"
1389
1779
        self.root_trans_id = transform.root
1390
1780
 
1391
1781
 
1392
 
class BzrBadParameter(BzrError):
 
1782
class BzrBadParameter(InternalBzrError):
1393
1783
 
1394
1784
    _fmt = "Bad parameter: %(param)r"
1395
1785
 
1457
1847
    def __init__(self, from_path, to_path, extra=None):
1458
1848
        BzrMoveFailedError.__init__(self, from_path, to_path, extra)
1459
1849
 
 
1850
class BzrRemoveChangedFilesError(BzrError):
 
1851
    """Used when user is trying to remove changed files."""
 
1852
 
 
1853
    _fmt = ("Can't safely remove modified or unknown files:\n"
 
1854
        "%(changes_as_text)s"
 
1855
        "Use --keep to not delete them, or --force to delete them regardless.")
 
1856
 
 
1857
    def __init__(self, tree_delta):
 
1858
        BzrError.__init__(self)
 
1859
        self.changes_as_text = tree_delta.get_changes_as_text()
 
1860
        #self.paths_as_string = '\n'.join(changed_files)
 
1861
        #self.paths_as_string = '\n'.join([quotefn(p) for p in changed_files])
 
1862
 
1460
1863
 
1461
1864
class BzrBadParameterNotString(BzrBadParameter):
1462
1865
 
1470
1873
 
1471
1874
class BzrBadParameterUnicode(BzrBadParameter):
1472
1875
 
1473
 
    _fmt = "Parameter %(param)s is unicode but only byte-strings are permitted."
 
1876
    _fmt = ("Parameter %(param)s is unicode but"
 
1877
            " only byte-strings are permitted.")
1474
1878
 
1475
1879
 
1476
1880
class BzrBadParameterContainsNewline(BzrBadParameter):
1518
1922
        self.format = format
1519
1923
 
1520
1924
 
 
1925
class NoDiffFound(BzrError):
 
1926
 
 
1927
    _fmt = 'Could not find an appropriate Differ for file "%(path)s"'
 
1928
 
 
1929
    def __init__(self, path):
 
1930
        BzrError.__init__(self, path)
 
1931
 
 
1932
 
 
1933
class ExecutableMissing(BzrError):
 
1934
 
 
1935
    _fmt = "%(exe_name)s could not be found on this machine"
 
1936
 
 
1937
    def __init__(self, exe_name):
 
1938
        BzrError.__init__(self, exe_name=exe_name)
 
1939
 
 
1940
 
1521
1941
class NoDiff(BzrError):
1522
1942
 
1523
1943
    _fmt = "Diff is not installed on this machine: %(msg)s"
1531
1951
    _fmt = "Diff3 is not installed on this machine."
1532
1952
 
1533
1953
 
 
1954
class ExistingContent(BzrError):
 
1955
    # Added in bzrlib 0.92, used by VersionedFile.add_lines.
 
1956
 
 
1957
    _fmt = "The content being inserted is already present."
 
1958
 
 
1959
 
1534
1960
class ExistingLimbo(BzrError):
1535
1961
 
1536
1962
    _fmt = """This tree contains left-over files from a failed operation.
1542
1968
       self.limbo_dir = limbo_dir
1543
1969
 
1544
1970
 
 
1971
class ExistingPendingDeletion(BzrError):
 
1972
 
 
1973
    _fmt = """This tree contains left-over files from a failed operation.
 
1974
    Please examine %(pending_deletion)s to see if it contains any files you
 
1975
    wish to keep, and delete it when you are done."""
 
1976
 
 
1977
    def __init__(self, pending_deletion):
 
1978
       BzrError.__init__(self, pending_deletion=pending_deletion)
 
1979
 
 
1980
 
1545
1981
class ImmortalLimbo(BzrError):
1546
1982
 
1547
 
    _fmt = """Unable to delete transform temporary directory $(limbo_dir)s.
 
1983
    _fmt = """Unable to delete transform temporary directory %(limbo_dir)s.
1548
1984
    Please examine %(limbo_dir)s to see if it contains any files you wish to
1549
1985
    keep, and delete it when you are done."""
1550
1986
 
1553
1989
       self.limbo_dir = limbo_dir
1554
1990
 
1555
1991
 
 
1992
class ImmortalPendingDeletion(BzrError):
 
1993
 
 
1994
    _fmt = ("Unable to delete transform temporary directory "
 
1995
    "%(pending_deletion)s.  Please examine %(pending_deletion)s to see if it "
 
1996
    "contains any files you wish to keep, and delete it when you are done.")
 
1997
 
 
1998
    def __init__(self, pending_deletion):
 
1999
       BzrError.__init__(self, pending_deletion=pending_deletion)
 
2000
 
 
2001
 
1556
2002
class OutOfDateTree(BzrError):
1557
2003
 
1558
2004
    _fmt = "Working tree is out of date, please run 'bzr update'."
1562
2008
        self.tree = tree
1563
2009
 
1564
2010
 
 
2011
class PublicBranchOutOfDate(BzrError):
 
2012
 
 
2013
    _fmt = 'Public branch "%(public_location)s" lacks revision '\
 
2014
        '"%(revstring)s".'
 
2015
 
 
2016
    def __init__(self, public_location, revstring):
 
2017
        import bzrlib.urlutils as urlutils
 
2018
        public_location = urlutils.unescape_for_display(public_location,
 
2019
                                                        'ascii')
 
2020
        BzrError.__init__(self, public_location=public_location,
 
2021
                          revstring=revstring)
 
2022
 
 
2023
 
1565
2024
class MergeModifiedFormatError(BzrError):
1566
2025
 
1567
2026
    _fmt = "Error in merge modified format"
1572
2031
    _fmt = "Format error in conflict listings"
1573
2032
 
1574
2033
 
 
2034
class CorruptDirstate(BzrError):
 
2035
 
 
2036
    _fmt = ("Inconsistency in dirstate file %(dirstate_path)s.\n"
 
2037
            "Error: %(description)s")
 
2038
 
 
2039
    def __init__(self, dirstate_path, description):
 
2040
        BzrError.__init__(self)
 
2041
        self.dirstate_path = dirstate_path
 
2042
        self.description = description
 
2043
 
 
2044
 
1575
2045
class CorruptRepository(BzrError):
1576
2046
 
1577
 
    _fmt = """An error has been detected in the repository %(repo_path)s.
1578
 
Please run bzr reconcile on this repository."""
 
2047
    _fmt = ("An error has been detected in the repository %(repo_path)s.\n"
 
2048
            "Please run bzr reconcile on this repository.")
1579
2049
 
1580
2050
    def __init__(self, repo):
1581
2051
        BzrError.__init__(self)
1582
2052
        self.repo_path = repo.bzrdir.root_transport.base
1583
2053
 
1584
2054
 
 
2055
class InconsistentDelta(BzrError):
 
2056
    """Used when we get a delta that is not valid."""
 
2057
 
 
2058
    _fmt = ("An inconsistent delta was supplied involving %(path)r,"
 
2059
            " %(file_id)r\nreason: %(reason)s")
 
2060
 
 
2061
    def __init__(self, path, file_id, reason):
 
2062
        BzrError.__init__(self)
 
2063
        self.path = path
 
2064
        self.file_id = file_id
 
2065
        self.reason = reason
 
2066
 
 
2067
 
1585
2068
class UpgradeRequired(BzrError):
1586
2069
 
1587
2070
    _fmt = "To use this feature you must upgrade your branch at %(path)s."
1591
2074
        self.path = path
1592
2075
 
1593
2076
 
 
2077
class RepositoryUpgradeRequired(UpgradeRequired):
 
2078
 
 
2079
    _fmt = "To use this feature you must upgrade your repository at %(path)s."
 
2080
 
 
2081
 
1594
2082
class LocalRequiresBoundBranch(BzrError):
1595
2083
 
1596
2084
    _fmt = "Cannot perform local-only commits on unbound branches."
1603
2091
 
1604
2092
class InvalidProgressBarType(BzrError):
1605
2093
 
1606
 
    _fmt = """Environment variable BZR_PROGRESS_BAR='%(bar_type)s is not a supported type
1607
 
Select one of: %(valid_types)s"""
 
2094
    _fmt = ("Environment variable BZR_PROGRESS_BAR='%(bar_type)s"
 
2095
            " is not a supported type Select one of: %(valid_types)s")
1608
2096
 
1609
2097
    def __init__(self, bar_type, valid_types):
1610
2098
        BzrError.__init__(self, bar_type=bar_type, valid_types=valid_types)
1612
2100
 
1613
2101
class UnsupportedOperation(BzrError):
1614
2102
 
1615
 
    _fmt = "The method %(mname)s is not supported on objects of type %(tname)s."
 
2103
    _fmt = ("The method %(mname)s is not supported on"
 
2104
            " objects of type %(tname)s.")
1616
2105
 
1617
2106
    def __init__(self, method, method_self):
1618
2107
        self.method = method
1625
2114
 
1626
2115
 
1627
2116
class NonAsciiRevisionId(UnsupportedOperation):
1628
 
    """Raised when a commit is attempting to set a non-ascii revision id but cant."""
 
2117
    """Raised when a commit is attempting to set a non-ascii revision id
 
2118
       but cant.
 
2119
    """
1629
2120
 
1630
2121
 
1631
2122
class BinaryFile(BzrError):
1644
2135
 
1645
2136
class TestamentMismatch(BzrError):
1646
2137
 
1647
 
    _fmt = """Testament did not match expected value.  
1648
 
       For revision_id {%(revision_id)s}, expected {%(expected)s}, measured 
 
2138
    _fmt = """Testament did not match expected value.
 
2139
       For revision_id {%(revision_id)s}, expected {%(expected)s}, measured
1649
2140
       {%(measured)s}"""
1650
2141
 
1651
2142
    def __init__(self, revision_id, expected, measured):
1720
2211
        BadInventoryFormat.__init__(self, msg=msg)
1721
2212
 
1722
2213
 
1723
 
class NoSmartMedium(BzrError):
 
2214
class RootNotRich(BzrError):
 
2215
 
 
2216
    _fmt = """This operation requires rich root data storage"""
 
2217
 
 
2218
 
 
2219
class NoSmartMedium(InternalBzrError):
1724
2220
 
1725
2221
    _fmt = "The transport '%(transport)s' cannot tunnel the smart protocol."
1726
 
    internal_error = True
1727
2222
 
1728
2223
    def __init__(self, transport):
1729
2224
        self.transport = transport
1733
2228
 
1734
2229
    _fmt = "No smart server available at %(url)s"
1735
2230
 
 
2231
    @symbol_versioning.deprecated_method(symbol_versioning.one_four)
1736
2232
    def __init__(self, url):
1737
2233
        self.url = url
1738
2234
 
1746
2242
        self.vendor = vendor
1747
2243
 
1748
2244
 
 
2245
class SSHVendorNotFound(BzrError):
 
2246
 
 
2247
    _fmt = ("Don't know how to handle SSH connections."
 
2248
            " Please set BZR_SSH environment variable.")
 
2249
 
 
2250
 
1749
2251
class GhostRevisionUnusableHere(BzrError):
1750
2252
 
1751
2253
    _fmt = "Ghost revision {%(revision_id)s} cannot be used here."
1755
2257
        self.revision_id = revision_id
1756
2258
 
1757
2259
 
1758
 
class IllegalUseOfScopeReplacer(BzrError):
1759
 
 
1760
 
    _fmt = "ScopeReplacer object %(name)r was used incorrectly: %(msg)s%(extra)s"
1761
 
 
1762
 
    internal_error = True
 
2260
class IllegalUseOfScopeReplacer(InternalBzrError):
 
2261
 
 
2262
    _fmt = ("ScopeReplacer object %(name)r was used incorrectly:"
 
2263
            " %(msg)s%(extra)s")
1763
2264
 
1764
2265
    def __init__(self, name, msg, extra=None):
1765
2266
        BzrError.__init__(self)
1771
2272
            self.extra = ''
1772
2273
 
1773
2274
 
1774
 
class InvalidImportLine(BzrError):
 
2275
class InvalidImportLine(InternalBzrError):
1775
2276
 
1776
2277
    _fmt = "Not a valid import statement: %(msg)\n%(text)s"
1777
2278
 
1778
 
    internal_error = True
1779
 
 
1780
2279
    def __init__(self, text, msg):
1781
2280
        BzrError.__init__(self)
1782
2281
        self.text = text
1783
2282
        self.msg = msg
1784
2283
 
1785
2284
 
1786
 
class ImportNameCollision(BzrError):
1787
 
 
1788
 
    _fmt = "Tried to import an object to the same name as an existing object. %(name)s"
1789
 
 
1790
 
    internal_error = True
1791
 
 
1792
 
    def __init__(self, name):
1793
 
        BzrError.__init__(self)
1794
 
        self.name = name
 
2285
class ImportNameCollision(InternalBzrError):
 
2286
 
 
2287
    _fmt = ("Tried to import an object to the same name as"
 
2288
            " an existing object. %(name)s")
 
2289
 
 
2290
    def __init__(self, name):
 
2291
        BzrError.__init__(self)
 
2292
        self.name = name
 
2293
 
 
2294
 
 
2295
class NotAMergeDirective(BzrError):
 
2296
    """File starting with %(firstline)r is not a merge directive"""
 
2297
    def __init__(self, firstline):
 
2298
        BzrError.__init__(self, firstline=firstline)
 
2299
 
 
2300
 
 
2301
class NoMergeSource(BzrError):
 
2302
    """Raise if no merge source was specified for a merge directive"""
 
2303
 
 
2304
    _fmt = "A merge directive must provide either a bundle or a public"\
 
2305
        " branch location."
 
2306
 
 
2307
 
 
2308
class IllegalMergeDirectivePayload(BzrError):
 
2309
    """A merge directive contained something other than a patch or bundle"""
 
2310
 
 
2311
    _fmt = "Bad merge directive payload %(start)r"
 
2312
 
 
2313
    def __init__(self, start):
 
2314
        BzrError(self)
 
2315
        self.start = start
 
2316
 
 
2317
 
 
2318
class PatchVerificationFailed(BzrError):
 
2319
    """A patch from a merge directive could not be verified"""
 
2320
 
 
2321
    _fmt = "Preview patch does not match requested changes."
 
2322
 
 
2323
 
 
2324
class PatchMissing(BzrError):
 
2325
    """Raise a patch type was specified but no patch supplied"""
 
2326
 
 
2327
    _fmt = "Patch_type was %(patch_type)s, but no patch was supplied."
 
2328
 
 
2329
    def __init__(self, patch_type):
 
2330
        BzrError.__init__(self)
 
2331
        self.patch_type = patch_type
 
2332
 
 
2333
 
 
2334
class UnsupportedInventoryKind(BzrError):
 
2335
    
 
2336
    _fmt = """Unsupported entry kind %(kind)s"""
 
2337
 
 
2338
    def __init__(self, kind):
 
2339
        self.kind = kind
 
2340
 
 
2341
 
 
2342
class BadSubsumeSource(BzrError):
 
2343
 
 
2344
    _fmt = "Can't subsume %(other_tree)s into %(tree)s. %(reason)s"
 
2345
 
 
2346
    def __init__(self, tree, other_tree, reason):
 
2347
        self.tree = tree
 
2348
        self.other_tree = other_tree
 
2349
        self.reason = reason
 
2350
 
 
2351
 
 
2352
class SubsumeTargetNeedsUpgrade(BzrError):
 
2353
    
 
2354
    _fmt = """Subsume target %(other_tree)s needs to be upgraded."""
 
2355
 
 
2356
    def __init__(self, other_tree):
 
2357
        self.other_tree = other_tree
 
2358
 
 
2359
 
 
2360
class BadReferenceTarget(InternalBzrError):
 
2361
 
 
2362
    _fmt = "Can't add reference to %(other_tree)s into %(tree)s." \
 
2363
           "%(reason)s"
 
2364
 
 
2365
    def __init__(self, tree, other_tree, reason):
 
2366
        self.tree = tree
 
2367
        self.other_tree = other_tree
 
2368
        self.reason = reason
 
2369
 
 
2370
 
 
2371
class NoSuchTag(BzrError):
 
2372
 
 
2373
    _fmt = "No such tag: %(tag_name)s"
 
2374
 
 
2375
    def __init__(self, tag_name):
 
2376
        self.tag_name = tag_name
 
2377
 
 
2378
 
 
2379
class TagsNotSupported(BzrError):
 
2380
 
 
2381
    _fmt = ("Tags not supported by %(branch)s;"
 
2382
            " you may be able to use bzr upgrade --dirstate-tags.")
 
2383
 
 
2384
    def __init__(self, branch):
 
2385
        self.branch = branch
 
2386
 
 
2387
        
 
2388
class TagAlreadyExists(BzrError):
 
2389
 
 
2390
    _fmt = "Tag %(tag_name)s already exists."
 
2391
 
 
2392
    def __init__(self, tag_name):
 
2393
        self.tag_name = tag_name
 
2394
 
 
2395
 
 
2396
class MalformedBugIdentifier(BzrError):
 
2397
 
 
2398
    _fmt = "Did not understand bug identifier %(bug_id)s: %(reason)s"
 
2399
 
 
2400
    def __init__(self, bug_id, reason):
 
2401
        self.bug_id = bug_id
 
2402
        self.reason = reason
 
2403
 
 
2404
 
 
2405
class InvalidBugTrackerURL(BzrError):
 
2406
 
 
2407
    _fmt = ("The URL for bug tracker \"%(abbreviation)s\" doesn't "
 
2408
            "contain {id}: %(url)s")
 
2409
 
 
2410
    def __init__(self, abbreviation, url):
 
2411
        self.abbreviation = abbreviation
 
2412
        self.url = url
 
2413
 
 
2414
 
 
2415
class UnknownBugTrackerAbbreviation(BzrError):
 
2416
 
 
2417
    _fmt = ("Cannot find registered bug tracker called %(abbreviation)s "
 
2418
            "on %(branch)s")
 
2419
 
 
2420
    def __init__(self, abbreviation, branch):
 
2421
        self.abbreviation = abbreviation
 
2422
        self.branch = branch
 
2423
 
 
2424
 
 
2425
class UnexpectedSmartServerResponse(BzrError):
 
2426
 
 
2427
    _fmt = "Could not understand response from smart server: %(response_tuple)r"
 
2428
 
 
2429
    def __init__(self, response_tuple):
 
2430
        self.response_tuple = response_tuple
 
2431
 
 
2432
 
 
2433
class ContainerError(BzrError):
 
2434
    """Base class of container errors."""
 
2435
 
 
2436
 
 
2437
class UnknownContainerFormatError(ContainerError):
 
2438
 
 
2439
    _fmt = "Unrecognised container format: %(container_format)r"
 
2440
    
 
2441
    def __init__(self, container_format):
 
2442
        self.container_format = container_format
 
2443
 
 
2444
 
 
2445
class UnexpectedEndOfContainerError(ContainerError):
 
2446
 
 
2447
    _fmt = "Unexpected end of container stream"
 
2448
 
 
2449
 
 
2450
class UnknownRecordTypeError(ContainerError):
 
2451
 
 
2452
    _fmt = "Unknown record type: %(record_type)r"
 
2453
 
 
2454
    def __init__(self, record_type):
 
2455
        self.record_type = record_type
 
2456
 
 
2457
 
 
2458
class InvalidRecordError(ContainerError):
 
2459
 
 
2460
    _fmt = "Invalid record: %(reason)s"
 
2461
 
 
2462
    def __init__(self, reason):
 
2463
        self.reason = reason
 
2464
 
 
2465
 
 
2466
class ContainerHasExcessDataError(ContainerError):
 
2467
 
 
2468
    _fmt = "Container has data after end marker: %(excess)r"
 
2469
 
 
2470
    def __init__(self, excess):
 
2471
        self.excess = excess
 
2472
 
 
2473
 
 
2474
class DuplicateRecordNameError(ContainerError):
 
2475
 
 
2476
    _fmt = "Container has multiple records with the same name: %(name)s"
 
2477
 
 
2478
    def __init__(self, name):
 
2479
        self.name = name
 
2480
 
 
2481
 
 
2482
class NoDestinationAddress(InternalBzrError):
 
2483
 
 
2484
    _fmt = "Message does not have a destination address."
 
2485
 
 
2486
 
 
2487
class RepositoryDataStreamError(BzrError):
 
2488
 
 
2489
    _fmt = "Corrupt or incompatible data stream: %(reason)s"
 
2490
 
 
2491
    def __init__(self, reason):
 
2492
        self.reason = reason
 
2493
 
 
2494
 
 
2495
class SMTPError(BzrError):
 
2496
 
 
2497
    _fmt = "SMTP error: %(error)s"
 
2498
 
 
2499
    def __init__(self, error):
 
2500
        self.error = error
 
2501
 
 
2502
 
 
2503
class NoMessageSupplied(BzrError):
 
2504
 
 
2505
    _fmt = "No message supplied."
 
2506
 
 
2507
 
 
2508
class NoMailAddressSpecified(BzrError):
 
2509
 
 
2510
    _fmt = "No mail-to address specified."
 
2511
 
 
2512
 
 
2513
class UnknownMailClient(BzrError):
 
2514
 
 
2515
    _fmt = "Unknown mail client: %(mail_client)s"
 
2516
 
 
2517
    def __init__(self, mail_client):
 
2518
        BzrError.__init__(self, mail_client=mail_client)
 
2519
 
 
2520
 
 
2521
class MailClientNotFound(BzrError):
 
2522
 
 
2523
    _fmt = "Unable to find mail client with the following names:"\
 
2524
        " %(mail_command_list_string)s"
 
2525
 
 
2526
    def __init__(self, mail_command_list):
 
2527
        mail_command_list_string = ', '.join(mail_command_list)
 
2528
        BzrError.__init__(self, mail_command_list=mail_command_list,
 
2529
                          mail_command_list_string=mail_command_list_string)
 
2530
 
 
2531
class SMTPConnectionRefused(SMTPError):
 
2532
 
 
2533
    _fmt = "SMTP connection to %(host)s refused"
 
2534
 
 
2535
    def __init__(self, error, host):
 
2536
        self.error = error
 
2537
        self.host = host
 
2538
 
 
2539
 
 
2540
class DefaultSMTPConnectionRefused(SMTPConnectionRefused):
 
2541
 
 
2542
    _fmt = "Please specify smtp_server.  No server at default %(host)s."
 
2543
 
 
2544
 
 
2545
class BzrDirError(BzrError):
 
2546
 
 
2547
    def __init__(self, bzrdir):
 
2548
        import bzrlib.urlutils as urlutils
 
2549
        display_url = urlutils.unescape_for_display(bzrdir.root_transport.base,
 
2550
                                                    'ascii')
 
2551
        BzrError.__init__(self, bzrdir=bzrdir, display_url=display_url)
 
2552
 
 
2553
 
 
2554
class UnsyncedBranches(BzrDirError):
 
2555
 
 
2556
    _fmt = ("'%(display_url)s' is not in sync with %(target_url)s.  See"
 
2557
            " bzr help sync-for-reconfigure.")
 
2558
 
 
2559
    def __init__(self, bzrdir, target_branch):
 
2560
        BzrDirError.__init__(self, bzrdir)
 
2561
        import bzrlib.urlutils as urlutils
 
2562
        self.target_url = urlutils.unescape_for_display(target_branch.base,
 
2563
                                                        'ascii')
 
2564
 
 
2565
 
 
2566
class AlreadyBranch(BzrDirError):
 
2567
 
 
2568
    _fmt = "'%(display_url)s' is already a branch."
 
2569
 
 
2570
 
 
2571
class AlreadyTree(BzrDirError):
 
2572
 
 
2573
    _fmt = "'%(display_url)s' is already a tree."
 
2574
 
 
2575
 
 
2576
class AlreadyCheckout(BzrDirError):
 
2577
 
 
2578
    _fmt = "'%(display_url)s' is already a checkout."
 
2579
 
 
2580
 
 
2581
class AlreadyLightweightCheckout(BzrDirError):
 
2582
 
 
2583
    _fmt = "'%(display_url)s' is already a lightweight checkout."
 
2584
 
 
2585
 
 
2586
class AlreadyUsingShared(BzrDirError):
 
2587
 
 
2588
    _fmt = "'%(display_url)s' is already using a shared repository."
 
2589
 
 
2590
 
 
2591
class AlreadyStandalone(BzrDirError):
 
2592
 
 
2593
    _fmt = "'%(display_url)s' is already standalone."
 
2594
 
 
2595
 
 
2596
class ReconfigurationNotSupported(BzrDirError):
 
2597
 
 
2598
    _fmt = "Requested reconfiguration of '%(display_url)s' is not supported."
 
2599
 
 
2600
 
 
2601
class NoBindLocation(BzrDirError):
 
2602
 
 
2603
    _fmt = "No location could be found to bind to at %(display_url)s."
 
2604
 
 
2605
 
 
2606
class UncommittedChanges(BzrError):
 
2607
 
 
2608
    _fmt = 'Working tree "%(display_url)s" has uncommitted changes.'
 
2609
 
 
2610
    def __init__(self, tree):
 
2611
        import bzrlib.urlutils as urlutils
 
2612
        display_url = urlutils.unescape_for_display(
 
2613
            tree.bzrdir.root_transport.base, 'ascii')
 
2614
        BzrError.__init__(self, tree=tree, display_url=display_url)
 
2615
 
 
2616
 
 
2617
class MissingTemplateVariable(BzrError):
 
2618
 
 
2619
    _fmt = 'Variable {%(name)s} is not available.'
 
2620
 
 
2621
    def __init__(self, name):
 
2622
        self.name = name
 
2623
 
 
2624
 
 
2625
class NoTemplate(BzrError):
 
2626
 
 
2627
    _fmt = 'No template specified.'
 
2628
 
 
2629
 
 
2630
class UnableCreateSymlink(BzrError):
 
2631
 
 
2632
    _fmt = 'Unable to create symlink %(path_str)son this platform'
 
2633
 
 
2634
    def __init__(self, path=None):
 
2635
        path_str = ''
 
2636
        if path:
 
2637
            try:
 
2638
                path_str = repr(str(path))
 
2639
            except UnicodeEncodeError:
 
2640
                path_str = repr(path)
 
2641
            path_str += ' '
 
2642
        self.path_str = path_str
 
2643
 
 
2644
 
 
2645
class UnsupportedTimezoneFormat(BzrError):
 
2646
 
 
2647
    _fmt = ('Unsupported timezone format "%(timezone)s", '
 
2648
            'options are "utc", "original", "local".')
 
2649
 
 
2650
    def __init__(self, timezone):
 
2651
        self.timezone = timezone
 
2652
 
 
2653
 
 
2654
class CommandAvailableInPlugin(StandardError):
 
2655
    
 
2656
    internal_error = False
 
2657
 
 
2658
    def __init__(self, cmd_name, plugin_metadata, provider):
 
2659
        
 
2660
        self.plugin_metadata = plugin_metadata
 
2661
        self.cmd_name = cmd_name
 
2662
        self.provider = provider
 
2663
 
 
2664
    def __str__(self):
 
2665
 
 
2666
        _fmt = ('"%s" is not a standard bzr command. \n' 
 
2667
                'However, the following official plugin provides this command: %s\n'
 
2668
                'You can install it by going to: %s'
 
2669
                % (self.cmd_name, self.plugin_metadata['name'], 
 
2670
                    self.plugin_metadata['url']))
 
2671
 
 
2672
        return _fmt
 
2673
 
 
2674
 
 
2675
class NoPluginAvailable(BzrError):
 
2676
    pass    
 
2677
 
 
2678
 
 
2679
class NotATerminal(BzrError):
 
2680
 
 
2681
    _fmt = 'Unable to ask for a password without real terminal.'
 
2682
 
 
2683
 
 
2684
class UnableEncodePath(BzrError):
 
2685
 
 
2686
    _fmt = ('Unable to encode %(kind)s path %(path)r in '
 
2687
            'user encoding %(user_encoding)s')
 
2688
 
 
2689
    def __init__(self, path, kind):
 
2690
        self.path = path
 
2691
        self.kind = kind
 
2692
        self.user_encoding = osutils.get_user_encoding()