~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/errors.py

  • Committer: Aaron Bentley
  • Date: 2008-03-03 16:52:41 UTC
  • mfrom: (3144.3.11 fix-conflict-handling)
  • mto: This revision was merged to the branch mainline in revision 3250.
  • Revision ID: aaron@aaronbentley.com-20080303165241-0k2c7ggs6kr9q6hf
Merge with fix-conflict-handling

Show diffs side-by-side

added added

removed removed

Lines of Context:
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,
80
81
        parameters.
81
82
 
82
83
        :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'.
 
84
        not subject to expansion.
85
85
        """
86
86
        StandardError.__init__(self)
87
87
        if msg is not None:
93
93
            for key, value in kwds.items():
94
94
                setattr(self, key, value)
95
95
 
96
 
    def _format(self):
 
96
    def __str__(self):
97
97
        s = getattr(self, '_preformatted_string', None)
98
98
        if s is not None:
99
 
            # contains a preformatted message
100
 
            return s
 
99
            # contains a preformatted message; must be cast to plain str
 
100
            return str(s)
101
101
        try:
102
102
            fmt = self._get_format_string()
103
103
            if fmt:
104
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')
105
108
                s = fmt % d
106
109
                # __str__() should always return a 'str' object
107
110
                # never a 'unicode' object.
 
111
                if isinstance(s, unicode):
 
112
                    return s.encode('utf8')
108
113
                return s
109
114
        except (AttributeError, TypeError, NameError, ValueError, KeyError), e:
110
115
            return 'Unprintable exception %s: dict=%r, fmt=%r, error=%r' \
113
118
                   getattr(self, '_fmt', None),
114
119
                   e)
115
120
 
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
121
    def _get_format_string(self):
140
122
        """Return format string for this exception or None"""
141
123
        fmt = getattr(self, '_fmt', None)
153
135
               getattr(self, '_fmt', None),
154
136
               )
155
137
 
156
 
    def __eq__(self, other):
157
 
        if self.__class__ != other.__class__:
158
 
            return NotImplemented
159
 
        return self.__dict__ == other.__dict__
160
 
 
161
138
 
162
139
class InternalBzrError(BzrError):
163
140
    """Base class for errors that are internal in nature.
204
181
 
205
182
 
206
183
class AlreadyBuilding(BzrError):
207
 
 
 
184
    
208
185
    _fmt = "The tree builder is already building a tree."
209
186
 
210
187
 
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
188
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
 
189
    
 
190
    _fmt = "Internal check failed: %(message)s"
 
191
 
 
192
    def __init__(self, message):
 
193
        BzrError.__init__(self)
 
194
        self.message = message
235
195
 
236
196
 
237
197
class DisabledMethod(InternalBzrError):
345
305
        BzrError.__init__(self, repository=repository, file_id=file_id)
346
306
 
347
307
 
348
 
class NotStacked(BranchError):
349
 
 
350
 
    _fmt = "The branch '%(branch)s' is not stacked."
351
 
 
352
 
 
353
308
class InventoryModified(InternalBzrError):
354
309
 
355
310
    _fmt = ("The current inventory for the tree %(tree)r has been modified,"
399
354
    # are not intended to be caught anyway.  UI code need not subclass
400
355
    # BzrCommandError, and non-UI code should not throw a subclass of
401
356
    # BzrCommandError.  ADHB 20051211
 
357
    def __init__(self, msg):
 
358
        # Object.__str__() must return a real string
 
359
        # returning a Unicode string is a python error.
 
360
        if isinstance(msg, unicode):
 
361
            self.msg = msg.encode('utf8')
 
362
        else:
 
363
            self.msg = msg
 
364
 
 
365
    def __str__(self):
 
366
        return self.msg
402
367
 
403
368
 
404
369
class NotWriteLocked(BzrError):
576
541
 
577
542
class InvalidURLJoin(PathError):
578
543
 
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
 
544
    _fmt = 'Invalid URL join request: "%(args)s"%(extra)s'
 
545
 
 
546
    def __init__(self, msg, base, args):
 
547
        PathError.__init__(self, base, msg)
 
548
        self.args = [base] + list(args)
608
549
 
609
550
 
610
551
class UnknownHook(BzrError):
625
566
        PathError.__init__(self, url, extra=extra)
626
567
 
627
568
 
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
569
class ReadError(PathError):
651
570
    
652
571
    _fmt = """Error reading from %(path)r."""
765
684
 
766
685
class UnknownFormatError(BzrError):
767
686
    
768
 
    _fmt = "Unknown %(kind)s format: %(format)r"
769
 
 
770
 
    def __init__(self, format, kind='branch'):
771
 
        self.kind = kind
772
 
        self.format = format
 
687
    _fmt = "Unknown branch format: %(format)r"
773
688
 
774
689
 
775
690
class IncompatibleFormat(BzrError):
784
699
 
785
700
class IncompatibleRepositories(BzrError):
786
701
 
787
 
    _fmt = "%(target)s\n" \
788
 
            "is not compatible with\n" \
789
 
            "%(source)s\n" \
790
 
            "%(details)s"
 
702
    _fmt = "Repository %(target)s is not compatible with repository"\
 
703
        " %(source)s"
791
704
 
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)
 
