~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/errors.py

  • Committer: Robert Collins
  • Date: 2007-07-20 03:20:20 UTC
  • mfrom: (2592 +trunk)
  • mto: This revision was merged to the branch mainline in revision 2635.
  • Revision ID: robertc@robertcollins.net-20070720032020-xiftpb5gqeebo861
(robertc) Reinstate the accidentally backed out external_url patch.

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, 2007 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
12
12
#
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
 
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
16
 
17
17
"""Exceptions for bzr, and reporting of them.
18
18
"""
19
19
 
 
20
 
20
21
from bzrlib import (
21
22
    osutils,
22
23
    symbol_versioning,
31
32
 
32
33
 
33
34
# TODO: is there any value in providing the .args field used by standard
34
 
# python exceptions?   A list of values with no names seems less useful
 
35
# python exceptions?   A list of values with no names seems less useful 
35
36
# to me.
36
37
 
37
 
# TODO: Perhaps convert the exception to a string at the moment it's
 
38
# TODO: Perhaps convert the exception to a string at the moment it's 
38
39
# constructed to make sure it will succeed.  But that says nothing about
39
40
# exceptions that are never raised.
40
41
 
43
44
# 'unprintable'.
44
45
 
45
46
 
46
 
# return codes from the bzr program
47
 
EXIT_OK = 0
48
 
EXIT_ERROR = 3
49
 
EXIT_INTERNAL_ERROR = 4
50
 
 
51
 
 
52
47
class BzrError(StandardError):
53
48
    """
54
49
    Base class for errors raised by bzrlib.
61
56
    :cvar _fmt: Format string to display the error; this is expanded
62
57
    by the instance's dict.
63
58
    """
64
 
 
 
59
    
65
60
    internal_error = False
66
61
 
67
62
    def __init__(self, msg=None, **kwds):
72
67
        arguments can be given.  The first is for generic "user" errors which
73
68
        are not intended to be caught and so do not need a specific subclass.
74
69
        The second case is for use with subclasses that provide a _fmt format
75
 
        string to print the arguments.
 
70
        string to print the arguments.  
76
71
 
77
 
        Keyword arguments are taken as parameters to the error, which can
78
 
        be inserted into the format string template.  It's recommended
79
 
        that subclasses override the __init__ method to require specific
 
72
        Keyword arguments are taken as parameters to the error, which can 
 
73
        be inserted into the format string template.  It's recommended 
 
74
        that subclasses override the __init__ method to require specific 
80
75
        parameters.
81
76
 
82
77
        :param msg: If given, this is the literal complete text for the error,
83
 
           not subject to expansion. 'msg' is used instead of 'message' because
84
 
           python evolved and, in 2.6, forbids the use of 'message'.
 
78
        not subject to expansion.
85
79
        """
86
80
        StandardError.__init__(self)
87
81
        if msg is not None:
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
 
                s = fmt % d
 
98
                s = fmt % self.__dict__
106
99
                # __str__() should always return a 'str' object
107
100
                # never a 'unicode' object.
 
101
                if isinstance(s, unicode):
 
102
                    return s.encode('utf8')
108
103
                return s
109
104
        except (AttributeError, TypeError, NameError, ValueError, KeyError), e:
110
105
            return 'Unprintable exception %s: dict=%r, fmt=%r, error=%r' \
113
108
                   getattr(self, '_fmt', None),
114
109
                   e)
115
110
 
116
 
    def __unicode__(self):
117
 
        u = self._format()
118
 
        if isinstance(u, str):
119
 
            # Try decoding the str using the default encoding.
120
 
            u = unicode(u)
121
 
        elif not isinstance(u, unicode):
122
 
            # Try to make a unicode object from it, because __unicode__ must
123
 
            # return a unicode object.
124
 
            u = unicode(u)
125
 
        return u
126
 
 
127
 
    def __str__(self):
128
 
        s = self._format()
129
 
        if isinstance(s, unicode):
130
 
            s = s.encode('utf8')
131
 
        else:
132
 
            # __str__ must return a str.
133
 
            s = str(s)
134
 
        return s
135
 
 
136
 
    def __repr__(self):
137
 
        return '%s(%s)' % (self.__class__.__name__, str(self))
138
 
 
139
111
    def _get_format_string(self):
140
112
        """Return format string for this exception or None"""
141
113
        fmt = getattr(self, '_fmt', None)
153
125
               getattr(self, '_fmt', None),
154
126
               )
155
127
 
156
 
    def __eq__(self, other):
157
 
        if self.__class__ is not 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."""
204
160
 
205
161
 
206
162
class AlreadyBuilding(BzrError):
207
 
 
 
163
    
208
164
    _fmt = "The tree builder is already building a tree."
209
165
 
210
166
 
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):
219
 
 
220
 
    _fmt = "Internal check failed: %(msg)s"
221
 
 
222
 
    def __init__(self, msg):
223
 
        BzrError.__init__(self)
224
 
        self.msg = msg
225
 
 
226
 
 
227
 
class DirstateCorrupt(BzrError):
228
 
 
229
 
    _fmt = "The dirstate file (%(state)s) appears to be corrupt: %(msg)s"
230
 
 
231
 
    def __init__(self, state, msg):
232
 
        BzrError.__init__(self)
233
 
        self.state = state
234
 
        self.msg = msg
235
 
 
236
 
 
237
 
class DisabledMethod(InternalBzrError):
 
167
class BzrCheckError(BzrError):
 
168
    
 
169
    _fmt = "Internal check failed: %(message)s"
 
170
 
 
171
    internal_error = True
 
172
 
 
173
    def __init__(self, message):
 
174
        BzrError.__init__(self)
 
175
        self.message = message
 
176
 
 
177
 
 
178
class DisabledMethod(BzrError):
238
179
 
239
180
    _fmt = "The smart server method '%(class_name)s' is disabled."
240
181
 
 
182
    internal_error = True
 
183
 
241
184
    def __init__(self, class_name):
242
185
        BzrError.__init__(self)
243
186
        self.class_name = class_name
264
207
        self.transport = transport
265
208
 
266
209
 
267
 
class InvalidEntryName(InternalBzrError):
268
 
 
 
210
class InvalidEntryName(BzrError):
 
211
    
269
212
    _fmt = "Invalid entry name: %(name)s"
270
213
 
 
214
    internal_error = True
 
215
 
271
216
    def __init__(self, name):
272
217
        BzrError.__init__(self)
273
218
        self.name = name
274
219
 
275
220
 
276
221
class InvalidRevisionNumber(BzrError):
277
 
 
 
222
    
278
223
    _fmt = "Invalid revision number %(revno)s"
279
224
 
280
225
    def __init__(self, revno):
292
237
        self.revision_id = revision_id
293
238
        self.branch = branch
294
239
 
295
 
 
296
240
class ReservedId(BzrError):
297
241
 
298
242
    _fmt = "Reserved revision-id {%(revision_id)s}"
301
245
        self.revision_id = revision_id
302
246
 
303
247
 
304
 
class RootMissing(InternalBzrError):
305
 
 
306
 
    _fmt = ("The root entry of a tree must be the first entry supplied to "
307
 
        "record_entry_contents.")
308
 
 
309
 
 
310
 
class NoPublicBranch(BzrError):
311
 
 
312
 
    _fmt = 'There is no public branch set for "%(branch_url)s".'
313
 
 
314
 
    def __init__(self, branch):
315
 
        import bzrlib.urlutils as urlutils
316
 
        public_location = urlutils.unescape_for_display(branch.base, 'ascii')
317
 
        BzrError.__init__(self, branch_url=public_location)
318
 
 
319
 
 
320
248
class NoHelpTopic(BzrError):
321
249
 
322
250
    _fmt = ("No help could be found for '%(topic)s'. "
328
256
 
329
257
class NoSuchId(BzrError):
330
258
 
331
 
    _fmt = 'The file id "%(file_id)s" is not present in the tree %(tree)s.'
332
 
 
 
259
    _fmt = "The file id %(file_id)s is not present in the tree %(tree)s."
 
260
    
333
261
    def __init__(self, tree, file_id):
334
262
        BzrError.__init__(self)
335
263
        self.file_id = file_id
336
264
        self.tree = tree
337
265
 
338
266
 
339
 
class NoSuchIdInRepository(NoSuchId):
340
 
 
341
 
    _fmt = ('The file id "%(file_id)s" is not present in the repository'
342
 
            ' %(repository)r')
343
 
 
344
 
    def __init__(self, repository, file_id):
345
 
        BzrError.__init__(self, repository=repository, file_id=file_id)
346
 
 
347
 
 
348
 
class NotStacked(BranchError):
349
 
 
350
 
    _fmt = "The branch '%(branch)s' is not stacked."
351
 
 
352
 
 
353
 
class InventoryModified(InternalBzrError):
 
267
class InventoryModified(BzrError):
354
268
 
355
269
    _fmt = ("The current inventory for the tree %(tree)r has been modified,"
356
270
            " so a clean inventory cannot be read without data loss.")
357
271
 
 
272
    internal_error = True
 
273
 
358
274
    def __init__(self, tree):
359
275
        self.tree = tree
360
276
 
361
277
 
362
278
class NoWorkingTree(BzrError):
363
279
 
364
 
    _fmt = 'No WorkingTree exists for "%(base)s".'
365
 
 
 
280
    _fmt = "No WorkingTree exists for %(base)s."
 
281
    
366
282
    def __init__(self, base):
367
283
        BzrError.__init__(self)
368
284
        self.base = base
381
297
        self.url = url
382
298
 
383
299
 
384
 
class WorkingTreeAlreadyPopulated(InternalBzrError):
385
 
 
386
 
    _fmt = 'Working tree already populated in "%(base)s"'
 
300
class WorkingTreeAlreadyPopulated(BzrError):
 
301
 
 
302
    _fmt = """Working tree already populated in %(base)s"""
 
303
 
 
304
    internal_error = True
387
305
 
388
306
    def __init__(self, base):
389
307
        self.base = base
390
308
 
391
 
 
392
309
class BzrCommandError(BzrError):
393
310
    """Error from user command"""
394
311
 
 
312
    internal_error = False
 
313
 
395
314
    # Error from malformed user command; please avoid raising this as a
396
315
    # generic exception not caused by user input.
397
316
    #
399
318
    # are not intended to be caught anyway.  UI code need not subclass
400
319
    # BzrCommandError, and non-UI code should not throw a subclass of
401
320
    # BzrCommandError.  ADHB 20051211
 
321
    def __init__(self, msg):
 
322
        # Object.__str__() must return a real string
 
323
        # returning a Unicode string is a python error.
 
324
        if isinstance(msg, unicode):
 
325
            self.msg = msg.encode('utf8')
 
326
        else:
 
327
            self.msg = msg
 
328
 
 
329
    def __str__(self):
 
330
        return self.msg
402
331
 
403
332
 
404
333
class NotWriteLocked(BzrError):
477
406
    def __init__(self, name, value):
478
407
        BzrError.__init__(self, name=name, value=value)
479
408
 
480
 
 
 
409
    
481
410
class StrictCommitFailed(BzrError):
482
411
 
483
412
    _fmt = "Commit refused because there are unknown files in the tree"
486
415
# XXX: Should be unified with TransportError; they seem to represent the
487
416
# same thing
488
417
# RBC 20060929: I think that unifiying with TransportError would be a mistake
489
 
# - this is finer than a TransportError - and more useful as such. It
 
418
# - this is finer than a TransportError - and more useful as such. It 
490
419
# differentiates between 'transport has failed' and 'operation on a transport
491
420
# has failed.'
492
421
class PathError(BzrError):
493
 
 
 
422
    
494
423
    _fmt = "Generic path error: %(path)r%(extra)s)"
495
424
 
496
425
    def __init__(self, path, extra=None):
516
445
    """Used when renaming and both source and dest exist."""
517
446
 
518
447
    _fmt = ("Could not rename %(source)s => %(dest)s because both files exist."
519
 
            " (Use --after to tell bzr about a rename that has already"
520
 
            " happened)%(extra)s")
 
448
            "%(extra)s")
