/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/errors.py

  • Committer: Martin Packman
  • Date: 2011-11-28 17:15:29 UTC
  • mto: This revision was merged to the branch mainline in revision 6328.
  • Revision ID: martin.packman@canonical.com-20111128171529-21crn1k8g8kulk2w
Remove deprecated classes and practices from bzrlib.errors

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005-2010 Canonical Ltd
 
1
# Copyright (C) 2005-2011 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
19
19
 
20
20
from bzrlib import (
21
21
    osutils,
22
 
    symbol_versioning,
23
 
    )
24
 
from bzrlib.patches import (
25
 
    MalformedHunkHeader,
26
 
    MalformedLine,
27
 
    MalformedPatchHeader,
28
 
    PatchConflict,
29
 
    PatchSyntax,
30
 
    )
 
22
    i18n,
 
23
    trace,
 
24
    )
 
25
from bzrlib.i18n import gettext
31
26
 
32
27
 
33
28
# TODO: is there any value in providing the .args field used by standard
54
49
    Base class for errors raised by bzrlib.
55
50
 
56
51
    :cvar internal_error: if True this was probably caused by a bzr bug and
57
 
    should be displayed with a traceback; if False (or absent) this was
58
 
    probably a user or environment error and they don't need the gory details.
59
 
    (That can be overridden by -Derror on the command line.)
 
52
        should be displayed with a traceback; if False (or absent) this was
 
53
        probably a user or environment error and they don't need the gory
 
54
        details.  (That can be overridden by -Derror on the command line.)
60
55
 
61
56
    :cvar _fmt: Format string to display the error; this is expanded
62
 
    by the instance's dict.
 
57
        by the instance's dict.