705
    def __init__(self, source, target):
 
706
        BzrError.__init__(self, target=target, source=source)
796
707
 
797
708
 
798
709
class IncompatibleRevision(BzrError):
885
796
        BzrError.__init__(self, filename=filename, kind=kind)
886
797
 
887
798
 
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
799
class ForbiddenControlFileError(BzrError):
900
800
 
901
801
    _fmt = 'Cannot operate on "%(filename)s" because it is a control file'
954
854
        self.obj = obj
955
855
 
956
856
 
 
857
class ReadOnlyLockError(LockError):
 
858
 
 
859
    _fmt = "Cannot acquire write lock on %(fname)s. %(msg)s"
 
860
 
 
861
    @symbol_versioning.deprecated_method(symbol_versioning.zero_ninetytwo)
 
862
    def __init__(self, fname, msg):
 
863
        LockError.__init__(self, '')
 
864
        self.fname = fname
 
865
        self.msg = msg
 
866
 
 
867
 
957
868
class LockFailed(LockError):
958
869
 
959
870
    internal_error = False
1115
1026
        BzrError.__init__(self, branch=branch, revision=revision)
1116
1027
 
1117
1028
 
 
1029
# zero_ninetyone: this exception is no longer raised and should be removed
 
1030
class NotLeftParentDescendant(InternalBzrError):
 
1031
 
 
1032
    _fmt = ("Revision %(old_revision)s is not the left parent of"
 
1033
            " %(new_revision)s, but branch %(branch_location)s expects this")
 
1034
 
 
1035
    def __init__(self, branch, old_revision, new_revision):
 
1036
        BzrError.__init__(self, branch_location=branch.base,
 
1037
                          old_revision=old_revision,
 
1038
                          new_revision=new_revision)
 
1039
 
 
1040
 
1118
1041
class RangeInChangeOption(BzrError):
1119
1042
 
1120
1043
    _fmt = "Option --change does not accept revision ranges"
1246
1169
        self.bases = bases
1247
1170
 
1248
1171
 
1249
 
class NoCommits(BranchError):
 
1172
class NoCommits(BzrError):
1250
1173
 
1251
1174
    _fmt = "Branch %(branch)s has no commits."
1252
1175
 
 
1176
    def __init__(self, branch):
 
1177
        BzrError.__init__(self, branch=branch)
 
1178
 
1253
1179
 
1254
1180
class UnlistableStore(BzrError):
1255
1181
 
1310
1236
 
1311
1237
class WeaveError(BzrError):
1312
1238
 
1313
 
    _fmt = "Error in processing weave: %(msg)s"
 
1239
    _fmt = "Error in processing weave: %(message)s"
1314
1240
 
1315
 
    def __init__(self, msg=None):
 
1241
    def __init__(self, message=None):
1316
1242
        BzrError.__init__(self)
1317
 
        self.msg = msg
 
1243
        self.message = message
1318
1244
 
1319
1245
 
1320
1246
class WeaveRevisionAlreadyPresent(WeaveError):
1426
1352
        self.how = how
1427
1353
 
1428
1354
 
1429
 
class SHA1KnitCorrupt(KnitCorrupt):
1430
 
 
1431
 
    _fmt = ("Knit %(filename)s corrupt: sha-1 of reconstructed text does not "
1432
 
        "match expected sha-1. key %(key)s expected sha %(expected)s actual "
1433
 
        "sha %(actual)s")
1434
 
 
1435
 
    def __init__(self, filename, actual, expected, key, content):
1436
 
        KnitError.__init__(self)
1437
 
        self.filename = filename
1438
 
        self.actual = actual