521
449
 
522
450
    def __init__(self, source, dest, extra=None):
523
451
        BzrError.__init__(self)
531
459
 
532
460
class NotADirectory(PathError):
533
461
 
534
 
    _fmt = '"%(path)s" is not a directory %(extra)s'
 
462
    _fmt = "%(path)r is not a directory %(extra)s"
535
463
 
536
464
 
537
465
class NotInWorkingDirectory(PathError):
538
466
 
539
 
    _fmt = '"%(path)s" is not in the working directory %(extra)s'
 
467
    _fmt = "%(path)r is not in the working directory %(extra)s"
540
468
 
541
469
 
542
470
class DirectoryNotEmpty(PathError):
543
471
 
544
 
    _fmt = 'Directory not empty: "%(path)s"%(extra)s'
545
 
 
546
 
 
547
 
class HardLinkNotSupported(PathError):
548
 
 
549
 
    _fmt = 'Hard-linking "%(path)s" is not supported'
550
 
 
551
 
 
552
 
class ReadingCompleted(InternalBzrError):
553
 
 
 
472
    _fmt = "Directory not empty: %(path)r%(extra)s"
 
473
 
 
474
 
 
475
class ReadingCompleted(BzrError):
 
476
    
554
477
    _fmt = ("The MediumRequest '%(request)s' has already had finish_reading "
555
478
            "called upon it - the request has been completed and no more "
556
479
            "data may be read.")
557
480
 
 
481
    internal_error = True
 
482
 
558
483
    def __init__(self, request):
559
484
        self.request = request
560
485
 
561
486
 
562
487
class ResourceBusy(PathError):
563
488
 
564
 
    _fmt = 'Device or resource busy: "%(path)s"%(extra)s'
 
489
    _fmt = "Device or resource busy: %(path)r%(extra)s"
565
490
 
566
491
 
567
492
class PermissionDenied(PathError):
568
493
 
569
 
    _fmt = 'Permission denied: "%(path)s"%(extra)s'
 
494
    _fmt = "Permission denied: %(path)r%(extra)s"
570
495
 
571
496
 
572
497
class InvalidURL(PathError):
573
498
 
574
 
    _fmt = 'Invalid url supplied to transport: "%(path)s"%(extra)s'
 
499
    _fmt = "Invalid url supplied to transport: %(path)r%(extra)s"
575
500
 
576
501
 
577
502
class InvalidURLJoin(PathError):
578
503
 
579
 
    _fmt = "Invalid URL join request: %(reason)s: %(base)r + %(join_args)r"
580
 
 
581
 
    def __init__(self, reason, base, join_args):
582
 
        self.reason = reason
583
 
        self.base = base
584
 
        self.join_args = join_args
585
 
        PathError.__init__(self, base, reason)
586
 
 
587
 
 
588
 
class InvalidRebaseURLs(PathError):
589
 
 
590
 
    _fmt = "URLs differ by more than path: %(from_)r and %(to)r"
591
 
 
592
 
    def __init__(self, from_, to):
593
 
        self.from_ = from_
594
 
        self.to = to
595
 
        PathError.__init__(self, from_, 'URLs differ by more than path.')
596
 
 
597
 
 
598
 
class UnavailableRepresentation(InternalBzrError):
599
 
 
600
 
    _fmt = ("The encoding '%(wanted)s' is not available for key %(key)s which "
601
 
        "is encoded as '%(native)s'.")
602
 
 
603
 
    def __init__(self, key, wanted, native):
604
 
        InternalBzrError.__init__(self)
605
 
        self.wanted = wanted
606
 
        self.native = native
607
 
        self.key = key
 
504
    _fmt = "Invalid URL join request: %(args)s%(extra)s"
 
505
 
 
506
    def __init__(self, msg, base, args):
 
507
        PathError.__init__(self, base, msg)
 
508
        self.args = [base] + list(args)
608
509
 
609
510
 
610
511
class UnknownHook(BzrError):
625
526
        PathError.__init__(self, url, extra=extra)
626
527
 
627
528
 
628
 
class UnstackableBranchFormat(BzrError):
629
 
 
630
 
    _fmt = ("The branch '%(url)s'(%(format)s) is not a stackable format. "
631
 
        "You will need to upgrade the branch to permit branch stacking.")
632
 
 
633
 
    def __init__(self, format, url):
634
 
        BzrError.__init__(self)
635
 
        self.format = format
636
 
        self.url = url
637
 
 
638
 
 
639
 
class UnstackableRepositoryFormat(BzrError):
640
 
 
641
 
    _fmt = ("The repository '%(url)s'(%(format)s) is not a stackable format. "
642
 
        "You will need to upgrade the repository to permit branch stacking.")
643
 
 
644
 
    def __init__(self, format, url):
645
 
        BzrError.__init__(self)
646
 
        self.format = format
647
 
        self.url = url
648
 
 
649
 
 
650
529
class ReadError(PathError):
651
 
 
 
530
    
652
531
    _fmt = """Error reading from %(path)r."""
653
532
 
654
533
 
655
534
class ShortReadvError(PathError):
656
535
 
657
 
    _fmt = ('readv() read %(actual)s bytes rather than %(length)s bytes'
658
 
            ' at %(offset)s for "%(path)s"%(extra)s')
 
536
    _fmt = ("readv() read %(actual)s bytes rather than %(length)s bytes"
 
537
            " at %(offset)s for %(path)s%(extra)s")
659
538
 
660
539
    internal_error = True
661
540
 
666
545
        self.actual = actual
667
546
 
668
547
 
669
 
class PathNotChild(PathError):
 
548
class PathNotChild(BzrError):
670
549
 
671
 
    _fmt = 'Path "%(path)s" is not a child of path "%(base)s"%(extra)s'
 
550
    _fmt = "Path %(path)r is not a child of path %(base)r%(extra)s"
672
551
 
673
552
    internal_error = True
674
553
 
684
563
 
685
564
class InvalidNormalization(PathError):
686
565
 
687
 
    _fmt = 'Path "%(path)s" is not unicode normalized'
 
566
    _fmt = "Path %(path)r is not unicode normalized"
688
567
 
689
568
 
690
569
# TODO: This is given a URL; we try to unescape it but doing that from inside
691
570
# the exception object is a bit undesirable.
692
 
# TODO: Probably this behavior of should be a common superclass
 
571
# TODO: Probably this behavior of should be a common superclass 
693
572
class NotBranchError(PathError):
694
573
 
695
 
    _fmt = 'Not a branch: "%(path)s".'
 
574
    _fmt = "Not a branch: %(path)s"
696
575
 
697
576
    def __init__(self, path):
698
577
       import bzrlib.urlutils as urlutils
710
589
 
711
590
class AlreadyBranchError(PathError):
712
591
 
713
 
    _fmt = 'Already a branch: "%(path)s".'
 
592
    _fmt = "Already a branch: %(path)s."
714
593
 
715
594
 
716
595
class BranchExistsWithoutWorkingTree(PathError):
717
596
 
718
 
    _fmt = 'Directory contains a branch, but no working tree \
719
 
(use bzr checkout if you wish to build a working tree): "%(path)s"'
 
597
    _fmt = "Directory contains a branch, but no working tree \
 
598
(use bzr checkout if you wish to build a working tree): %(path)s"
720
599
 
721
600
 
722
601
class AtomicFileAlreadyClosed(PathError):
723
602
 
724
 
    _fmt = ('"%(function)s" called on an AtomicFile after it was closed:'
725
 
            ' "%(path)s"')
 
603
    _fmt = ("'%(function)s' called on an AtomicFile after it was closed:"
 
604
            " %(path)s")
726
605
 
727
606
    def __init__(self, path, function):
728
607
        PathError.__init__(self, path=path, extra=None)
731
610
 
732
611
class InaccessibleParent(PathError):
733
612
 
734
 
    _fmt = ('Parent not accessible given base "%(base)s" and'
735
 
            ' relative path "%(path)s"')
 
613
    _fmt = ("Parent not accessible given base %(base)s and"
 
614
            " relative path %(path)s")
736
615
 
737
616
    def __init__(self, path, base):
738
617
        PathError.__init__(self, path)
741
620
 
742
621
class NoRepositoryPresent(BzrError):
743
622
 
744
 
    _fmt = 'No repository present: "%(path)s"'
 
623
    _fmt = "No repository present: %(path)r"
745
624
    def __init__(self, bzrdir):
746
625
        BzrError.__init__(self)
747
626
        self.path = bzrdir.transport.clone('..').base
749
628
 
750
629
class FileInWrongBranch(BzrError):
751
630
 
752
 
    _fmt = 'File "%(path)s" is not in branch %(branch_base)s.'
 
631
    _fmt = "File %(path)s in not in branch %(branch_base)s."
753
632
 
754
633
    def __init__(self, branch, path):
755
634
        BzrError.__init__(self)
764
643
 
765
644
 
766
645
class UnknownFormatError(BzrError):
767
 
 
768
 
    _fmt = "Unknown %(kind)s format: %(format)r"
769
 
 
770
 
    def __init__(self, format, kind='branch'):
771
 
        self.kind = kind
772
 
        self.format = format
 
646
    
 
647
    _fmt = "Unknown branch format: %(format)r"
773
648
 
774
649
 
775
650
class IncompatibleFormat(BzrError):
776
 
 
 
651
    
777
652
    _fmt = "Format %(format)s is not compatible with .bzr version %(bzrdir)s."
778
653
 
779
654
    def __init__(self, format, bzrdir_format):
784
659
 
785
660
class IncompatibleRepositories(BzrError):
786
661
 
787
 
    _fmt = "%(target)s\n" \
788
 
            "is not compatible with\n" \
789
 
            "%(source)s\n" \