63
58
    """
64
59
 
65
60
    internal_error = False
140
135
        """Return format string for this exception or None"""
141
136
        fmt = getattr(self, '_fmt', None)
142
137
        if fmt is not None:
143
 
            return fmt
144
 
        fmt = getattr(self, '__doc__', None)
145
 
        if fmt is not None:
146
 
            symbol_versioning.warn("%s uses its docstring as a format, "
147
 
                    "it should use _fmt instead" % self.__class__.__name__,
148
 
                    DeprecationWarning)
149
 
            return fmt
 
138
            i18n.install()
 
139
            unicode_fmt = unicode(fmt) #_fmt strings should be ascii
 
140
            if type(fmt) == unicode:
 
141
                trace.mutter("Unicode strings in error.fmt are deprecated")
 
142
            return gettext(unicode_fmt)
150
143
        return 'Unprintable exception %s: dict=%r, fmt=%r' \
151
144
            % (self.__class__.__name__,
152
145
               self.__dict__,
170
163
    internal_error = True
171
164
 
172
165
 
173
 
class BzrNewError(BzrError):
174
 
    """Deprecated error base class."""
175
 
    # base classes should override the docstring with their human-
176
 
    # readable explanation
177
 
 
178
 
    def __init__(self, *args, **kwds):
179
 
        # XXX: Use the underlying BzrError to always generate the args
180
 
        # attribute if it doesn't exist.  We can't use super here, because
181
 
        # exceptions are old-style classes in python2.4 (but new in 2.5).
182
 
        # --bmc, 20060426
183
 
        symbol_versioning.warn('BzrNewError was deprecated in bzr 0.13; '
184
 
             'please convert %s to use BzrError instead'
185
 
             % self.__class__.__name__,
186
 
             DeprecationWarning,
187
 
             stacklevel=2)
188
 
        BzrError.__init__(self, *args)
189
 
        for key, value in kwds.items():
190
 
            setattr(self, key, value)
191
 
 
192
 
    def __str__(self):
193
 
        try:
194
 
            # __str__() should always return a 'str' object
195
 
            # never a 'unicode' object.
196
 
            s = self.__doc__ % self.__dict__
197
 
            if isinstance(s, unicode):
198
 
                return s.encode('utf8')
199
 
            return s
200
 
        except (TypeError, NameError, ValueError, KeyError), e:
201
 
            return 'Unprintable exception %s(%r): %r' \
202
 
                % (self.__class__.__name__,
203
 
                   self.__dict__, e)
204
 
 
205
 
 
206
166
class AlreadyBuilding(BzrError):
207
167
 
208
168
    _fmt = "The tree builder is already building a tree."
304
264
class RootMissing(InternalBzrError):
305
265
 
306
266
    _fmt = ("The root entry of a tree must be the first entry supplied to "
307
 
        "record_entry_contents.")
 
267
        "the commit builder.")
308
268
 
309
269
 
310
270
class NoPublicBranch(BzrError):
621
581
 
622
582
    _fmt = 'Unsupported protocol for url "%(path)s"%(extra)s'
623
583
 
624
 
    def __init__(self, url, extra):
 
584
    def __init__(self, url, extra=""):
625
585
        PathError.__init__(self, url, extra=extra)
626
586
 
627
587
 
680
640
 
681
641
    _fmt = 'Path "%(path)s" is not a child of path "%(base)s"%(extra)s'
682
642
 
683
 
    internal_error = True
 
643
    internal_error = False
684
644
 
685
645
    def __init__(self, path, base, extra=None):
686
646
        BzrError.__init__(self)
713
673
       self.bzrdir = bzrdir
714
674
       PathError.__init__(self, path=path)
715
675
 
 
676
    def __repr__(self):
 
677
        return '<%s %r>' % (self.__class__.__name__, self.__dict__)
 
678
 
716
679
    def _format(self):
717
680
        # XXX: Ideally self.detail would be a property, but Exceptions in
718
681
        # Python 2.4 have to be old-style classes so properties don't work.
723
686
                    self.bzrdir.open_repository()
724
687
                except NoRepositoryPresent:
725
688
                    self.detail = ''
 
689
                except Exception:
 
690
                    # Just ignore unexpected errors.  Raising arbitrary errors
 
691
                    # during str(err) can provoke strange bugs.  Concretely
 
692
                    # Launchpad's codehosting managed to raise NotBranchError
 
693
                    # here, and then get stuck in an infinite loop/recursion
 
694
                    # trying to str() that error.  All this error really cares
 
695
                    # about that there's no working repository there, and if
 
696
                    # open_repository() fails, there probably isn't.
 
697
                    self.detail = ''
726
698
                else:
727
699
                    self.detail = ': location is a repository'
728
700
            else:
778
750
        self.path = bzrdir.transport.clone('..').base
779
751
 
780
752
 
781
 
class FileInWrongBranch(BzrError):
782
 
 
783
 
    _fmt = 'File "%(path)s" is not in branch %(branch_base)s.'
784
 
 
785
 
    def __init__(self, branch, path):
786
 
        BzrError.__init__(self)
787
 
        self.branch = branch
788
 
        self.branch_base = branch.base
789
 
        self.path = path
790
 
 
791
 
 
792
753
class UnsupportedFormatError(BzrError):
793
754
 
794
755
    _fmt = "Unsupported branch format: %(format)s\nPlease run 'bzr upgrade'"
850
811
        """Construct a new AlreadyVersionedError.
851
812
 
852
813
        :param path: This is the path which is versioned,
853
 
        which should be in a user friendly form.
 
814
            which should be in a user friendly form.
854
815
        :param context_info: If given, this is information about the context,
855
 
        which could explain why this is expected to not be versioned.
 
816
            which could explain why this is expected to not be versioned.
856
817
        """
857
818
        BzrError.__init__(self)
858
819
        self.path = path
871
832
        """Construct a new NotVersionedError.
872
833
 
873
834
        :param path: This is the path which is not versioned,
874
 
        which should be in a user friendly form.
 
835
            which should be in a user friendly form.
875
836
        :param context_info: If given, this is information about the context,
876
 
        which could explain why this is expected to be versioned.
 
837
            which could explain why this is expected to be versioned.