1439
 
        self.expected = expected
1440
 
        self.key = key
1441
 
        self.content = content
1442
 
 
1443
 
 
1444
1355
class KnitDataStreamIncompatible(KnitError):
1445
1356
    # Not raised anymore, as we can convert data streams.  In future we may
1446
1357
    # need it again for more exotic cases, so we're keeping it around for now.
1485
1396
        self.options = options
1486
1397
 
1487
1398
 
1488
 
class RetryWithNewPacks(BzrError):
1489
 
    """Raised when we realize that the packs on disk have changed.
1490
 
 
1491
 
    This is meant as more of a signaling exception, to trap between where a
1492
 
    local error occurred and the code that can actually handle the error and
1493
 
    code that can retry appropriately.
1494
 
    """
1495
 
 
1496
 
    internal_error = True
1497
 
 
1498
 
    _fmt = ("Pack files have changed, reload and retry. context: %(context)s"
1499
 
            " %(orig_error)s")
1500
 
 
1501
 
    def __init__(self, context, reload_occurred, exc_info):
1502
 
        """create a new RetryWithNewPacks error.
1503
 
 
1504
 
        :param reload_occurred: Set to True if we know that the packs have
1505
 
            already been reloaded, and we are failing because of an in-memory
1506
 
            cache miss. If set to True then we will ignore if a reload says
1507
 
            nothing has changed, because we assume it has already reloaded. If
1508
 
            False, then a reload with nothing changed will force an error.
1509
 
        :param exc_info: The original exception traceback, so if there is a
1510
 
            problem we can raise the original error (value from sys.exc_info())
1511
 
        """
1512
 
        BzrError.__init__(self)
1513
 
        self.reload_occurred = reload_occurred
1514
 
        self.exc_info = exc_info
1515
 
        self.orig_error = exc_info[1]
1516
 
        # TODO: The global error handler should probably treat this by
1517
 
        #       raising/printing the original exception with a bit about
1518
 
        #       RetryWithNewPacks also not being caught
1519
 
 
1520
 
 
1521
 
class RetryAutopack(RetryWithNewPacks):
1522
 
    """Raised when we are autopacking and we find a missing file.
1523
 
 
1524
 
    Meant as a signaling exception, to tell the autopack code it should try
1525
 
    again.
1526
 
    """
1527
 
 
1528
 
    internal_error = True
1529
 
 
1530
 
    _fmt = ("Pack files have changed, reload and try autopack again."
1531
 
            " context: %(context)s %(orig_error)s")
1532
 
 
1533
 
 
1534
1399
class NoSuchExportFormat(BzrError):
1535
1400
    
1536
1401
    _fmt = "Export format %(format)r not supported"
1574
1439
        self.details = details
1575
1440
 
1576
1441
 
1577
 
class UnexpectedProtocolVersionMarker(TransportError):
1578
 
 
1579
 
    _fmt = "Received bad protocol version marker: %(marker)r"
1580
 
 
1581
 
    def __init__(self, marker):
1582
 
        self.marker = marker
1583
 
 
1584
 
 
1585
 
class UnknownSmartMethod(InternalBzrError):
1586
 
 
1587
 
    _fmt = "The server does not recognise the '%(verb)s' request."
1588
 
 
1589
 
    def __init__(self, verb):
1590
 
        self.verb = verb
1591
 
 
1592
 
 
1593
 
class SmartMessageHandlerError(InternalBzrError):
1594
 
 
1595
 
    _fmt = ("The message handler raised an exception:\n"
1596
 
            "%(traceback_text)s")
1597
 
 
1598
 
    def __init__(self, exc_info):
1599
 
        import traceback
1600
 
        self.exc_type, self.exc_value, self.exc_tb = exc_info
1601
 
        self.exc_info = exc_info
1602
 
        traceback_strings = traceback.format_exception(
1603
 
                self.exc_type, self.exc_value, self.exc_tb)
1604
 
        self.traceback_text = ''.join(traceback_strings)
1605
 
 
1606
 
 
1607
1442
# A set of semi-meaningful errors which can be thrown
1608
1443
class TransportNotPossible(TransportError):
1609
1444
 
1680
1515
 
1681
1516
    _fmt = '%(source)s is%(permanently)s redirected to %(target)s'
1682
1517
 
1683
 
    def __init__(self, source, target, is_permanent=False):
 
1518
    def __init__(self, source, target, is_permanent=False, qual_proto=None):