790
 
            "%(details)s"
 
662
    _fmt = "Repository %(target)s is not compatible with repository"\
 
663
        " %(source)s"
791
664
 
792
 
    def __init__(self, source, target, details=None):
793
 
        if details is None:
794
 
            details = "(no details)"
795
 
        BzrError.__init__(self, target=target, source=source, details=details)
 
665
    def __init__(self, source, target):
 
666
        BzrError.__init__(self, target=target, source=source)
796
667
 
797
668
 
798
669
class IncompatibleRevision(BzrError):
799
 
 
 
670
    
800
671
    _fmt = "Revision is not compatible with %(repo_format)s"
801
672
 
802
673
    def __init__(self, repo_format):
807
678
class AlreadyVersionedError(BzrError):
808
679
    """Used when a path is expected not to be versioned, but it is."""
809
680
 
810
 
    _fmt = "%(context_info)s%(path)s is already versioned."
 
681
    _fmt = "%(context_info)s%(path)s is already versioned"
811
682
 
812
683
    def __init__(self, path, context_info=None):
813
684
        """Construct a new AlreadyVersionedError.
828
699
class NotVersionedError(BzrError):
829
700
    """Used when a path is expected to be versioned, but it is not."""
830
701
 
831
 
    _fmt = "%(context_info)s%(path)s is not versioned."
 
702
    _fmt = "%(context_info)s%(path)s is not versioned"
832
703
 
833
704
    def __init__(self, path, context_info=None):
834
705
        """Construct a new NotVersionedError.
885
756
        BzrError.__init__(self, filename=filename, kind=kind)
886
757
 
887
758
 
888
 
class BadFilenameEncoding(BzrError):
889
 
 
890
 
    _fmt = ('Filename %(filename)r is not valid in your current filesystem'
891
 
            ' encoding %(fs_encoding)s')
892
 
 
893
 
    def __init__(self, filename, fs_encoding):
894
 
        BzrError.__init__(self)
895
 
        self.filename = filename
896
 
        self.fs_encoding = fs_encoding
897
 
 
898
 
 
899
759
class ForbiddenControlFileError(BzrError):
900
760
 
901
 
    _fmt = 'Cannot operate on "%(filename)s" because it is a control file'
902
 
 
903
 
 
904
 
class LockError(InternalBzrError):
 
761
    _fmt = "Cannot operate on %(filename)s because it is a control file"
 
762
 
 
763
 
 
764
class LockError(BzrError):
905
765
 
906
766
    _fmt = "Lock error: %(msg)s"
907
767
 
 
768
    internal_error = True
 
769
 
908
770
    # All exceptions from the lock/unlock functions should be from
909
771
    # this exception class.  They will be translated as necessary. The
910
772
    # original exception is available as e.original_error
912
774
    # New code should prefer to raise specific subclasses
913
775
    def __init__(self, message):
914
776
        # Python 2.5 uses a slot for StandardError.message,
915
 
        # so use a different variable name.  We now work around this in
916
 
        # BzrError.__str__, but this member name is kept for compatability.
 
777
        # so use a different variable name
 
778
        # so it is exposed in self.__dict__
917
779
        self.msg = message
918
780
 
919
781
 
954
816
        self.obj = obj
955
817
 
956
818
 
957
 
class LockFailed(LockError):
958
 
 
959
 
    internal_error = False
960
 
 
961
 
    _fmt = "Cannot lock %(lock)s: %(why)s"
962
 
 
963
 
    def __init__(self, lock, why):
 
819
class ReadOnlyLockError(LockError):
 
820
 
 
821
    _fmt = "Cannot acquire write lock on %(fname)s. %(msg)s"
 
822
 
 
823
    def __init__(self, fname, msg):
964
824
        LockError.__init__(self, '')
965
 
        self.lock = lock
966
 
        self.why = why
 
825
        self.fname = fname
 
826
        self.msg = msg
967
827
 
968
828
 
969
829
class OutSideTransaction(BzrError):
993
853
 
994
854
class UnlockableTransport(LockError):
995
855
 
996
 
    internal_error = False
997
 
 
998
856
    _fmt = "Cannot lock: transport is read only: %(transport)s"
999
857
 
1000
858
    def __init__(self, transport):
1003
861
 
1004
862
class LockContention(LockError):
1005
863
 
1006
 
    _fmt = 'Could not acquire lock "%(lock)s": %(msg)s'
 
864
    _fmt = "Could not acquire lock %(lock)s"
1007
865
    # TODO: show full url for lock, combining the transport and relative
1008
866
    # bits?
1009
867
 
1010
868
    internal_error = False
1011
869
 
1012
 
    def __init__(self, lock, msg=''):
 
870
    def __init__(self, lock):
1013
871
        self.lock = lock
1014
 
        self.msg = msg
1015
872
 
1016
873
 
1017
874
class LockBroken(LockError):
1052
909
 
1053
910
    _fmt = "The object %(obj)s does not support token specifying a token when locking."
1054
911
 
 
912
    internal_error = True
 
913
 
1055
914
    def __init__(self, obj):
1056
915
        self.obj = obj
1057
916
 
1082
941
        BzrError.__init__(self, files=files, files_str=files_str)
1083
942
 
1084
943
 
1085
 
class BadCommitMessageEncoding(BzrError):
1086
 
 
1087
 
    _fmt = 'The specified commit message contains characters unsupported by '\
1088
 
        'the current encoding.'
1089
 
 
1090
 
 
1091
944
class UpgradeReadonly(BzrError):
1092
945
 
1093
946
    _fmt = "Upgrade URL cannot work with readonly URLs."
1107
960
    _fmt = "Commit refused because there are unknowns in the tree."
1108
961
 
1109
962
 
1110
 
class NoSuchRevision(InternalBzrError):
1111
 
 
1112
 
    _fmt = "%(branch)s has no revision %(revision)s"
 
963
class NoSuchRevision(BzrError):
 
964
 
 
965
    _fmt = "Branch %(branch)s has no revision %(revision)s"
 
966
 
 
967
    internal_error = True
1113
968
 
1114
969
    def __init__(self, branch, revision):
1115
 
        # 'branch' may sometimes be an internal object like a KnitRevisionStore
1116
970
        BzrError.__init__(self, branch=branch, revision=revision)
1117
971
 
1118
972
 
1119
 
class RangeInChangeOption(BzrError):
1120
 
 
1121
 
    _fmt = "Option --change does not accept revision ranges"
 
973
class NotLeftParentDescendant(BzrError):
 
974
 
 
975
    _fmt = ("Revision %(old_revision)s is not the left parent of"
 
976
            " %(new_revision)s, but branch %(branch_location)s expects this")
 
977
 
 
978
    internal_error = True
 
979
 
 
980
    def __init__(self, branch, old_revision, new_revision):
 
981
        BzrError.__init__(self, branch_location=branch.base,
 
982
                          old_revision=old_revision,
 
983
                          new_revision=new_revision)
1122
984
 
1123
985
 
1124
986
class NoSuchRevisionSpec(BzrError):
1131
993
 
1132
994
class NoSuchRevisionInTree(NoSuchRevision):
1133
995
    """When using Tree.revision_tree, and the revision is not accessible."""
1134
 
 
1135
 
    _fmt = "The revision id {%(revision_id)s} is not present in the tree %(tree)s."
 
996
    
 
997
    _fmt = "The revision id %(revision_id)s is not present in the tree %(tree)s."
1136
998
 
1137
999
    def __init__(self, tree, revision_id):
1138
1000
        BzrError.__init__(self)
1175
1037
    _fmt = ("These branches have diverged."
1176
1038
            " Use the merge command to reconcile them.")
1177
1039
 
 
1040
    internal_error = False
 
1041
 
1178
1042
    def __init__(self, branch1, branch2):
1179
1043
        self.branch1 = branch1
1180
1044
        self.branch2 = branch2
1181
1045
 
1182
1046
 
1183
 
class NotLefthandHistory(InternalBzrError):
 
1047
class NotLefthandHistory(BzrError):
1184
1048
 
1185
1049
    _fmt = "Supplied history does not follow left-hand parents"
1186
1050
 
 
1051
    internal_error = True
 
1052
 
1187
1053
    def __init__(self, history):
1188
1054
        BzrError.__init__(self, history=history)
1189
1055
 
1193
1059
    _fmt = ("Branches have no common ancestor, and"
1194
1060
            " no merge base revision was specified.")
1195
1061
 
1196
 
 
1197
 
class CannotReverseCherrypick(BzrError):
1198
 
 
1199
 
    _fmt = ('Selected merge cannot perform reverse cherrypicks.  Try merge3'
1200
 
            ' or diff3.')
 
1062
    internal_error = False
1201
1063
 
1202
1064
 
1203
1065
class NoCommonAncestor(BzrError):
1204
 
 
 
1066
    
1205
1067
    _fmt = "Revisions have no common ancestor: %(revision_a)s %(revision_b)s"
1206
1068
 
1207
1069
    def __init__(self, revision_a, revision_b):
1247
1109
        self.bases = bases
1248
1110
 
1249
1111
 
1250
 
class NoCommits(BranchError):
 
1112
class NoCommits(BzrError):
1251
1113
 
1252
1114
    _fmt = "Branch %(branch)s has no commits."
1253
1115
 
 
1116
    def __init__(self, branch):
 
1117
        BzrError.__init__(self, branch=branch)
 
1118
 
1254
1119
 
1255
1120
class UnlistableStore(BzrError):
1256
1121
 
1267
1132
 
1268
1133
class BoundBranchOutOfDate(BzrError):
1269
1134
 
1270
 
    _fmt = ("Bound branch %(branch)s is out of date with master branch"
1271
 
            " %(master)s.")
 
1135
    _fmt = ("Bound branch %(branch)s is out of date"
 
1136
            " with master branch %(master)s.")
1272
1137
 
1273
1138
    def __init__(self, branch, master):
1274
1139
        BzrError.__init__(self)
1275
1140
        self.branch = branch
1276
1141
        self.master = master
1277
1142
 
1278
 
 
 
1143
        
1279
1144
class CommitToDoubleBoundBranch(BzrError):
1280
1145
 