877
838
        """
878
839
        BzrError.__init__(self)
879
840
        self.path = path
947
908
    # original exception is available as e.original_error
948
909
    #
949
910
    # New code should prefer to raise specific subclasses
950
 
    def __init__(self, message):
951
 
        # Python 2.5 uses a slot for StandardError.message,
952
 
        # so use a different variable name.  We now work around this in
953
 
        # BzrError.__str__, but this member name is kept for compatability.
954
 
        self.msg = message
 
911
    def __init__(self, msg):
 
912
        self.msg = msg
955
913
 
956
914
 
957
915
class LockActive(LockError):
1041
999
class LockContention(LockError):
1042
1000
 
1043
1001
    _fmt = 'Could not acquire lock "%(lock)s": %(msg)s'
1044
 
    # TODO: show full url for lock, combining the transport and relative
1045
 
    # bits?
1046
1002
 
1047
1003
    internal_error = False
1048
1004
 
1075
1031
        self.target = target
1076
1032
 
1077
1033
 
 
1034
class LockCorrupt(LockError):
 
1035
 
 
1036
    _fmt = ("Lock is apparently held, but corrupted: %(corruption_info)s\n"
 
1037
            "Use 'bzr break-lock' to clear it")
 
1038
 
 
1039
    internal_error = False
 
1040
 
 
1041
    def __init__(self, corruption_info, file_data=None):
 
1042
        self.corruption_info = corruption_info
 
1043
        self.file_data = file_data
 
1044
 
 
1045
 
1078
1046
class LockNotHeld(LockError):
1079
1047
 
1080
1048
    _fmt = "Lock not held: %(lock)s"
1119
1087
        BzrError.__init__(self, files=files, files_str=files_str)
1120
1088
 
1121
1089
 
 
1090
class ExcludesUnsupported(BzrError):
 
1091
 
 
1092
    _fmt = ('Excluding paths during commit is not supported by '
 
1093
            'repository at %(repository)r.')
 
1094
 
 
1095
    def __init__(self, repository):
 
1096
        BzrError.__init__(self, repository=repository)
 
1097
 
 
1098
 
1122
1099
class BadCommitMessageEncoding(BzrError):
1123
1100
 
1124
1101
    _fmt = 'The specified commit message contains characters unsupported by '\
1180
1157
class InvalidRevisionSpec(BzrError):
1181
1158
 
1182
1159
    _fmt = ("Requested revision: '%(spec)s' does not exist in branch:"
1183
 
            " %(branch)s%(extra)s")
 
1160
            " %(branch_url)s%(extra)s")
1184
1161
 
1185
1162
    def __init__(self, spec, branch, extra=None):
1186
1163
        BzrError.__init__(self, branch=branch, spec=spec)
 
1164
        self.branch_url = getattr(branch, 'user_url', str(branch))
1187
1165
        if extra:
1188
1166
            self.extra = '\n' + str(extra)
1189
1167
        else:
1265
1243
            not_ancestor_id=not_ancestor_id)
1266
1244
 
1267
1245
 
1268
 
class AmbiguousBase(BzrError):
1269
 
 
1270
 
    def __init__(self, bases):
1271
 
        symbol_versioning.warn("BzrError AmbiguousBase has been deprecated "
1272
 
            "as of bzrlib 0.8.", DeprecationWarning, stacklevel=2)
1273
 
        msg = ("The correct base is unclear, because %s are all equally close"
1274
 
                % ", ".join(bases))
1275
 
        BzrError.__init__(self, msg)
1276
 
        self.bases = bases
1277
 
 
1278
 
 
1279
1246
class NoCommits(BranchError):
1280
1247
 
1281
1248
    _fmt = "Branch %(branch)s has no commits."
1380
1347
 
1381
1348
class WeaveParentMismatch(WeaveError):
1382
1349
 
1383
 
    _fmt = "Parents are mismatched between two revisions. %(message)s"
 
1350
    _fmt = "Parents are mismatched between two revisions. %(msg)s"
1384
1351
 
1385
1352
 
1386
1353
class WeaveInvalidChecksum(WeaveError):
1387
1354
 
1388
 
    _fmt = "Text did not match it's checksum: %(message)s"
 
1355
    _fmt = "Text did not match its checksum: %(msg)s"
1389
1356
 
1390
1357
 
1391
1358
class WeaveTextDiffers(WeaveError):
1439
1406
 
1440
1407
class VersionedFileInvalidChecksum(VersionedFileError):
1441
1408
 
1442
 
    _fmt = "Text did not match its checksum: %(message)s"
 
1409
    _fmt = "Text did not match its checksum: %(msg)s"
1443
1410
 
1444
1411
 
1445
1412
class KnitError(InternalBzrError):
1541
1508
            problem we can raise the original error (value from sys.exc_info())
1542
1509
        """
1543
1510
        BzrError.__init__(self)
 
1511
        self.context = context
1544
1512
        self.reload_occurred = reload_occurred