1684
1519
        self.source = source
1685
1520
        self.target = target
1686
1521
        if is_permanent:
1687
1522
            self.permanently = ' permanently'
1688
1523
        else:
1689
1524
            self.permanently = ''
 
1525
        self._qualified_proto = qual_proto
1690
1526
        TransportError.__init__(self)
1691
1527
 
 
1528
    def _requalify_url(self, url):
 
1529
        """Restore the qualified proto in front of the url"""
 
1530
        # When this exception is raised, source and target are in
 
1531
        # user readable format. But some transports may use a
 
1532
        # different proto (http+urllib:// will present http:// to
 
1533
        # the user. If a qualified proto is specified, the code
 
1534
        # trapping the exception can get the qualified urls to
 
1535
        # properly handle the redirection themself (creating a
 
1536
        # new transport object from the target url for example).
 
1537
        # But checking that the scheme of the original and
 
1538
        # redirected urls are the same can be tricky. (see the
 
1539
        # FIXME in BzrDir.open_from_transport for the unique use
 
1540
        # case so far).
 
1541
        if self._qualified_proto is None:
 
1542
            return url
 
1543
 
 
1544
        # The TODO related to NotBranchError mention that doing
 
1545
        # that kind of manipulation on the urls may not be the
 
1546
        # exception object job. On the other hand, this object is
 
1547
        # the interface between the code and the user so
 
1548
        # presenting the urls in different ways is indeed its
 
1549
        # job...
 
1550
        import urlparse
 
1551
        proto, netloc, path, query, fragment = urlparse.urlsplit(url)
 
1552
        return urlparse.urlunsplit((self._qualified_proto, netloc, path,
 
1553
                                   query, fragment))
 
1554
 
 
1555
    def get_source_url(self):
 
1556
        return self._requalify_url(self.source)
 
1557
 
 
1558
    def get_target_url(self):
 
1559
        return self._requalify_url(self.target)
 
1560
 
1692
1561
 
1693
1562
class TooManyRedirections(TransportError):
1694
1563
 
1706
1575
        if filename is None:
1707
1576
            filename = ""
1708
1577
        message = "Error(s) parsing config file %s:\n%s" % \
1709
 
            (filename, ('\n'.join(e.msg for e in errors)))
 
1578
            (filename, ('\n'.join(e.message for e in errors)))
1710
1579
        BzrError.__init__(self, message)
1711
1580
 
1712
1581
 
1897
1766
    _fmt = "Could not move %(from_path)s%(operator)s %(to_path)s%(extra)s"
1898
1767
 
1899
1768
    def __init__(self, from_path='', to_path='', extra=None):
1900
 
        from bzrlib.osutils import splitpath
1901
1769
        BzrError.__init__(self)
1902
1770
        if extra:
1903
1771
            self.extra = ': ' + str(extra)
1907
1775
        has_from = len(from_path) > 0
1908
1776
        has_to = len(to_path) > 0
1909
1777
        if has_from:
1910
 
            self.from_path = splitpath(from_path)[-1]
 
1778
            self.from_path = osutils.splitpath(from_path)[-1]
1911
1779
        else:
1912
1780
            self.from_path = ''
1913
1781
 
1914
1782
        if has_to:
1915
 
            self.to_path = splitpath(to_path)[-1]
 
1783
            self.to_path = osutils.splitpath(to_path)[-1]
1916
1784
        else:
1917
1785
            self.to_path = ''
1918
1786
 
2161
2029
        self.path = path
2162
2030
 
2163
2031
 
2164
 
class RepositoryUpgradeRequired(UpgradeRequired):
2165
 
 
2166
 
    _fmt = "To use this feature you must upgrade your repository at %(path)s."
2167
 
 
2168
 
 
2169
2032
class LocalRequiresBoundBranch(BzrError):
2170
2033
 
2171
2034
    _fmt = "Cannot perform local-only commits on unbound branches."
2172
2035
 
2173
2036
 
 
2037
class MissingProgressBarFinish(BzrError):
 
2038
 
 
2039
    _fmt = "A nested progress bar was not 'finished' correctly."
 
2040
 
 
2041
 
2174
2042
class InvalidProgressBarType(BzrError):
2175
2043
 