1281
1146
    _fmt = ("Cannot commit to branch %(branch)s."
1311
1176
 
1312
1177
class WeaveError(BzrError):
1313
1178
 
1314
 
    _fmt = "Error in processing weave: %(msg)s"
 
1179
    _fmt = "Error in processing weave: %(message)s"
1315
1180
 
1316
 
    def __init__(self, msg=None):
 
1181
    def __init__(self, message=None):
1317
1182
        BzrError.__init__(self)
1318
 
        self.msg = msg
 
1183
        self.message = message
1319
1184
 
1320
1185
 
1321
1186
class WeaveRevisionAlreadyPresent(WeaveError):
1350
1215
 
1351
1216
class WeaveParentMismatch(WeaveError):
1352
1217
 
1353
 
    _fmt = "Parents are mismatched between two revisions. %(message)s"
1354
 
 
 
1218
    _fmt = "Parents are mismatched between two revisions."
 
1219
    
1355
1220
 
1356
1221
class WeaveInvalidChecksum(WeaveError):
1357
1222
 
1383
1248
 
1384
1249
 
1385
1250
class VersionedFileError(BzrError):
1386
 
 
 
1251
    
1387
1252
    _fmt = "Versioned file error"
1388
1253
 
1389
1254
 
1390
1255
class RevisionNotPresent(VersionedFileError):
1391
 
 
1392
 
    _fmt = 'Revision {%(revision_id)s} not present in "%(file_id)s".'
 
1256
    
 
1257
    _fmt = "Revision {%(revision_id)s} not present in %(file_id)s."
1393
1258
 
1394
1259
    def __init__(self, revision_id, file_id):
1395
1260
        VersionedFileError.__init__(self)
1398
1263
 
1399
1264
 
1400
1265
class RevisionAlreadyPresent(VersionedFileError):
1401
 
 
1402
 
    _fmt = 'Revision {%(revision_id)s} already present in "%(file_id)s".'
 
1266
    
 
1267
    _fmt = "Revision {%(revision_id)s} already present in %(file_id)s."
1403
1268
 
1404
1269
    def __init__(self, revision_id, file_id):
1405
1270
        VersionedFileError.__init__(self)
1412
1277
    _fmt = "Text did not match its checksum: %(message)s"
1413
1278
 
1414
1279
 
1415
 
class KnitError(InternalBzrError):
1416
 
 
 
1280
class KnitError(BzrError):
 
1281
    
1417
1282
    _fmt = "Knit error"
1418
1283
 
 
1284
    internal_error = True
 
1285
 
 
1286
 
 
1287
class KnitHeaderError(KnitError):
 
1288
 
 
1289
    _fmt = "Knit header error: %(badline)r unexpected for file %(filename)s"
 
1290
 
 
1291
    def __init__(self, badline, filename):
 
1292
        KnitError.__init__(self)
 
1293
        self.badline = badline
 
1294
        self.filename = filename
 
1295
 
1419
1296
 
1420
1297
class KnitCorrupt(KnitError):
1421
1298
 
1427
1304
        self.how = how
1428
1305
 
1429
1306
 
1430
 
class SHA1KnitCorrupt(KnitCorrupt):
1431
 
 
1432
 
    _fmt = ("Knit %(filename)s corrupt: sha-1 of reconstructed text does not "
1433
 
        "match expected sha-1. key %(key)s expected sha %(expected)s actual "
1434
 
        "sha %(actual)s")
1435
 
 
1436
 
    def __init__(self, filename, actual, expected, key, content):
1437
 
        KnitError.__init__(self)
1438
 
        self.filename = filename
1439
 
        self.actual = actual
1440
 
        self.expected = expected
1441
 
        self.key = key
1442
 
        self.content = content
1443
 
 
1444
 
 
1445
 
class KnitDataStreamIncompatible(KnitError):
1446
 
    # Not raised anymore, as we can convert data streams.  In future we may
1447
 
    # need it again for more exotic cases, so we're keeping it around for now.
1448
 
 
1449
 
    _fmt = "Cannot insert knit data stream of format \"%(stream_format)s\" into knit of format \"%(target_format)s\"."
1450
 
 
1451
 
    def __init__(self, stream_format, target_format):
1452
 
        self.stream_format = stream_format
1453
 
        self.target_format = target_format
1454
 
 
1455
 
 
1456
 
class KnitDataStreamUnknown(KnitError):
1457
 
    # Indicates a data stream we don't know how to handle.
1458
 
 
1459
 
    _fmt = "Cannot parse knit data stream of format \"%(stream_format)s\"."
1460
 
 
1461
 
    def __init__(self, stream_format):
1462
 
        self.stream_format = stream_format
1463
 
 
1464
 
 
1465
 
class KnitHeaderError(KnitError):
1466
 
 
1467
 
    _fmt = 'Knit header error: %(badline)r unexpected for file "%(filename)s".'
1468
 
 
1469
 
    def __init__(self, badline, filename):
1470
 
        KnitError.__init__(self)
1471
 
        self.badline = badline
1472
 
        self.filename = filename
1473
 
 
1474
1307
class KnitIndexUnknownMethod(KnitError):
1475
1308
    """Raised when we don't understand the storage method.
1476
1309
 
1477
1310
    Currently only 'fulltext' and 'line-delta' are supported.
1478
1311
    """
1479
 
 
 
1312
    
1480
1313
    _fmt = ("Knit index %(filename)s does not have a known method"
1481
1314
            " in options: %(options)r")
1482
1315
 
1486
1319
        self.options = options
1487
1320
 
1488
1321
 
1489
 
class RetryWithNewPacks(BzrError):
1490
 
    """Raised when we realize that the packs on disk have changed.
1491
 
 
1492
 
    This is meant as more of a signaling exception, to trap between where a
1493
 
    local error occurred and the code that can actually handle the error and
1494
 
    code that can retry appropriately.
1495
 
    """
1496
 
 
1497
 
    internal_error = True
1498
 
 
1499
 
    _fmt = ("Pack files have changed, reload and retry. context: %(context)s"
1500
 
            " %(orig_error)s")
1501
 
 
1502
 
    def __init__(self, context, reload_occurred, exc_info):
1503
 
        """create a new RetryWithNewPacks error.
1504
 
 
1505
 
        :param reload_occurred: Set to True if we know that the packs have
1506
 
            already been reloaded, and we are failing because of an in-memory
1507
 
            cache miss. If set to True then we will ignore if a reload says
1508
 
            nothing has changed, because we assume it has already reloaded. If
1509
 
            False, then a reload with nothing changed will force an error.
1510
 
        :param exc_info: The original exception traceback, so if there is a
1511
 
            problem we can raise the original error (value from sys.exc_info())
1512
 
        """
1513
 
        BzrError.__init__(self)
1514
 
        self.reload_occurred = reload_occurred
1515
 
        self.exc_info = exc_info
1516
 
        self.orig_error = exc_info[1]
1517
 
        # TODO: The global error handler should probably treat this by
1518
 
        #       raising/printing the original exception with a bit about
1519
 
        #       RetryWithNewPacks also not being caught
1520
 
 
1521
 
 
1522
 
class RetryAutopack(RetryWithNewPacks):
1523
 
    """Raised when we are autopacking and we find a missing file.
1524
 
 
1525
 
    Meant as a signaling exception, to tell the autopack code it should try
1526
 
    again.
1527
 
    """
1528
 
 
1529
 
    internal_error = True
1530
 
 
1531
 
    _fmt = ("Pack files have changed, reload and try autopack again."
1532
 
            " context: %(context)s %(orig_error)s")
1533
 
 
1534
 
 
1535
1322
class NoSuchExportFormat(BzrError):
1536
 
 
 
1323
    
1537
1324
    _fmt = "Export format %(format)r not supported"
1538
1325
 
1539
1326
    def __init__(self, format):
1542
1329
 
1543
1330
 
1544
1331
class TransportError(BzrError):
1545
 
 
 
1332
    
1546
1333
    _fmt = "Transport error: %(msg)s %(orig_error)s"
1547
1334
 
1548
1335
    def __init__(self, msg=None, orig_error=None):
1557
1344
        BzrError.__init__(self)
1558
1345
 
1559
1346
 
1560
 
class TooManyConcurrentRequests(InternalBzrError):
 
1347
class TooManyConcurrentRequests(BzrError):
1561
1348
 
1562
1349
    _fmt = ("The medium '%(medium)s' has reached its concurrent request limit."
1563
1350
            " Be sure to finish_writing and finish_reading on the"
1564
1351
            " currently open request.")
1565
1352
 
 
1353
    internal_error = True
 
1354
 
1566
1355
    def __init__(self, medium):
1567
1356
        self.medium = medium
1568
1357
 
1575
1364
        self.details = details
1576
1365
 
1577
1366
 
1578
 
class UnexpectedProtocolVersionMarker(TransportError):
1579
 
 
1580
 
    _fmt = "Received bad protocol version marker: %(marker)r"
1581
 
 
1582
 
    def __init__(self, marker):
1583
 
        self.marker = marker
1584
 
 
1585
 
 
1586
 
class UnknownSmartMethod(InternalBzrError):
1587
 
 
1588
 
    _fmt = "The server does not recognise the '%(verb)s' request."
1589
 
 
1590
 
    def __init__(self, verb):
1591
 
        self.verb = verb
1592
 
 
1593
 
 
1594
 
class SmartMessageHandlerError(InternalBzrError):
1595
 
 
1596
 
    _fmt = ("The message handler raised an exception:\n"
1597
 
            "%(traceback_text)s")
1598
 
 
1599
 
    def __init__(self, exc_info):
1600
 
        import traceback
1601
 
        self.exc_type, self.exc_value, self.exc_tb = exc_info
1602
 
        self.exc_info = exc_info
1603
 
        traceback_strings = traceback.format_exception(
1604
 
                self.exc_type, self.exc_value, self.exc_tb)
1605
 
        self.traceback_text = ''.join(traceback_strings)
1606
 
 
1607
 
 
1608
1367
# A set of semi-meaningful errors which can be thrown
1609
1368
class TransportNotPossible(TransportError):
1610
1369
 
1635
1394
            self.port = ':%s' % port
1636
1395
 
1637
1396
 
1638
 
# XXX: This is also used for unexpected end of file, which is different at the
1639
 
# TCP level from "connection reset".
1640
1397
class ConnectionReset(TransportError):
1641
1398
 
1642
1399
    _fmt = "Connection closed: %(msg)s %(orig_error)s"
1644
1401
 
1645
1402
class InvalidRange(TransportError):
1646
1403
 
1647
 
    _fmt = "Invalid range access in %(path)s at %(offset)s: %(msg)s"
1648
 
 
1649
 
    def __init__(self, path, offset, msg=None):
1650
 
        TransportError.__init__(self, msg)
 
1404
    _fmt = "Invalid range access in %(path)s at %(offset)s."
 
1405
    
 
1406
    def __init__(self, path, offset):
 
1407
        TransportError.__init__(self, ("Invalid range access in %s at %d"
 
1408
                                       % (path, offset)))
1651
1409
        self.path = path
1652
1410
        self.offset = offset
1653
1411
 
1664
1422
class InvalidHttpRange(InvalidHttpResponse):
1665
1423
 
1666
1424
    _fmt = "Invalid http range %(range)r for %(path)s: %(msg)s"
1667
 
 
 
1425
    
1668
1426
    def __init__(self, path, range, msg):
1669
1427
        self.range = range
1670
1428
        InvalidHttpResponse.__init__(self, path, msg)
1673
1431
class InvalidHttpContentType(InvalidHttpResponse):
1674
1432
 
1675
1433
    _fmt = 'Invalid http Content-type "%(ctype)s" for %(path)s: %(msg)s'
1676
 
 
 
1434
    
1677
1435
    def __init__(self, path, ctype, msg):
1678
1436
        self.ctype = ctype
1679
1437
        InvalidHttpResponse.__init__(self, path, msg)
1683
1441
 
1684
1442
    _fmt = '%(source)s is%(permanently)s redirected to %(target)s'
1685
1443
 
1686
 
    def __init__(self, source, target, is_permanent=False):
 
1444
    def __init__(self, source, target, is_permament=False, qual_proto=None):
1687
1445
        self.source = source
1688
1446
        self.target = target
1689
 
        if is_permanent:
 
1447
        if is_permament:
1690
1448
            self.permanently = ' permanently'
1691
1449
        else:
1692
1450
            self.permanently = ''
 
1451
        self.is_permament = is_permament
 
1452
        self._qualified_proto = qual_proto
1693
1453
        TransportError.__init__(self)
1694
1454
 
 
1455
    def _requalify_url(self, url):
 
1456
        """Restore the qualified proto in front of the url"""
 
1457
        # When this exception is raised, source and target are in
 
1458
        # user readable format. But some transports may use a
 
1459
        # different proto (http+urllib:// will present http:// to
 
1460
        # the user. If a qualified proto is specified, the code
 
1461
        # trapping the exception can get the qualified urls to
 
1462
        # properly handle the redirection themself (creating a
 
1463
        # new transport object from the target url for example).
 
1464
        # But checking that the scheme of the original and
 
1465
        # redirected urls are the same can be tricky. (see the
 
1466
        # FIXME in BzrDir.open_from_transport for the unique use
 
1467
        # case so far).
 
1468
        if self._qualified_proto is None:
 
1469
            return url
 
1470
 
 
1471
        # The TODO related to NotBranchError mention that doing
 
1472
        # that kind of manipulation on the urls may not be the
 
1473
        # exception object job. On the other hand, this object is
 
1474
        # the interface between the code and the user so
 
1475
        # presenting the urls in different ways is indeed its
 
1476
        # job...
 
1477
        import urlparse
 
1478
        proto, netloc, path, query, fragment = urlparse.urlsplit(url)
 
1479
        return urlparse.urlunsplit((self._qualified_proto, netloc, path,
 
1480
                                   query, fragment))
 
1481
 
 
1482
    def get_source_url(self):
 
1483
        return self._requalify_url(self.source)
 
1484
 
 
1485
    def get_target_url(self):
 
1486
        return self._requalify_url(self.target)
 
1487
 
1695
1488
 
1696
1489
class TooManyRedirections(TransportError):
1697
1490
 
1698
1491
    _fmt = "Too many redirections"
1699
1492
 
1700
 
 
1701
1493
class ConflictsInTree(BzrError):
1702
1494
 
1703
1495
    _fmt = "Working tree has conflicts."
1709
1501
        if filename is None:
1710
1502
            filename = ""
1711
1503
        message = "Error(s) parsing config file %s:\n%s" % \
1712
 
            (filename, ('\n'.join(e.msg for e in errors)))
 
1504
            (filename, ('\n'.join(e.message for e in errors)))
1713
1505
        BzrError.__init__(self, message)
1714
1506
 
1715
1507
 
1724
1516
 
1725
1517
class SigningFailed(BzrError):
1726
1518
 
1727
 
    _fmt = 'Failed to gpg sign data with command "%(command_line)s"'
 
1519
    _fmt = "Failed to gpg sign data with command %(command_line)r"
1728
1520
 
1729
1521
    def __init__(self, command_line):
1730
1522
        BzrError.__init__(self, command_line=command_line)
1732
1524
 
1733
1525
class WorkingTreeNotRevision(BzrError):
1734
1526
 
1735
 
    _fmt = ("The working tree for %(basedir)s has changed since"
 
1527
    _fmt = ("The working tree for %(basedir)s has changed since" 
1736
1528
            " the last commit, but weave merge requires that it be"
1737
1529
            " unchanged")
1738
1530
 
1755
1547
        self.graph = graph
1756
1548
 
1757
1549
 
1758
 
class WritingCompleted(InternalBzrError):
 
1550
class WritingCompleted(BzrError):
1759
1551
 
1760
1552
    _fmt = ("The MediumRequest '%(request)s' has already had finish_writing "
1761
1553
            "called upon it - accept bytes may not be called anymore.")
1762
1554
 
 
1555
    internal_error = True
 
1556
 
1763
1557
    def __init__(self, request):
1764
1558
        self.request = request
1765
1559
 
1766
1560
 
1767
 
class WritingNotComplete(InternalBzrError):
 
1561
class WritingNotComplete(BzrError):
1768
1562
 
1769
1563
    _fmt = ("The MediumRequest '%(request)s' has not has finish_writing "
1770
1564
            "called upon it - until the write phase is complete no "
1771
1565
            "data may be read.")
1772
1566
 
 
1567
    internal_error = True
 
1568
 
1773
1569
    def __init__(self, request):
1774
1570
        self.request = request
1775
1571
 
1783
1579
        self.filename = filename
1784
1580
 
1785
1581
 
1786
 
class MediumNotConnected(InternalBzrError):
 
1582
class MediumNotConnected(BzrError):
1787
1583
 
1788
1584
    _fmt = """The medium '%(medium)s' is not connected."""
1789
1585
 
 
1586
    internal_error = True
 
1587
 
1790
1588
    def __init__(self, medium):
1791
1589
        self.medium = medium
1792
1590
 
1798
1596
 
1799
1597
class NoBundleFound(BzrError):
1800
1598
 
1801
 
    _fmt = 'No bundle was found in "%(filename)s".'
 
1599
    _fmt = "No bundle was found in %(filename)s"
1802
1600
 
1803
1601
    def __init__(self, filename):
1804
1602
        BzrError.__init__(self)
1827
1625
        self.text_revision = text_revision
1828
1626
        self.file_id = file_id
1829
1627
 
1830
 
 
1831
1628
class DuplicateFileId(BzrError):
1832
1629
 
1833
1630
    _fmt = "File id {%(file_id)s} already exists in inventory as %(entry)s"
1868
1665
        self.root_trans_id = transform.root
1869
1666
 
1870
1667
 
1871
 
class BzrBadParameter(InternalBzrError):
 
1668
class BzrBadParameter(BzrError):
1872
1669
 
1873
1670
    _fmt = "Bad parameter: %(param)r"
1874
1671
 
 
1672
    internal_error = True
 
1673
 
1875
1674
    # This exception should never be thrown, but it is a base class for all
1876
1675
    # parameter-to-function errors.
1877
1676
 
1900
1699
    _fmt = "Could not move %(from_path)s%(operator)s %(to_path)s%(extra)s"
1901
1700
 
1902
1701
    def __init__(self, from_path='', to_path='', extra=None):
1903
 
        from bzrlib.osutils import splitpath
1904
1702
        BzrError.__init__(self)
1905
1703
        if extra:
1906
1704
            self.extra = ': ' + str(extra)
1910
1708
        has_from = len(from_path) > 0
1911
1709
        has_to = len(to_path) > 0
1912
1710
        if has_from:
1913
 
            self.from_path = splitpath(from_path)[-1]
 
1711
            self.from_path = osutils.splitpath(from_path)[-1]
1914
1712
        else:
1915
1713
            self.from_path = ''
1916
1714
 
1917
1715
        if has_to:
1918
 
            self.to_path = splitpath(to_path)[-1]
 
1716
            self.to_path = osutils.splitpath(to_path)[-1]
1919
1717
        else:
1920
1718
            self.to_path = ''
1921
1719
 
1940
1738
class BzrRemoveChangedFilesError(BzrError):
1941
1739
    """Used when user is trying to remove changed files."""
1942
1740
 
1943
 
    _fmt = ("Can't safely remove modified or unknown files:\n"
1944
 
        "%(changes_as_text)s"
 
1741
    _fmt = ("Can't remove changed or unknown files:\n%(changes_as_text)s"
1945
1742
        "Use --keep to not delete them, or --force to delete them regardless.")
1946
1743
 
1947
1744
    def __init__(self, tree_delta):
2012
1809
        self.format = format
2013
1810
 
2014
1811
 
2015
 
class NoDiffFound(BzrError):
2016
 
 
2017
 
    _fmt = 'Could not find an appropriate Differ for file "%(path)s"'
2018
 
 
2019
 
    def __init__(self, path):
2020
 
        BzrError.__init__(self, path)
2021
 
 
2022
 
 
2023
 
class ExecutableMissing(BzrError):
2024
 
 
2025
 
    _fmt = "%(exe_name)s could not be found on this machine"
2026
 
 
2027
 
    def __init__(self, exe_name):
2028
 
        BzrError.__init__(self, exe_name=exe_name)
2029
 
 
2030
 
 
2031
1812
class NoDiff(BzrError):
2032
1813
 
2033
1814
    _fmt = "Diff is not installed on this machine: %(msg)s"
2041
1822
    _fmt = "Diff3 is not installed on this machine."
2042
1823
 
2043
1824
 
2044
 
class ExistingContent(BzrError):
2045
 
    # Added in bzrlib 0.92, used by VersionedFile.add_lines.
2046
 
 
2047
 
    _fmt = "The content being inserted is already present."
2048
 
 
2049
 
 
2050
1825
class ExistingLimbo(BzrError):
2051
1826
 
2052
1827
    _fmt = """This tree contains left-over files from a failed operation.
2053
1828
    Please examine %(limbo_dir)s to see if it contains any files you wish to
2054
1829
    keep, and delete it when you are done."""
2055
 
 
 
1830
    
2056
1831
    def __init__(self, limbo_dir):
2057
1832
       BzrError.__init__(self)
2058
1833
       self.limbo_dir = limbo_dir
2059
1834
 
2060
1835
 
2061
 
class ExistingPendingDeletion(BzrError):
2062
 
 
2063
 
    _fmt = """This tree contains left-over files from a failed operation.
2064
 
    Please examine %(pending_deletion)s to see if it contains any files you
2065
 
    wish to keep, and delete it when you are done."""
2066
 
 
2067
 
    def __init__(self, pending_deletion):
2068
 
       BzrError.__init__(self, pending_deletion=pending_deletion)
2069
 
 
2070
 
 
2071
1836
class ImmortalLimbo(BzrError):
2072
1837
 
2073
 
    _fmt = """Unable to delete transform temporary directory %(limbo_dir)s.
 
1838
    _fmt = """Unable to delete transform temporary directory $(limbo_dir)s.
2074
1839
    Please examine %(limbo_dir)s to see if it contains any files you wish to
2075
1840
    keep, and delete it when you are done."""
2076
1841
 
2079
1844
       self.limbo_dir = limbo_dir
2080
1845
 
2081
1846
 
2082
 
class ImmortalPendingDeletion(BzrError):
2083
 
 
2084
 
    _fmt = ("Unable to delete transform temporary directory "
2085
 
    "%(pending_deletion)s.  Please examine %(pending_deletion)s to see if it "
2086
 
    "contains any files you wish to keep, and delete it when you are done.")
2087
 
 
2088
 
    def __init__(self, pending_deletion):
2089
 
       BzrError.__init__(self, pending_deletion=pending_deletion)
2090
 
 
2091
 
 
2092
1847
class OutOfDateTree(BzrError):
2093
1848
 
2094
1849
    _fmt = "Working tree is out of date, please run 'bzr update'."
2121
1876
    _fmt = "Format error in conflict listings"
2122
1877
 
2123
1878
 
2124
 
class CorruptDirstate(BzrError):
2125
 
 
2126
 
    _fmt = ("Inconsistency in dirstate file %(dirstate_path)s.\n"
2127
 
            "Error: %(description)s")
2128
 
 
2129
 
    def __init__(self, dirstate_path, description):
2130
 
        BzrError.__init__(self)
2131
 
        self.dirstate_path = dirstate_path
2132
 
        self.description = description
2133
 
 
2134
 
 
2135
1879
class CorruptRepository(BzrError):
2136
1880
 
2137
1881
    _fmt = ("An error has been detected in the repository %(repo_path)s.\n"
2142
1886
        self.repo_path = repo.bzrdir.root_transport.base
2143
1887
 
2144
1888
 
2145
 
class InconsistentDelta(BzrError):
2146
 
    """Used when we get a delta that is not valid."""
2147
 
 
2148
 
    _fmt = ("An inconsistent delta was supplied involving %(path)r,"
2149
 
            " %(file_id)r\nreason: %(reason)s")
2150
 
 
2151
 
    def __init__(self, path, file_id, reason):
2152
 
        BzrError.__init__(self)
2153
 
        self.path = path
2154
 
        self.file_id = file_id
2155
 
        self.reason = reason
2156
 
 
2157
 
 
2158
1889
class UpgradeRequired(BzrError):
2159
1890
 
2160
1891
    _fmt = "To use this feature you must upgrade your branch at %(path)s."
2164
1895
        self.path = path
2165
1896
 
2166
1897
 
2167
 
class RepositoryUpgradeRequired(UpgradeRequired):
2168
 
 
2169
 
    _fmt = "To use this feature you must upgrade your repository at %(path)s."
2170
 
 
2171
 
 
2172
1898
class LocalRequiresBoundBranch(BzrError):
2173
1899
 
2174
1900
    _fmt = "Cannot perform local-only commits on unbound branches."
2175
1901
 
2176
1902
 
 
1903
class MissingProgressBarFinish(BzrError):
 
1904
 
 
1905
    _fmt = "A nested progress bar was not 'finished' correctly."
 
1906
 
 
1907
 
2177
1908
class InvalidProgressBarType(BzrError):
2178
1909
 
2179
1910
    _fmt = ("Environment variable BZR_PROGRESS_BAR='%(bar_type)s"
2205
1936
 
2206
1937
 
2207
1938
class BinaryFile(BzrError):
2208
 
 
 
1939
    
2209
1940
    _fmt = "File is binary but should be text."
2210
1941
 
2211
1942
 
2231
1962
 
2232
1963
 
2233
1964
class NotABundle(BzrError):
2234
 
 
 
1965
    
2235
1966
    _fmt = "Not a bzr revision-bundle: %(text)r"
2236
1967
 
2237
1968
    def __init__(self, text):
2239
1970
        self.text = text
2240
1971
 
2241
1972
 
2242
 
class BadBundle(BzrError):
2243
 
 
 
1973
class BadBundle(BzrError): 
 
1974
    
2244
1975
    _fmt = "Bad bzr revision-bundle: %(text)r"
2245
1976
 
2246
1977
    def __init__(self, text):
2248
1979
        self.text = text
2249
1980
 
2250
1981
 
2251
 
class MalformedHeader(BadBundle):
2252
 
 
 
1982
class MalformedHeader(BadBundle): 
 
1983
    
2253
1984
    _fmt = "Malformed bzr revision-bundle header: %(text)r"
2254
1985
 
2255
1986
 
2256
 
class MalformedPatches(BadBundle):
2257
 
 
 
1987
class MalformedPatches(BadBundle): 
 
1988
    
2258
1989
    _fmt = "Malformed patches in bzr revision-bundle: %(text)r"
2259
1990
 
2260
1991
 
2261
 
class MalformedFooter(BadBundle):
2262
 
 
 
1992
class MalformedFooter(BadBundle): 
 
1993
    
2263
1994
    _fmt = "Malformed footer in bzr revision-bundle: %(text)r"
2264
1995
 
2265
1996
 
2266
1997
class UnsupportedEOLMarker(BadBundle):
2267
 
 
2268
 
    _fmt = "End of line marker was not \\n in bzr revision-bundle"
 
1998
    
 
1999
    _fmt = "End of line marker was not \\n in bzr revision-bundle"    
2269
2000
 
2270
2001
    def __init__(self):
2271
 
        # XXX: BadBundle's constructor assumes there's explanatory text,
 
2002
        # XXX: BadBundle's constructor assumes there's explanatory text, 
2272
2003
        # but for this there is not
2273
2004
        BzrError.__init__(self)
2274
2005
 
2275
2006
 
2276
2007
class IncompatibleBundleFormat(BzrError):
2277
 
 
 
2008
    
2278
2009
    _fmt = "Bundle format %(bundle_format)s is incompatible with %(other)s"
2279
2010
 
2280
2011
    def __init__(self, bundle_format, other):
2284
2015
 
2285
2016
 
2286
2017
class BadInventoryFormat(BzrError):
2287
 
 
 
2018
    
2288
2019
    _fmt = "Root class for inventory serialization errors"
2289
2020
 
2290
2021
 
2301
2032
    _fmt = """This operation requires rich root data storage"""
2302
2033
 
2303
2034
 
2304
 
class NoSmartMedium(InternalBzrError):
 
2035
class NoSmartMedium(BzrError):
2305
2036
 
2306
2037
    _fmt = "The transport '%(transport)s' cannot tunnel the smart protocol."
2307
2038
 
 
2039
    internal_error = True
 
2040
 
2308
2041
    def __init__(self, transport):
2309
2042
        self.transport = transport
2310
2043
 
2311
2044
 
 
2045
class NoSmartServer(NotBranchError):
 
2046
 
 
2047
    _fmt = "No smart server available at %(url)s"
 
2048
 
 
2049
    def __init__(self, url):
 
2050
        self.url = url
 
2051
 
 
2052
 
2312
2053
class UnknownSSH(BzrError):
2313
2054
 
2314
2055
    _fmt = "Unrecognised value for BZR_SSH environment variable: %(vendor)s"
2324
2065
            " Please set BZR_SSH environment variable.")
2325
2066
 
2326
2067
 
2327
 
class GhostRevisionsHaveNoRevno(BzrError):
2328
 
    """When searching for revnos, if we encounter a ghost, we are stuck"""
2329
 
 
2330
 
    _fmt = ("Could not determine revno for {%(revision_id)s} because"
2331
 
            " its ancestry shows a ghost at {%(ghost_revision_id)s}")
2332
 
 
2333
 
    def __init__(self, revision_id, ghost_revision_id):
2334
 
        self.revision_id = revision_id
2335
 
        self.ghost_revision_id = ghost_revision_id
2336
 
 
2337
 
 
2338
2068
class GhostRevisionUnusableHere(BzrError):
2339
2069
 
2340
2070
    _fmt = "Ghost revision {%(revision_id)s} cannot be used here."
2344
2074
        self.revision_id = revision_id
2345
2075
 
2346
2076
 
2347
 
class IllegalUseOfScopeReplacer(InternalBzrError):
 
2077
class IllegalUseOfScopeReplacer(BzrError):
2348
2078
 
2349
2079
    _fmt = ("ScopeReplacer object %(name)r was used incorrectly:"
2350
2080
            " %(msg)s%(extra)s")
2351
2081
 
 
2082
    internal_error = True
 
2083
 
2352
2084
    def __init__(self, name, msg, extra=None):
2353
2085
        BzrError.__init__(self)
2354
2086
        self.name = name
2359
2091
            self.extra = ''
2360
2092
 
2361
2093
 
2362
 
class InvalidImportLine(InternalBzrError):
 
2094
class InvalidImportLine(BzrError):
2363
2095
 
2364
2096
    _fmt = "Not a valid import statement: %(msg)\n%(text)s"
2365
2097
 
 
2098
    internal_error = True
 
2099
 
2366
2100
    def __init__(self, text, msg):
2367
2101
        BzrError.__init__(self)
2368
2102
        self.text = text
2369
2103
        self.msg = msg
2370
2104
 
2371
2105
 
2372
 
class ImportNameCollision(InternalBzrError):
 
2106
class ImportNameCollision(BzrError):
2373
2107
 
2374
2108
    _fmt = ("Tried to import an object to the same name as"
2375
2109
            " an existing object. %(name)s")
2376
2110
 
 
2111
    internal_error = True
 
2112
 
2377
2113
    def __init__(self, name):
2378
2114
        BzrError.__init__(self)
2379
2115
        self.name = name
2411
2147
class PatchMissing(BzrError):
2412
2148
    """Raise a patch type was specified but no patch supplied"""
2413
2149
 
2414
 
    _fmt = "Patch_type was %(patch_type)s, but no patch was supplied."
 
2150
    _fmt = "patch_type was %(patch_type)s, but no patch was supplied."
2415
2151
 
2416
2152
    def __init__(self, patch_type):
2417
2153
        BzrError.__init__(self)
2418
2154
        self.patch_type = patch_type
2419
2155
 
2420
2156
 
2421
 
class TargetNotBranch(BzrError):
2422
 
    """A merge directive's target branch is required, but isn't a branch"""
2423
 
 
2424
 
    _fmt = ("Your branch does not have all of the revisions required in "
2425
 
            "order to merge this merge directive and the target "
2426
 
            "location specified in the merge directive is not a branch: "
2427
 
            "%(location)s.")
2428
 
 
2429
 
    def __init__(self, location):
2430
 
        BzrError.__init__(self)
2431
 
        self.location = location
2432
 
 
2433
 
 
2434
2157
class UnsupportedInventoryKind(BzrError):
2435
 
 
 
2158
    
2436
2159
    _fmt = """Unsupported entry kind %(kind)s"""
2437
2160
 
2438
2161
    def __init__(self, kind):
2441
2164
 
2442
2165
class BadSubsumeSource(BzrError):
2443
2166
 
2444
 
    _fmt = "Can't subsume %(other_tree)s into %(tree)s. %(reason)s"
 
2167
    _fmt = """Can't subsume %(other_tree)s into %(tree)s.  %(reason)s"""
2445
2168
 
2446
2169
    def __init__(self, tree, other_tree, reason):
2447
2170
        self.tree = tree
2450
2173
 
2451
2174
 
2452
2175
class SubsumeTargetNeedsUpgrade(BzrError):
2453
 
 
 
2176
    
2454
2177
    _fmt = """Subsume target %(other_tree)s needs to be upgraded."""
2455
2178
 
2456
2179
    def __init__(self, other_tree):
2457
2180
        self.other_tree = other_tree
2458
2181
 
2459
2182
 
2460
 
class BadReferenceTarget(InternalBzrError):
2461
 
 
2462
 
    _fmt = "Can't add reference to %(other_tree)s into %(tree)s." \
2463
 
           "%(reason)s"
 
2183
class BadReferenceTarget(BzrError):
 
2184
 
 
2185
    _fmt = "Can't add reference to %(other_tree)s into %(tree)s.  %(reason)s"
 
2186
 
 
2187
    internal_error = True
2464
2188
 
2465
2189
    def __init__(self, tree, other_tree, reason):
2466
2190
        self.tree = tree
2479
2203
class TagsNotSupported(BzrError):
2480
2204
 
2481
2205
    _fmt = ("Tags not supported by %(branch)s;"
2482
 
            " you may be able to use bzr upgrade.")
 
2206
            " you may be able to use bzr upgrade --dirstate-tags.")
2483
2207
 
2484
2208
    def __init__(self, branch):
2485
2209
        self.branch = branch
2486
2210
 
2487
 
 
 
2211
        
2488
2212
class TagAlreadyExists(BzrError):
2489
2213
 
2490
2214
    _fmt = "Tag %(tag_name)s already exists."
2495
2219
 
2496
2220
class MalformedBugIdentifier(BzrError):
2497
2221
 
2498
 
    _fmt = ('Did not understand bug identifier %(bug_id)s: %(reason)s. '
2499
 
            'See "bzr help bugs" for more information on this feature.')
 
2222
    _fmt = "Did not understand bug identifier %(bug_id)s: %(reason)s"
2500
2223
 
2501
2224
    def __init__(self, bug_id, reason):
2502
2225
        self.bug_id = bug_id
2503
2226
        self.reason = reason
2504
2227
 
2505
2228
 
2506
 
class InvalidBugTrackerURL(BzrError):
2507
 
 
2508
 
    _fmt = ("The URL for bug tracker \"%(abbreviation)s\" doesn't "
2509
 
            "contain {id}: %(url)s")
2510
 
 
2511
 
    def __init__(self, abbreviation, url):
2512
 
        self.abbreviation = abbreviation
2513
 
        self.url = url
2514
 
 
2515
 
 
2516
2229
class UnknownBugTrackerAbbreviation(BzrError):
2517
2230
 
2518
2231
    _fmt = ("Cannot find registered bug tracker called %(abbreviation)s "
2523
2236
        self.branch = branch
2524
2237
 
2525
2238
 
2526
 
class InvalidLineInBugsProperty(BzrError):
2527
 
 
2528
 
    _fmt = ("Invalid line in bugs property: '%(line)s'")
2529
 
 
2530
 
    def __init__(self, line):
2531
 
        self.line = line
2532
 
 
2533
 
 
2534
 
class InvalidBugStatus(BzrError):
2535
 
 
2536
 
    _fmt = ("Invalid bug status: '%(status)s'")
2537
 
 
2538
 
    def __init__(self, status):
2539
 
        self.status = status
2540
 
 
2541
 
 
2542
2239
class UnexpectedSmartServerResponse(BzrError):
2543
2240
 
2544
2241
    _fmt = "Could not understand response from smart server: %(response_tuple)r"
2547
2244
        self.response_tuple = response_tuple
2548
2245
 
2549
2246
 
2550
 
class ErrorFromSmartServer(BzrError):
2551
 
    """An error was received from a smart server.
2552
 
 
2553
 
    :seealso: UnknownErrorFromSmartServer
2554
 
    """
2555
 
 
2556
 
    _fmt = "Error received from smart server: %(error_tuple)r"
2557
 
 
2558
 
    internal_error = True
2559
 
 
2560
 
    def __init__(self, error_tuple):
2561
 
        self.error_tuple = error_tuple
2562
 
        try:
2563
 
            self.error_verb = error_tuple[0]
2564
 
        except IndexError:
2565
 
            self.error_verb = None
2566
 
        self.error_args = error_tuple[1:]
2567
 
 
2568
 
 
2569
 
class UnknownErrorFromSmartServer(BzrError):
2570
 
    """An ErrorFromSmartServer could not be translated into a typical bzrlib
2571
 
    error.
2572
 
 
2573
 
    This is distinct from ErrorFromSmartServer so that it is possible to
2574
 
    distinguish between the following two cases:
2575
 
      - ErrorFromSmartServer was uncaught.  This is logic error in the client
2576
 
        and so should provoke a traceback to the user.
2577
 
      - ErrorFromSmartServer was caught but its error_tuple could not be
2578
 
        translated.  This is probably because the server sent us garbage, and
2579
 
        should not provoke a traceback.
2580
 
    """
2581
 
 
2582
 
    _fmt = "Server sent an unexpected error: %(error_tuple)r"
2583
 
 
2584
 
    internal_error = False
2585
 
 
2586
 
    def __init__(self, error_from_smart_server):
2587
 
        """Constructor.
2588
 
 
2589
 
        :param error_from_smart_server: An ErrorFromSmartServer instance.
2590
 
        """
2591
 
        self.error_from_smart_server = error_from_smart_server
2592
 
        self.error_tuple = error_from_smart_server.error_tuple
2593
 
 
2594
 
 
2595
2247
class ContainerError(BzrError):
2596
2248
    """Base class of container errors."""
2597
2249
 
2599
2251
class UnknownContainerFormatError(ContainerError):
2600
2252
 
2601
2253
    _fmt = "Unrecognised container format: %(container_format)r"
2602
 
 
 
2254
    
2603
2255
    def __init__(self, container_format):
2604
2256
        self.container_format = container_format
2605
2257
 
2608
2260
 
2609
2261
    _fmt = "Unexpected end of container stream"
2610
2262
 
 
2263
    internal_error = False
 
2264
 
2611
2265
 
2612
2266
class UnknownRecordTypeError(ContainerError):
2613
2267
 
2635
2289
 
2636
2290
class DuplicateRecordNameError(ContainerError):
2637
2291
 
2638
 
    _fmt = "Container has multiple records with the same name: %(name)s"
 
2292
    _fmt = "Container has multiple records with the same name: \"%(name)s\""
2639
2293
 
2640
2294
    def __init__(self, name):
2641
2295
        self.name = name
2642
2296
 
2643
2297
 
2644
 
class NoDestinationAddress(InternalBzrError):
 
2298
class NoDestinationAddress(BzrError):
2645
2299
 
2646
2300
    _fmt = "Message does not have a destination address."
2647
2301
 
2648
 
 
2649
 
class RepositoryDataStreamError(BzrError):
2650
 
 
2651
 
    _fmt = "Corrupt or incompatible data stream: %(reason)s"
2652
 
 
2653
 
    def __init__(self, reason):
2654
 
        self.reason = reason
 
2302
    internal_error = True
2655
2303
 
2656
2304
 
2657
2305
class SMTPError(BzrError):
2660
2308
 
2661
2309
    def __init__(self, error):
2662
2310
        self.error = error
2663
 
 
2664
 
 
2665
 
class NoMessageSupplied(BzrError):
2666
 
 
2667
 
    _fmt = "No message supplied."
2668
 
 
2669
 
 
2670
 
class NoMailAddressSpecified(BzrError):
2671
 
 
2672
 
    _fmt = "No mail-to address (--mail-to) or output (-o) specified."
2673
 
 
2674
 
 
2675
 
class UnknownMailClient(BzrError):
2676
 
 
2677
 
    _fmt = "Unknown mail client: %(mail_client)s"
2678
 
 
2679
 
    def __init__(self, mail_client):
2680
 
        BzrError.__init__(self, mail_client=mail_client)
2681
 
 
2682
 
 
2683
 
class MailClientNotFound(BzrError):
2684
 
 
2685
 
    _fmt = "Unable to find mail client with the following names:"\
2686
 
        " %(mail_command_list_string)s"
2687
 
 
2688
 
    def __init__(self, mail_command_list):
2689
 
        mail_command_list_string = ', '.join(mail_command_list)
2690
 
        BzrError.__init__(self, mail_command_list=mail_command_list,
2691
 
                          mail_command_list_string=mail_command_list_string)
2692
 
 
2693
 
class SMTPConnectionRefused(SMTPError):
2694
 
 
2695
 
    _fmt = "SMTP connection to %(host)s refused"
2696
 
 
2697
 
    def __init__(self, error, host):
2698
 
        self.error = error
2699
 
        self.host = host
2700
 
 
2701
 
 
2702
 
class DefaultSMTPConnectionRefused(SMTPConnectionRefused):
2703
 
 
2704
 
    _fmt = "Please specify smtp_server.  No server at default %(host)s."
2705
 
 
2706
 
 
2707
 
class BzrDirError(BzrError):
2708
 
 
2709
 
    def __init__(self, bzrdir):
2710
 
        import bzrlib.urlutils as urlutils
2711
 
        display_url = urlutils.unescape_for_display(bzrdir.root_transport.base,
2712
 
                                                    'ascii')
2713
 
        BzrError.__init__(self, bzrdir=bzrdir, display_url=display_url)
2714
 
 
2715
 
 
2716
 
class UnsyncedBranches(BzrDirError):
2717
 
 
2718
 
    _fmt = ("'%(display_url)s' is not in sync with %(target_url)s.  See"
2719
 
            " bzr help sync-for-reconfigure.")
2720
 
 
2721
 
    def __init__(self, bzrdir, target_branch):
2722
 
        BzrDirError.__init__(self, bzrdir)
2723
 
        import bzrlib.urlutils as urlutils
2724
 
        self.target_url = urlutils.unescape_for_display(target_branch.base,
2725
 
                                                        'ascii')
2726
 
 
2727
 
 
2728
 
class AlreadyBranch(BzrDirError):
2729
 
 
2730
 
    _fmt = "'%(display_url)s' is already a branch."
2731
 
 
2732
 
 
2733
 
class AlreadyTree(BzrDirError):
2734
 
 
2735
 
    _fmt = "'%(display_url)s' is already a tree."
2736
 
 
2737
 
 
2738
 
class AlreadyCheckout(BzrDirError):
2739
 
 
2740
 
    _fmt = "'%(display_url)s' is already a checkout."
2741
 
 
2742
 
 
2743
 
class AlreadyLightweightCheckout(BzrDirError):
2744
 
 
2745
 
    _fmt = "'%(display_url)s' is already a lightweight checkout."
2746
 
 
2747
 
 
2748
 
class AlreadyUsingShared(BzrDirError):
2749
 
 
2750
 
    _fmt = "'%(display_url)s' is already using a shared repository."
2751
 
 
2752
 
 
2753
 
class AlreadyStandalone(BzrDirError):
2754
 
 
2755
 
    _fmt = "'%(display_url)s' is already standalone."
2756
 
 
2757
 
 
2758
 
class AlreadyWithTrees(BzrDirError):
2759
 
 
2760
 
    _fmt = ("Shared repository '%(display_url)s' already creates "
2761
 
            "working trees.")
2762
 
 
2763
 
 
2764
 
class AlreadyWithNoTrees(BzrDirError):
2765
 
 
2766
 
    _fmt = ("Shared repository '%(display_url)s' already doesn't create "
2767
 
            "working trees.")
2768
 
 
2769
 
 
2770
 
class ReconfigurationNotSupported(BzrDirError):
2771
 
 
2772
 
    _fmt = "Requested reconfiguration of '%(display_url)s' is not supported."
2773
 
 
2774
 
 
2775
 
class NoBindLocation(BzrDirError):
2776
 
 
2777
 
    _fmt = "No location could be found to bind to at %(display_url)s."
2778
 
 
2779
 
 
2780
 
class UncommittedChanges(BzrError):
2781
 
 
2782
 
    _fmt = 'Working tree "%(display_url)s" has uncommitted changes.'
2783
 
 
2784
 
    def __init__(self, tree):
2785
 
        import bzrlib.urlutils as urlutils
2786
 
        display_url = urlutils.unescape_for_display(
2787
 
            tree.bzrdir.root_transport.base, 'ascii')
2788
 
        BzrError.__init__(self, tree=tree, display_url=display_url)
2789
 
 
2790
 
 
2791
 
class MissingTemplateVariable(BzrError):
2792
 
 
2793
 
    _fmt = 'Variable {%(name)s} is not available.'
2794
 
 
2795
 
    def __init__(self, name):
2796
 
        self.name = name
2797
 
 
2798
 
 
2799
 
class NoTemplate(BzrError):
2800
 
 
2801
 
    _fmt = 'No template specified.'
2802
 
 
2803
 
 
2804
 
class UnableCreateSymlink(BzrError):
2805
 
 
2806
 
    _fmt = 'Unable to create symlink %(path_str)son this platform'
2807
 
 
2808
 
    def __init__(self, path=None):
2809
 
        path_str = ''
2810
 
        if path:
2811
 
            try:
2812
 
                path_str = repr(str(path))
2813
 
            except UnicodeEncodeError:
2814
 
                path_str = repr(path)
2815
 
            path_str += ' '
2816
 
        self.path_str = path_str
2817
 
 
2818
 
 
2819
 
class UnsupportedTimezoneFormat(BzrError):
2820
 
 
2821
 
    _fmt = ('Unsupported timezone format "%(timezone)s", '
2822
 
            'options are "utc", "original", "local".')
2823
 
 
2824
 
    def __init__(self, timezone):
2825
 
        self.timezone = timezone
2826
 
 
2827
 
 
2828
 
class CommandAvailableInPlugin(StandardError):
2829
 
 
2830
 
    internal_error = False
2831
 
 
2832
 
    def __init__(self, cmd_name, plugin_metadata, provider):
2833
 
 
2834
 
        self.plugin_metadata = plugin_metadata
2835
 
        self.cmd_name = cmd_name
2836
 
        self.provider = provider
2837
 
 
2838
 
    def __str__(self):
2839
 
 
2840
 
        _fmt = ('"%s" is not a standard bzr command. \n'
2841
 
                'However, the following official plugin provides this command: %s\n'
2842
 
                'You can install it by going to: %s'
2843
 
                % (self.cmd_name, self.plugin_metadata['name'],
2844
 
                    self.plugin_metadata['url']))
2845
 
 
2846
 
        return _fmt
2847
 
 
2848
 
 
2849
 
class NoPluginAvailable(BzrError):
2850
 
    pass
2851
 
 
2852
 
 
2853
 
class UnableEncodePath(BzrError):
2854
 
 
2855
 
    _fmt = ('Unable to encode %(kind)s path %(path)r in '
2856
 
            'user encoding %(user_encoding)s')
2857
 
 
2858
 
    def __init__(self, path, kind):
2859
 
        from bzrlib.osutils import get_user_encoding
2860
 
        self.path = path
2861
 
        self.kind = kind
2862
 
        self.user_encoding = osutils.get_user_encoding()
2863
 
 
2864
 
 
2865
 
class NoSuchAlias(BzrError):
2866
 
 
2867
 
    _fmt = ('The alias "%(alias_name)s" does not exist.')
2868
 
 
2869
 
    def __init__(self, alias_name):
2870
 
        BzrError.__init__(self, alias_name=alias_name)
2871
 
 
2872
 
 
2873
 
class DirectoryLookupFailure(BzrError):
2874
 
    """Base type for lookup errors."""
2875
 
 
2876
 
    pass
2877
 
 
2878
 
 
2879
 
class InvalidLocationAlias(DirectoryLookupFailure):
2880
 
 
2881
 
    _fmt = '"%(alias_name)s" is not a valid location alias.'
2882
 
 
2883
 
    def __init__(self, alias_name):
2884
 
        DirectoryLookupFailure.__init__(self, alias_name=alias_name)
2885
 
 
2886
 
 
2887
 
class UnsetLocationAlias(DirectoryLookupFailure):
2888
 
 
2889
 
    _fmt = 'No %(alias_name)s location assigned.'
2890
 
 
2891
 
    def __init__(self, alias_name):
2892
 
        DirectoryLookupFailure.__init__(self, alias_name=alias_name[1:])
2893
 
 
2894
 
 
2895
 
class CannotBindAddress(BzrError):
2896
 
 
2897
 
    _fmt = 'Cannot bind address "%(host)s:%(port)i": %(orig_error)s.'
2898
 
 
2899
 
    def __init__(self, host, port, orig_error):
2900
 
        BzrError.__init__(self, host=host, port=port,
2901
 
            orig_error=orig_error[1])
2902
 
 
2903
 
 
2904
 
class UnknownRules(BzrError):
2905
 
 
2906
 
    _fmt = ('Unknown rules detected: %(unknowns_str)s.')
2907
 
 
2908
 
    def __init__(self, unknowns):
2909
 
        BzrError.__init__(self, unknowns_str=", ".join(unknowns))
2910
 
 
2911
 
 
2912
 
class HookFailed(BzrError):
2913
 
    """Raised when a pre_change_branch_tip hook function fails anything other
2914
 
    than TipChangeRejected.
2915
 
    """
2916
 
 
2917
 
    _fmt = ("Hook '%(hook_name)s' during %(hook_stage)s failed:\n"
2918
 
            "%(traceback_text)s%(exc_value)s")
2919
 
 
2920
 
    def __init__(self, hook_stage, hook_name, exc_info):
2921
 
        import traceback
2922
 
        self.hook_stage = hook_stage
2923
 
        self.hook_name = hook_name
2924
 
        self.exc_info = exc_info
2925
 
        self.exc_type = exc_info[0]
2926
 
        self.exc_value = exc_info[1]
2927
 
        self.exc_tb = exc_info[2]
2928
 
        self.traceback_text = ''.join(traceback.format_tb(self.exc_tb))
2929
 
 
2930
 
 
2931
 
class TipChangeRejected(BzrError):
2932
 
    """A pre_change_branch_tip hook function may raise this to cleanly and
2933
 
    explicitly abort a change to a branch tip.
2934
 
    """
2935
 
 
2936
 
    _fmt = u"Tip change rejected: %(msg)s"
2937
 
 
2938
 
    def __init__(self, msg):
2939
 
        self.msg = msg
2940
 
 
2941
 
 
2942
 
class ShelfCorrupt(BzrError):
2943
 
 
2944
 
    _fmt = "Shelf corrupt."
2945
 
 
2946
 
 
2947
 
class NoSuchShelfId(BzrError):
2948
 
 
2949
 
    _fmt = 'No changes are shelved with id "%(shelf_id)d".'
2950
 
 
2951
 
    def __init__(self, shelf_id):
2952
 
        BzrError.__init__(self, shelf_id=shelf_id)
2953
 
 
2954
 
 
2955
 
class InvalidShelfId(BzrError):
2956
 
 
2957
 
    _fmt = '"%(invalid_id)s" is not a valid shelf id, try a number instead.'
2958
 
 
2959
 
    def __init__(self, invalid_id):
2960
 
        BzrError.__init__(self, invalid_id=invalid_id)
2961
 
 
2962
 
 
2963
 
class UserAbort(BzrError):
2964
 
 
2965
 
    _fmt = 'The user aborted the operation.'
2966
 
 
2967
 
 
2968
 
class MustHaveWorkingTree(BzrError):
2969
 
 
2970
 
    _fmt = ("Branching '%(url)s'(%(format)s) must create a working tree.")
2971
 
 
2972
 
    def __init__(self, format, url):
2973
 
        BzrError.__init__(self, format=format, url=url)
2974
 
 
2975
 
 
2976
 
class NoSuchView(BzrError):
2977
 
    """A view does not exist.
2978
 
    """
2979
 
 
2980
 
    _fmt = u"No such view: %(view_name)s."
2981
 
 
2982
 
    def __init__(self, view_name):
2983
 
        self.view_name = view_name
2984
 
 
2985
 
 
2986
 
class ViewsNotSupported(BzrError):
2987
 
    """Views are not supported by a tree format.
2988
 
    """
2989
 
 
2990
 
    _fmt = ("Views are not supported by %(tree)s;"
2991
 
            " use 'bzr upgrade' to change your tree to a later format.")
2992
 
 
2993
 
    def __init__(self, tree):
2994
 
        self.tree = tree
2995
 
 
2996
 
 
2997
 
class FileOutsideView(BzrError):
2998
 
 
2999
 
    _fmt = ('Specified file "%(file_name)s" is outside the current view: '
3000
 
            '%(view_str)s')
3001
 
 
3002
 
    def __init__(self, file_name, view_files):
3003
 
        self.file_name = file_name
3004
 
        self.view_str = ", ".join(view_files)
3005
 
 
3006
 
 
3007
 
class UnresumableWriteGroup(BzrError):
3008
 
 
3009
 
    _fmt = ("Repository %(repository)s cannot resume write group "
3010
 
            "%(write_groups)r: %(reason)s")
3011
 
 
3012
 
    internal_error = True
3013
 
 
3014
 
    def __init__(self, repository, write_groups, reason):
3015
 
        self.repository = repository
3016
 
        self.write_groups = write_groups
3017
 
        self.reason = reason
3018
 
 
3019
 
 
3020
 
class UnsuspendableWriteGroup(BzrError):
3021
 
 
3022
 
    _fmt = ("Repository %(repository)s cannot suspend a write group.")
3023
 
 
3024
 
    internal_error = True
3025
 
 
3026
 
    def __init__(self, repository):
3027
 
        self.repository = repository