1545
1513
        self.exc_info = exc_info
1546
1514
        self.orig_error = exc_info[1]
1628
1596
 
1629
1597
    def __init__(self, exc_info):
1630
1598
        import traceback
 
1599
        # GZ 2010-08-10: Cycle with exc_tb/exc_info affects at least one test
1631
1600
        self.exc_type, self.exc_value, self.exc_tb = exc_info
1632
1601
        self.exc_info = exc_info
1633
1602
        traceback_strings = traceback.format_exception(
1672
1641
    _fmt = "Connection closed: %(msg)s %(orig_error)s"
1673
1642
 
1674
1643
 
 
1644
class ConnectionTimeout(ConnectionError):
 
1645
 
 
1646
    _fmt = "Connection Timeout: %(msg)s%(orig_error)s"
 
1647
 
 
1648
 
1675
1649
class InvalidRange(TransportError):
1676
1650
 
1677
1651
    _fmt = "Invalid range access in %(path)s at %(offset)s: %(msg)s"
1684
1658
 
1685
1659
class InvalidHttpResponse(TransportError):
1686
1660
 
1687
 
    _fmt = "Invalid http response for %(path)s: %(msg)s"
 
1661
    _fmt = "Invalid http response for %(path)s: %(msg)s%(orig_error)s"
1688
1662
 
1689
1663
    def __init__(self, path, msg, orig_error=None):
1690
1664
        self.path = path
 
1665
        if orig_error is None:
 
1666
            orig_error = ''
 
1667
        else:
 
1668
            # This is reached for obscure and unusual errors so we want to
 
1669
            # preserve as much info as possible to ease debug.
 
1670
            orig_error = ': %r' % (orig_error,)
1691
1671
        TransportError.__init__(self, msg, orig_error=orig_error)
1692
1672
 
1693
1673
 
1700
1680
        InvalidHttpResponse.__init__(self, path, msg)
1701
1681
 
1702
1682
 
 
1683
class HttpBoundaryMissing(InvalidHttpResponse):
 
1684
    """A multipart response ends with no boundary marker.
 
1685
 
 
1686
    This is a special case caused by buggy proxies, described in
 
1687
    <https://bugs.launchpad.net/bzr/+bug/198646>.
 
1688
    """
 
1689
 
 
1690
    _fmt = "HTTP MIME Boundary missing for %(path)s: %(msg)s"
 
1691
 
 
1692
    def __init__(self, path, msg):
 
1693
        InvalidHttpResponse.__init__(self, path, msg)
 
1694
 
 
1695
 
1703
1696
class InvalidHttpContentType(InvalidHttpResponse):
1704
1697
 
1705
1698
    _fmt = 'Invalid http Content-type "%(ctype)s" for %(path)s: %(msg)s'
1733
1726
    _fmt = "Working tree has conflicts."
1734
1727
 
1735
1728
 
 
1729
class ConfigContentError(BzrError):
 
1730
 
 
1731
    _fmt = "Config file %(filename)s is not UTF-8 encoded\n"
 
1732
 
 
1733
    def __init__(self, filename):
 
1734
        BzrError.__init__(self)
 
1735
        self.filename = filename
 
1736
 
 
1737
 
1736
1738
class ParseConfigError(BzrError):
1737
1739
 
 
1740
    _fmt = "Error(s) parsing config file %(filename)s:\n%(errors)s"
 
1741
 
1738
1742
    def __init__(self, errors, filename):
1739
 
        if filename is None:
1740
 
            filename = ""
1741
 
        message = "Error(s) parsing config file %s:\n%s" % \
1742
 
            (filename, ('\n'.join(e.msg for e in errors)))
1743
 
        BzrError.__init__(self, message)
 
1743
        BzrError.__init__(self)
 
1744
        self.filename = filename
 
1745
        self.errors = '\n'.join(e.msg for e in errors)
 
1746
 
 
1747
 
 
1748
class ConfigOptionValueError(BzrError):
 
1749
 
 
1750
    _fmt = """Bad value "%(value)s" for option "%(name)s"."""
 
1751
 
 
1752
    def __init__(self, name, value):
 
1753
        BzrError.__init__(self, name=name, value=value)
1744
1754
 
1745
1755
 
1746
1756
class NoEmailInUsername(BzrError):
1754
1764
 
1755
1765
class SigningFailed(BzrError):
1756
1766
 
1757
 
    _fmt = 'Failed to gpg sign data with command "%(command_line)s"'
 
1767
    _fmt = 'Failed to GPG sign data with command "%(command_line)s"'
1758
1768
 
1759
1769
    def __init__(self, command_line):
1760
1770
        BzrError.__init__(self, command_line=command_line)
1761
1771
 
1762
1772
 
 
1773
class SignatureVerificationFailed(BzrError):
 
1774
 
 
1775
    _fmt = 'Failed to verify GPG signature data with error "%(error)s"'
 
1776
 
 
1777
    def __init__(self, error):
 
1778
        BzrError.__init__(self, error=error)
 
1779
 
 
1780
 
 
1781
class DependencyNotPresent(BzrError):
 
1782
 
 
1783
    _fmt = 'Unable to import library "%(library)s": %(error)s'
 
1784
 
 
1785
    def __init__(self, library, error):
 
1786
        BzrError.__init__(self, library=library, error=error)
 
1787
 
 
1788
 
 
1789
class GpgmeNotInstalled(DependencyNotPresent):
 
1790
 
 
1791
    _fmt = 'python-gpgme is not installed, it is needed to verify signatures'
 
1792
 
 
1793
    def __init__(self, error):
 
1794
        DependencyNotPresent.__init__(self, 'gpgme', error)
 
1795
 
 
1796
 
1763
1797
class WorkingTreeNotRevision(BzrError):
1764
1798
 
1765
1799
    _fmt = ("The working tree for %(basedir)s has changed since"
1881
1915
        self.prefix = prefix
1882
1916
 
1883
1917
 
1884
 
class MalformedTransform(BzrError):
 
1918
class MalformedTransform(InternalBzrError):
1885
1919
 
1886
1920
    _fmt = "Tree transform is malformed %(conflicts)r"
1887
1921
 
1925
1959
    _fmt = "Moving the root directory is not supported at this time"
1926
1960
 
1927
1961
 
 
1962
class TransformRenameFailed(BzrError):
 
1963
 
 
1964
    _fmt = "Failed to rename %(from_path)s to %(to_path)s: %(why)s"
 
1965
 
 
1966
    def __init__(self, from_path, to_path, why, errno):
 
1967
        self.from_path = from_path
 
1968
        self.to_path = to_path
 
1969
        self.why = why
 
1970
        self.errno = errno
 
1971
 
 
1972
 
1928
1973
class BzrMoveFailedError(BzrError):
1929
1974
 
1930
 
    _fmt = "Could not move %(from_path)s%(operator)s %(to_path)s%(extra)s"
 
1975
    _fmt = ("Could not move %(from_path)s%(operator)s %(to_path)s"
 
1976
        "%(_has_extra)s%(extra)s")
1931
1977
 
1932
1978
    def __init__(self, from_path='', to_path='', extra=None):
1933
1979
        from bzrlib.osutils import splitpath
1934
1980
        BzrError.__init__(self)
1935
1981
        if extra:
1936
 
            self.extra = ': ' + str(extra)
 
1982
            self.extra, self._has_extra = extra, ': '
1937
1983
        else:
1938
 
            self.extra = ''
 
1984
            self.extra = self._has_extra = ''
1939
1985
 
1940
1986
        has_from = len(from_path) > 0
1941
1987
        has_to = len(to_path) > 0
1962
2008
 
1963
2009
class BzrRenameFailedError(BzrMoveFailedError):
1964
2010
 
1965
 
    _fmt = "Could not rename %(from_path)s%(operator)s %(to_path)s%(extra)s"
 
2011
    _fmt = ("Could not rename %(from_path)s%(operator)s %(to_path)s"
 
2012
        "%(_has_extra)s%(extra)s")
1966
2013
 
1967
2014
    def __init__(self, from_path, to_path, extra=None):
1968
2015
        BzrMoveFailedError.__init__(self, from_path, to_path, extra)
1969
2016
 
1970
 
class BzrRemoveChangedFilesError(BzrError):
1971
 
    """Used when user is trying to remove changed files."""
1972
 
 
1973
 
    _fmt = ("Can't safely remove modified or unknown files:\n"
1974
 
        "%(changes_as_text)s"
1975
 
        "Use --keep to not delete them, or --force to delete them regardless.")
1976
 
 
1977
 
    def __init__(self, tree_delta):
1978
 
        BzrError.__init__(self)
1979
 
        self.changes_as_text = tree_delta.get_changes_as_text()
1980
 
        #self.paths_as_string = '\n'.join(changed_files)
1981
 
        #self.paths_as_string = '\n'.join([quotefn(p) for p in changed_files])
1982
 
 
1983
2017
 
1984
2018
class BzrBadParameterNotString(BzrBadParameter):
1985
2019
 
1988
2022
 
1989
2023
class BzrBadParameterMissing(BzrBadParameter):
1990
2024
 
1991
 
    _fmt = "Parameter $(param)s is required but not present."
 
2025
    _fmt = "Parameter %(param)s is required but not present."
1992
2026
 
1993
2027
 
1994
2028
class BzrBadParameterUnicode(BzrBadParameter):
2002
2036
    _fmt = "Parameter %(param)s contains a newline."
2003
2037
 
2004
2038
 
2005
 
class DependencyNotPresent(BzrError):
2006
 
 
2007
 
    _fmt = 'Unable to import library "%(library)s": %(error)s'
2008
 
 
2009
 
    def __init__(self, library, error):
2010
 
        BzrError.__init__(self, library=library, error=error)
2011
 
 
2012
 
 
2013
2039
class ParamikoNotPresent(DependencyNotPresent):
2014
2040
 
2015
2041
    _fmt = "Unable to import paramiko (required for sftp support): %(error)s"
2250
2276
    """
2251
2277
 
2252
2278
 
 
2279
class GhostTagsNotSupported(BzrError):
 
2280
 
 
2281
    _fmt = "Ghost tags not supported by format %(format)r."
 
2282
 
 
2283
    def __init__(self, format):
 
2284
        self.format = format
 
2285
 
 
2286
 
2253
2287
class BinaryFile(BzrError):
2254
2288
 
2255
2289
    _fmt = "File is binary but should be text."
2618
2652
 
2619
2653
    This is distinct from ErrorFromSmartServer so that it is possible to
2620
2654
    distinguish between the following two cases:
2621
 
      - ErrorFromSmartServer was uncaught.  This is logic error in the client
2622
 
        and so should provoke a traceback to the user.
2623
 
      - ErrorFromSmartServer was caught but its error_tuple could not be
2624
 
        translated.  This is probably because the server sent us garbage, and
2625
 
        should not provoke a traceback.
 
2655
 
 
2656
    - ErrorFromSmartServer was uncaught.  This is logic error in the client
 
2657
      and so should provoke a traceback to the user.
 
2658
    - ErrorFromSmartServer was caught but its error_tuple could not be
 
2659
      translated.  This is probably because the server sent us garbage, and
 
2660
      should not provoke a traceback.
2626
2661
    """
2627
2662
 
2628
2663
    _fmt = "Server sent an unexpected error: %(error_tuple)r"
2684
2719
    _fmt = "Container has multiple records with the same name: %(name)s"
2685
2720
 
2686
2721
    def __init__(self, name):
2687
 
        self.name = name
 
2722
        self.name = name.decode("utf-8")
2688
2723
 
2689
2724
 
2690
2725
class NoDestinationAddress(InternalBzrError):
2834
2869
        else:
2835
2870
            more = ' ' + more
2836
2871
        import bzrlib.urlutils as urlutils
2837
 
        display_url = urlutils.unescape_for_display(
2838
 
            tree.user_url, 'ascii')
 
2872
        user_url = getattr(tree, "user_url", None)
 
2873
        if user_url is None:
 
2874
            display_url = str(tree)
 
2875
        else:
 
2876
            display_url = urlutils.unescape_for_display(user_url, 'ascii')
2839
2877
        BzrError.__init__(self, tree=tree, display_url=display_url, more=more)
2840
2878
 
2841
2879
 
 
2880
class ShelvedChanges(UncommittedChanges):
 
2881
 
 
2882
    _fmt = ('Working tree "%(display_url)s" has shelved changes'
 
2883
            ' (See bzr shelve --list).%(more)s')
 
2884
 
 
2885
 
2842
2886
class MissingTemplateVariable(BzrError):
2843
2887
 
2844
2888
    _fmt = 'Variable {%(name)s} is not available.'
2913
2957
        self.user_encoding = osutils.get_user_encoding()
2914
2958
 
2915
2959
 
 
2960
class NoSuchConfig(BzrError):
 
2961
 
 
2962
    _fmt = ('The "%(config_id)s" configuration does not exist.')
 
2963
 
 
2964
    def __init__(self, config_id):
 
2965
        BzrError.__init__(self, config_id=config_id)
 
2966
 
 
2967
 
 
2968
class NoSuchConfigOption(BzrError):
 
2969
 
 
2970
    _fmt = ('The "%(option_name)s" configuration option does not exist.')
 
2971
 
 
2972
    def __init__(self, option_name):
 
2973
        BzrError.__init__(self, option_name=option_name)
 
2974
 
 
2975
 
2916
2976
class NoSuchAlias(BzrError):
2917
2977
 
2918
2978
    _fmt = ('The alias "%(alias_name)s" does not exist.')
2961
3021
        BzrError.__init__(self, unknowns_str=", ".join(unknowns))
2962
3022
 
2963
3023
 
2964
 
class HookFailed(BzrError):
2965
 
    """Raised when a pre_change_branch_tip hook function fails anything other
2966
 
    than TipChangeRejected.
2967
 
 
2968
 
    Note that this exception is no longer raised, and the import is only left
2969
 
    to be nice to code which might catch it in a plugin.
2970
 
    """
2971
 
 
2972
 
    _fmt = ("Hook '%(hook_name)s' during %(hook_stage)s failed:\n"
2973
 
            "%(traceback_text)s%(exc_value)s")
2974
 
 
2975
 
    def __init__(self, hook_stage, hook_name, exc_info, warn=True):
2976
 
        if warn:
2977
 
            symbol_versioning.warn("BzrError HookFailed has been deprecated "
2978
 
                "as of bzrlib 2.1.", DeprecationWarning, stacklevel=2)
2979
 
        import traceback
2980
 
        self.hook_stage = hook_stage
2981
 
        self.hook_name = hook_name
2982
 
        self.exc_info = exc_info
2983
 
        self.exc_type = exc_info[0]
2984
 
        self.exc_value = exc_info[1]
2985
 
        self.exc_tb = exc_info[2]
2986
 
        self.traceback_text = ''.join(traceback.format_tb(self.exc_tb))
2987
 
 
2988
 
 
2989
3024
class TipChangeRejected(BzrError):
2990
3025
    """A pre_change_branch_tip hook function may raise this to cleanly and
2991
3026
    explicitly abort a change to a branch tip.
3002
3037
    _fmt = "Shelf corrupt."
3003
3038
 
3004
3039
 
 
3040
class DecompressCorruption(BzrError):
 
3041
 
 
3042
    _fmt = "Corruption while decompressing repository file%(orig_error)s"
 
3043
 
 
3044
    def __init__(self, orig_error=None):
 
3045
        if orig_error is not None:
 
3046
            self.orig_error = ", %s" % (orig_error,)
 
3047
        else:
 
3048
            self.orig_error = ""
 
3049
        BzrError.__init__(self)
 
3050
 
 
3051
 
3005
3052
class NoSuchShelfId(BzrError):
3006
3053
 
3007
3054
    _fmt = 'No changes are shelved with id "%(shelf_id)d".'
3134
3181
    def __init__(self, bzrdir):
3135
3182
        self.bzrdir = bzrdir
3136
3183
 
 
3184
 
 
3185
class NoWhoami(BzrError):
 
3186
 
 
3187
    _fmt = ('Unable to determine your name.\n'
 
3188
        "Please, set your name with the 'whoami' command.\n"
 
3189
        'E.g. bzr whoami "Your Name <name@example.com>"')
 
3190
 
 
3191
 
 
3192
class InvalidPattern(BzrError):
 
3193
 
 
3194
    _fmt = ('Invalid pattern(s) found. %(msg)s')
 
3195
 
 
3196
    def __init__(self, msg):
 
3197
        self.msg = msg
 
3198
 
 
3199
 
 
3200
class RecursiveBind(BzrError):
 
3201
 
 
3202
    _fmt = ('Branch "%(branch_url)s" appears to be bound to itself. '
 
3203
        'Please use `bzr unbind` to fix.')
 
3204
 
 
3205
    def __init__(self, branch_url):
 
3206
        self.branch_url = branch_url
 
3207
 
 
3208
 
 
3209
# FIXME: I would prefer to define the config related exception classes in
 
3210
# config.py but the lazy import mechanism proscribes this -- vila 20101222
 
3211
class OptionExpansionLoop(BzrError):
 
3212
 
 
3213
    _fmt = 'Loop involving %(refs)r while expanding "%(string)s".'
 
3214
 
 
3215
    def __init__(self, string, refs):
 
3216
        self.string = string
 
3217
        self.refs = '->'.join(refs)
 
3218
 
 
3219
 
 
3220
class ExpandingUnknownOption(BzrError):
 
3221
 
 
3222
    _fmt = 'Option %(name)s is not defined while expanding "%(string)s".'
 
3223
 
 
3224
    def __init__(self, name, string):
 
3225
        self.name = name
 
3226
        self.string = string
 
3227
 
 
3228
 
 
3229
class NoCompatibleInter(BzrError):
 
3230
 
 
3231
    _fmt = ('No compatible object available for operations from %(source)r '
 
3232
            'to %(target)r.')
 
3233
 
 
3234
    def __init__(self, source, target):
 
3235
        self.source = source
 
3236
        self.target = target
 
3237
 
 
3238
 
 
3239
class HpssVfsRequestNotAllowed(BzrError):
 
3240
 
 
3241
    _fmt = ("VFS requests over the smart server are not allowed. Encountered: "
 
3242
            "%(method)s, %(arguments)s.")
 
3243
 
 
3244
    def __init__(self, method, arguments):
 
3245
        self.method = method
 
3246
        self.arguments = arguments
 
3247
 
 
3248
 
 
3249
class UnsupportedKindChange(BzrError):
 
3250
 
 
3251
    _fmt = ("Kind change from %(from_kind)s to %(to_kind)s for "
 
3252
            "%(path)s not supported by format %(format)r")
 
3253
 
 
3254
    def __init__(self, path, from_kind, to_kind, format):
 
3255
        self.path = path
 
3256
        self.from_kind = from_kind
 
3257
        self.to_kind = to_kind
 
3258
        self.format = format
 
3259
 
 
3260
 
 
3261
class PatchSyntax(BzrError):
 
3262
    """Base class for patch syntax errors."""
 
3263
 
 
3264
 
 
3265
class BinaryFiles(BzrError):
 
3266
 
 
3267
    _fmt = 'Binary files section encountered.'
 
3268
 
 
3269
    def __init__(self, orig_name, mod_name):
 
3270
        self.orig_name = orig_name
 
3271
        self.mod_name = mod_name
 
3272
 
 
3273
 
 
3274
class MalformedPatchHeader(PatchSyntax):
 
3275
 
 
3276
    _fmt = "Malformed patch header.  %(desc)s\n%(line)r"
 
3277
 
 
3278
    def __init__(self, desc, line):
 
3279
        self.desc = desc
 
3280
        self.line = line
 
3281
 
 
3282
 
 
3283
class MalformedHunkHeader(PatchSyntax):
 
3284
 
 
3285
    _fmt = "Malformed hunk header.  %(desc)s\n%(line)r"
 
3286
 
 
3287
    def __init__(self, desc, line):
 
3288
        self.desc = desc
 
3289
        self.line = line
 
3290
 
 
3291
 
 
3292
class MalformedLine(PatchSyntax):
 
3293
 
 
3294
    _fmt = "Malformed line.  %(desc)s\n%(line)r"
 
3295
 
 
3296
    def __init__(self, desc, line):
 
3297
        self.desc = desc
 
3298
        self.line = line
 
3299
 
 
3300
 
 
3301
class PatchConflict(BzrError):
 
3302
 
 
3303
    _fmt = ('Text contents mismatch at line %(line_no)d.  Original has '
 
3304
            '"%(orig_line)s", but patch says it should be "%(patch_line)s"')
 
3305
 
 
3306
    def __init__(self, line_no, orig_line, patch_line):
 
3307
        self.line_no = line_no
 
3308
        self.orig_line = orig_line.rstrip('\n')
 
3309
        self.patch_line = patch_line.rstrip('\n')