2176
2044
    _fmt = ("Environment variable BZR_PROGRESS_BAR='%(bar_type)s"
2310
2178
 
2311
2179
    _fmt = "No smart server available at %(url)s"
2312
2180
 
2313
 
    @symbol_versioning.deprecated_method(symbol_versioning.one_four)
2314
2181
    def __init__(self, url):
2315
2182
        self.url = url
2316
2183
 
2330
2197
            " Please set BZR_SSH environment variable.")
2331
2198
 
2332
2199
 
2333
 
class GhostRevisionsHaveNoRevno(BzrError):
2334
 
    """When searching for revnos, if we encounter a ghost, we are stuck"""
2335
 
 
2336
 
    _fmt = ("Could not determine revno for {%(revision_id)s} because"
2337
 
            " its ancestry shows a ghost at {%(ghost_revision_id)s}")
2338
 
 
2339
 
    def __init__(self, revision_id, ghost_revision_id):
2340
 
        self.revision_id = revision_id
2341
 
        self.ghost_revision_id = ghost_revision_id
2342
 
 
2343
 
        
2344
2200
class GhostRevisionUnusableHere(BzrError):
2345
2201
 
2346
2202
    _fmt = "Ghost revision {%(revision_id)s} cannot be used here."
2424
2280
        self.patch_type = patch_type
2425
2281
 
2426
2282
 
2427
 
class TargetNotBranch(BzrError):
2428
 
    """A merge directive's target branch is required, but isn't a branch"""
2429
 
 
2430
 
    _fmt = ("Your branch does not have all of the revisions required in "
2431
 
            "order to merge this merge directive and the target "
2432
 
            "location specified in the merge directive is not a branch: "
2433
 
            "%(location)s.")
2434
 
 
2435
 
    def __init__(self, location):
2436
 
        BzrError.__init__(self)
2437
 
        self.location = location
2438
 
 
2439
 
 
2440
2283
class UnsupportedInventoryKind(BzrError):
2441
2284
    
2442
2285
    _fmt = """Unsupported entry kind %(kind)s"""
2485
2328
class TagsNotSupported(BzrError):
2486
2329
 
2487
2330
    _fmt = ("Tags not supported by %(branch)s;"
2488
 
            " you may be able to use bzr upgrade.")
 
2331
            " you may be able to use bzr upgrade --dirstate-tags.")
2489
2332
 
2490
2333
    def __init__(self, branch):
2491
2334
        self.branch = branch
2536
2379
        self.response_tuple = response_tuple
2537
2380
 
2538
2381
 
2539
 
class ErrorFromSmartServer(BzrError):
2540
 
    """An error was received from a smart server.
2541
 
 
2542
 
    :seealso: UnknownErrorFromSmartServer
2543
 
    """
2544
 
 
2545
 
    _fmt = "Error received from smart server: %(error_tuple)r"
2546
 
 
2547
 
    internal_error = True
2548
 
 
2549
 
    def __init__(self, error_tuple):
2550
 
        self.error_tuple = error_tuple
2551
 
        try:
2552
 
            self.error_verb = error_tuple[0]
2553
 
        except IndexError:
2554
 
            self.error_verb = None
2555
 
        self.error_args = error_tuple[1:]
2556
 
 
2557
 
 
2558
 
class UnknownErrorFromSmartServer(BzrError):
2559
 
    """An ErrorFromSmartServer could not be translated into a typical bzrlib
2560
 
    error.
2561
 
 
2562
 
    This is distinct from ErrorFromSmartServer so that it is possible to
2563
 
    distinguish between the following two cases:
2564
 
      - ErrorFromSmartServer was uncaught.  This is logic error in the client
2565
 
        and so should provoke a traceback to the user.
2566
 
      - ErrorFromSmartServer was caught but its error_tuple could not be
2567
 
        translated.  This is probably because the server sent us garbage, and
2568
 
        should not provoke a traceback.
2569
 
    """
2570
 
 
2571
 
    _fmt = "Server sent an unexpected error: %(error_tuple)r"
2572
 
 
2573
 
    internal_error = False
2574
 
 
2575
 
    def __init__(self, error_from_smart_server):
2576
 
        """Constructor.
2577
 
 
2578
 
        :param error_from_smart_server: An ErrorFromSmartServer instance.
2579
 
        """
2580
 
        self.error_from_smart_server = error_from_smart_server
2581
 
        self.error_tuple = error_from_smart_server.error_tuple
2582
 
        
2583
 
 
2584
2382
class ContainerError(BzrError):
2585
2383
    """Base class of container errors."""
2586
2384
 
2658
2456
 
2659
2457
class NoMailAddressSpecified(BzrError):
2660
2458
 
2661
 
    _fmt = "No mail-to address (--mail-to) or output (-o) specified."
 
2459
    _fmt = "No mail-to address specified."
2662
2460
 
2663
2461
 
2664
2462
class UnknownMailClient(BzrError):
2702
2500
        BzrError.__init__(self, bzrdir=bzrdir, display_url=display_url)
2703
2501
 
2704
2502
 
2705
 
class UnsyncedBranches(BzrDirError):
2706
 
 
2707
 
    _fmt = ("'%(display_url)s' is not in sync with %(target_url)s.  See"
2708
 
            " bzr help sync-for-reconfigure.")
2709
 
 
2710
 
    def __init__(self, bzrdir, target_branch):
2711
 
        BzrDirError.__init__(self, bzrdir)
2712
 
        import bzrlib.urlutils as urlutils
2713
 
        self.target_url = urlutils.unescape_for_display(target_branch.base,
2714
 
                                                        'ascii')
2715
 
 
2716
 
 
2717
2503
class AlreadyBranch(BzrDirError):
2718
2504
 
2719
2505
    _fmt = "'%(display_url)s' is already a branch."
2734
2520
    _fmt = "'%(display_url)s' is already a lightweight checkout."
2735
2521
 
2736
2522
 
2737
 
class AlreadyUsingShared(BzrDirError):
2738
 
 
2739
 
    _fmt = "'%(display_url)s' is already using a shared repository."
2740
 
 
2741
 
 
2742
 
class AlreadyStandalone(BzrDirError):
2743
 
 
2744
 
    _fmt = "'%(display_url)s' is already standalone."
2745
 
 
2746
 
 
2747
 
class AlreadyWithTrees(BzrDirError):
2748
 
 
2749
 
    _fmt = ("Shared repository '%(display_url)s' already creates "
2750
 
            "working trees.")
2751
 
 
2752
 
 
2753
 
class AlreadyWithNoTrees(BzrDirError):
2754
 
 
2755
 
    _fmt = ("Shared repository '%(display_url)s' already doesn't create "
2756
 
            "working trees.")
2757
 
 
2758
 
 
2759
2523
class ReconfigurationNotSupported(BzrDirError):
2760
2524
 
2761
2525
    _fmt = "Requested reconfiguration of '%(display_url)s' is not supported."
2812
2576
 
2813
2577
    def __init__(self, timezone):
2814
2578
        self.timezone = timezone
2815
 
 
2816
 
 
2817
 
class CommandAvailableInPlugin(StandardError):
2818
 
    
2819
 
    internal_error = False
2820
 
 
2821
 
    def __init__(self, cmd_name, plugin_metadata, provider):
2822
 
        
2823
 
        self.plugin_metadata = plugin_metadata
2824
 
        self.cmd_name = cmd_name
2825
 
        self.provider = provider
2826
 
 
2827
 
    def __str__(self):
2828
 
 
2829
 
        _fmt = ('"%s" is not a standard bzr command. \n' 
2830
 
                'However, the following official plugin provides this command: %s\n'
2831
 
                'You can install it by going to: %s'
2832
 
                % (self.cmd_name, self.plugin_metadata['name'], 
2833
 
                    self.plugin_metadata['url']))
2834
 
 
2835
 
        return _fmt
2836
 
 
2837
 
 
2838
 
class NoPluginAvailable(BzrError):
2839
 
    pass    
2840
 
 
2841
 
 
2842
 
class NotATerminal(BzrError):
2843
 
 
2844
 
    _fmt = 'Unable to ask for a password without real terminal.'
2845
 
 
2846
 
 
2847
 
class UnableEncodePath(BzrError):
2848
 
 
2849
 
    _fmt = ('Unable to encode %(kind)s path %(path)r in '
2850
 
            'user encoding %(user_encoding)s')
2851
 
 
2852
 
    def __init__(self, path, kind):
2853
 
        from bzrlib.osutils import get_user_encoding
2854
 
        self.path = path
2855
 
        self.kind = kind
2856
 
        self.user_encoding = osutils.get_user_encoding()
2857
 
 
2858
 
 
2859
 
class NoSuchAlias(BzrError):
2860
 
 
2861
 
    _fmt = ('The alias "%(alias_name)s" does not exist.')
2862
 
 
2863
 
    def __init__(self, alias_name):
2864
 
        BzrError.__init__(self, alias_name=alias_name)
2865
 
 
2866
 
 
2867
 
class DirectoryLookupFailure(BzrError):
2868
 
    """Base type for lookup errors."""
2869
 
 
2870
 
    pass
2871
 
 
2872
 
 
2873
 
class InvalidLocationAlias(DirectoryLookupFailure):
2874
 
 
2875
 
    _fmt = '"%(alias_name)s" is not a valid location alias.'
2876
 
 
2877
 
    def __init__(self, alias_name):
2878
 
        DirectoryLookupFailure.__init__(self, alias_name=alias_name)
2879
 
 
2880
 
 
2881
 
class UnsetLocationAlias(DirectoryLookupFailure):
2882
 
 
2883
 
    _fmt = 'No %(alias_name)s location assigned.'
2884
 
 
2885
 
    def __init__(self, alias_name):
2886
 
        DirectoryLookupFailure.__init__(self, alias_name=alias_name[1:])
2887
 
 
2888
 
 
2889
 
class CannotBindAddress(BzrError):
2890
 
 
2891
 
    _fmt = 'Cannot bind address "%(host)s:%(port)i": %(orig_error)s.'
2892
 
 
2893
 
    def __init__(self, host, port, orig_error):
2894
 
        BzrError.__init__(self, host=host, port=port,
2895
 
            orig_error=orig_error[1])
2896
 
 
2897
 
 
2898
 
class UnknownRules(BzrError):
2899
 
 
2900
 
    _fmt = ('Unknown rules detected: %(unknowns_str)s.')
2901
 
 
2902
 
    def __init__(self, unknowns):
2903
 
        BzrError.__init__(self, unknowns_str=", ".join(unknowns))
2904
 
 
2905
 
 
2906
 
class HookFailed(BzrError):
2907
 
    """Raised when a pre_change_branch_tip hook function fails anything other
2908
 
    than TipChangeRejected.
2909
 
    """
2910
 
 
2911
 
    _fmt = ("Hook '%(hook_name)s' during %(hook_stage)s failed:\n"
2912
 
            "%(traceback_text)s%(exc_value)s")
2913
 
 
2914
 
    def __init__(self, hook_stage, hook_name, exc_info):
2915
 
        import traceback
2916
 
        self.hook_stage = hook_stage
2917
 
        self.hook_name = hook_name
2918
 
        self.exc_info = exc_info
2919
 
        self.exc_type = exc_info[0]
2920
 
        self.exc_value = exc_info[1]
2921
 
        self.exc_tb = exc_info[2]
2922
 
        self.traceback_text = ''.join(traceback.format_tb(self.exc_tb))
2923
 
 
2924
 
 
2925
 
class TipChangeRejected(BzrError):
2926
 
    """A pre_change_branch_tip hook function may raise this to cleanly and
2927
 
    explicitly abort a change to a branch tip.
2928
 
    """
2929
 
    
2930
 
    _fmt = u"Tip change rejected: %(msg)s"
2931
 
 
2932
 
    def __init__(self, msg):
2933
 
        self.msg = msg
2934
 
 
2935
 
 
2936
 
class ShelfCorrupt(BzrError):
2937
 
 
2938
 
    _fmt = "Shelf corrupt."
2939
 
 
2940
 
 
2941
 
class NoSuchShelfId(BzrError):
2942
 
 
2943
 
    _fmt = 'No changes are shelved with id "%(shelf_id)d".'
2944
 
 
2945
 
    def __init__(self, shelf_id):
2946
 
        BzrError.__init__(self, shelf_id=shelf_id)
2947
 
 
2948
 
 
2949
 
class InvalidShelfId(BzrError):
2950
 
 
2951
 
    _fmt = '"%(invalid_id)s" is not a valid shelf id, try a number instead.'
2952
 
 
2953
 
    def __init__(self, invalid_id):
2954
 
        BzrError.__init__(self, invalid_id=invalid_id)
2955
 
 
2956
 
 
2957
 
class UserAbort(BzrError):
2958
 
 
2959
 
    _fmt = 'The user aborted the operation.'
2960
 
 
2961
 
 
2962
 
class MustHaveWorkingTree(BzrError):
2963
 
 
2964
 
    _fmt = ("Branching '%(url)s'(%(format)s) must create a working tree.")
2965
 
 
2966
 
    def __init__(self, format, url):
2967
 
        BzrError.__init__(self, format=format, url=url)