~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/errors.py

  • Committer: Jelmer Vernooij
  • Date: 2011-05-02 20:35:22 UTC
  • mto: This revision was merged to the branch mainline in revision 5844.
  • Revision ID: jelmer@samba.org-20110502203522-lwa7pxbsckfzalal
Use MetaDirVersionedFileRepositoryFormat (a Soyuz worthy name).

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
from bzrlib import (
21
21
    osutils,
22
22
    symbol_versioning,
23
 
    i18n,
24
 
    trace,
25
 
    )
26
 
from bzrlib.i18n import gettext
 
23
    )
 
24
from bzrlib.patches import (
 
25
    MalformedHunkHeader,
 
26
    MalformedLine,
 
27
    MalformedPatchHeader,
 
28
    PatchConflict,
 
29
    PatchSyntax,
 
30
    )
27
31
 
28
32
 
29
33
# TODO: is there any value in providing the .args field used by standard
50
54
    Base class for errors raised by bzrlib.
51
55
 
52
56
    :cvar internal_error: if True this was probably caused by a bzr bug and
53
 
        should be displayed with a traceback; if False (or absent) this was
54
 
        probably a user or environment error and they don't need the gory
55
 
        details.  (That can be overridden by -Derror on the command line.)
 
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.)
56
60
 
57
61
    :cvar _fmt: Format string to display the error; this is expanded
58
 
        by the instance's dict.
 
62
    by the instance's dict.
59
63
    """
60
64
 
61
65
    internal_error = False
136
140
        """Return format string for this exception or None"""
137
141
        fmt = getattr(self, '_fmt', None)
138
142
        if fmt is not None:
139
 
            i18n.install()
140
 
            unicode_fmt = unicode(fmt) #_fmt strings should be ascii
141
 
            if type(fmt) == unicode:
142
 
                trace.mutter("Unicode strings in error.fmt are deprecated")
143
 
            return gettext(unicode_fmt)
 
143
            return fmt
144
144
        fmt = getattr(self, '__doc__', None)
145
145
        if fmt is not None:
146
146
            symbol_versioning.warn("%s uses its docstring as a format, "
304
304
class RootMissing(InternalBzrError):
305
305
 
306
306
    _fmt = ("The root entry of a tree must be the first entry supplied to "
307
 
        "the commit builder.")
 
307
        "record_entry_contents.")
308
308
 
309
309
 
310
310
class NoPublicBranch(BzrError):
621
621
 
622
622
    _fmt = 'Unsupported protocol for url "%(path)s"%(extra)s'
623
623
 
624
 
    def __init__(self, url, extra=""):
 
624
    def __init__(self, url, extra):
625
625
        PathError.__init__(self, url, extra=extra)
626
626
 
627
627
 
864
864
        """Construct a new AlreadyVersionedError.
865
865
 
866
866
        :param path: This is the path which is versioned,
867
 
            which should be in a user friendly form.
 
867
        which should be in a user friendly form.
868
868
        :param context_info: If given, this is information about the context,
869
 
            which could explain why this is expected to not be versioned.
 
869
        which could explain why this is expected to not be versioned.
870
870
        """
871
871
        BzrError.__init__(self)
872
872
        self.path = path
885
885
        """Construct a new NotVersionedError.
886
886
 
887
887
        :param path: This is the path which is not versioned,
888
 
            which should be in a user friendly form.
 
888
        which should be in a user friendly form.
889
889
        :param context_info: If given, this is information about the context,
890
 
            which could explain why this is expected to be versioned.
 
890
        which could explain why this is expected to be versioned.
891
891
        """
892
892
        BzrError.__init__(self)
893
893
        self.path = path
1572
1572
            problem we can raise the original error (value from sys.exc_info())
1573
1573
        """
1574
1574
        BzrError.__init__(self)
1575
 
        self.context = context
1576
1575
        self.reload_occurred = reload_occurred
1577
1576
        self.exc_info = exc_info
1578
1577
        self.orig_error = exc_info[1]
1660
1659
 
1661
1660
    def __init__(self, exc_info):
1662
1661
        import traceback
1663
 
        # GZ 2010-08-10: Cycle with exc_tb/exc_info affects at least one test
1664
1662
        self.exc_type, self.exc_value, self.exc_tb = exc_info
1665
1663
        self.exc_info = exc_info
1666
1664
        traceback_strings = traceback.format_exception(
1705
1703
    _fmt = "Connection closed: %(msg)s %(orig_error)s"
1706
1704
 
1707
1705
 
1708
 
class ConnectionTimeout(ConnectionError):
1709
 
 
1710
 
    _fmt = "Connection Timeout: %(msg)s%(orig_error)s"
1711
 
 
1712
 
 
1713
1706
class InvalidRange(TransportError):
1714
1707
 
1715
1708
    _fmt = "Invalid range access in %(path)s at %(offset)s: %(msg)s"
1722
1715
 
1723
1716
class InvalidHttpResponse(TransportError):
1724
1717
 
1725
 
    _fmt = "Invalid http response for %(path)s: %(msg)s%(orig_error)s"
 
1718
    _fmt = "Invalid http response for %(path)s: %(msg)s"
1726
1719
 
1727
1720
    def __init__(self, path, msg, orig_error=None):
1728
1721
        self.path = path
1729
 
        if orig_error is None:
1730
 
            orig_error = ''
1731
 
        else:
1732
 
            # This is reached for obscure and unusual errors so we want to
1733
 
            # preserve as much info as possible to ease debug.
1734
 
            orig_error = ': %r' % (orig_error,)
1735
1722
        TransportError.__init__(self, msg, orig_error=orig_error)
1736
1723
 
1737
1724
 
1744
1731
        InvalidHttpResponse.__init__(self, path, msg)
1745
1732
 
1746
1733
 
1747
 
class HttpBoundaryMissing(InvalidHttpResponse):
1748
 
    """A multipart response ends with no boundary marker.
1749
 
 
1750
 
    This is a special case caused by buggy proxies, described in
1751
 
    <https://bugs.launchpad.net/bzr/+bug/198646>.
1752
 
    """
1753
 
 
1754
 
    _fmt = "HTTP MIME Boundary missing for %(path)s: %(msg)s"
1755
 
 
1756
 
    def __init__(self, path, msg):
1757
 
        InvalidHttpResponse.__init__(self, path, msg)
1758
 
 
1759
 
 
1760
1734
class InvalidHttpContentType(InvalidHttpResponse):
1761
1735
 
1762
1736
    _fmt = 'Invalid http Content-type "%(ctype)s" for %(path)s: %(msg)s'
1790
1764
    _fmt = "Working tree has conflicts."
1791
1765
 
1792
1766
 
1793
 
class ConfigContentError(BzrError):
1794
 
 
1795
 
    _fmt = "Config file %(filename)s is not UTF-8 encoded\n"
1796
 
 
1797
 
    def __init__(self, filename):
1798
 
        BzrError.__init__(self)
1799
 
        self.filename = filename
1800
 
 
1801
 
 
1802
1767
class ParseConfigError(BzrError):
1803
1768
 
1804
 
    _fmt = "Error(s) parsing config file %(filename)s:\n%(errors)s"
1805
 
 
1806
1769
    def __init__(self, errors, filename):
1807
 
        BzrError.__init__(self)
1808
 
        self.filename = filename
1809
 
        self.errors = '\n'.join(e.msg for e in errors)
1810
 
 
1811
 
 
1812
 
class ConfigOptionValueError(BzrError):
1813
 
 
1814
 
    _fmt = """Bad value "%(value)s" for option "%(name)s"."""
1815
 
 
1816
 
    def __init__(self, name, value):
1817
 
        BzrError.__init__(self, name=name, value=value)
 
1770
        if filename is None:
 
1771
            filename = ""
 
1772
        message = "Error(s) parsing config file %s:\n%s" % \
 
1773
            (filename, ('\n'.join(e.msg for e in errors)))
 
1774
        BzrError.__init__(self, message)
1818
1775
 
1819
1776
 
1820
1777
class NoEmailInUsername(BzrError):
1828
1785
 
1829
1786
class SigningFailed(BzrError):
1830
1787
 
1831
 
    _fmt = 'Failed to GPG sign data with command "%(command_line)s"'
 
1788
    _fmt = 'Failed to gpg sign data with command "%(command_line)s"'
1832
1789
 
1833
1790
    def __init__(self, command_line):
1834
1791
        BzrError.__init__(self, command_line=command_line)
1835
1792
 
1836
1793
 
1837
 
class SignatureVerificationFailed(BzrError):
1838
 
 
1839
 
    _fmt = 'Failed to verify GPG signature data with error "%(error)s"'
1840
 
 
1841
 
    def __init__(self, error):
1842
 
        BzrError.__init__(self, error=error)
1843
 
 
1844
 
 
1845
 
class DependencyNotPresent(BzrError):
1846
 
 
1847
 
    _fmt = 'Unable to import library "%(library)s": %(error)s'
1848
 
 
1849
 
    def __init__(self, library, error):
1850
 
        BzrError.__init__(self, library=library, error=error)
1851
 
 
1852
 
 
1853
 
class GpgmeNotInstalled(DependencyNotPresent):
1854
 
 
1855
 
    _fmt = 'python-gpgme is not installed, it is needed to verify signatures'
1856
 
 
1857
 
    def __init__(self, error):
1858
 
        DependencyNotPresent.__init__(self, 'gpgme', error)
1859
 
 
1860
 
 
1861
1794
class WorkingTreeNotRevision(BzrError):
1862
1795
 
1863
1796
    _fmt = ("The working tree for %(basedir)s has changed since"
1979
1912
        self.prefix = prefix
1980
1913
 
1981
1914
 
1982
 
class MalformedTransform(InternalBzrError):
 
1915
class MalformedTransform(BzrError):
1983
1916
 
1984
1917
    _fmt = "Tree transform is malformed %(conflicts)r"
1985
1918
 
2116
2049
    _fmt = "Parameter %(param)s contains a newline."
2117
2050
 
2118
2051
 
 
2052
class DependencyNotPresent(BzrError):
 
2053
 
 
2054
    _fmt = 'Unable to import library "%(library)s": %(error)s'
 
2055
 
 
2056
    def __init__(self, library, error):
 
2057
        BzrError.__init__(self, library=library, error=error)
 
2058
 
 
2059
 
2119
2060
class ParamikoNotPresent(DependencyNotPresent):
2120
2061
 
2121
2062
    _fmt = "Unable to import paramiko (required for sftp support): %(error)s"
2356
2297
    """
2357
2298
 
2358
2299
 
2359
 
class GhostTagsNotSupported(BzrError):
2360
 
 
2361
 
    _fmt = "Ghost tags not supported by format %(format)r."
2362
 
 
2363
 
    def __init__(self, format):
2364
 
        self.format = format
2365
 
 
2366
 
 
2367
2300
class BinaryFile(BzrError):
2368
2301
 
2369
2302
    _fmt = "File is binary but should be text."
2732
2665
 
2733
2666
    This is distinct from ErrorFromSmartServer so that it is possible to
2734
2667
    distinguish between the following two cases:
2735
 
 
2736
 
    - ErrorFromSmartServer was uncaught.  This is logic error in the client
2737
 
      and so should provoke a traceback to the user.
2738
 
    - ErrorFromSmartServer was caught but its error_tuple could not be
2739
 
      translated.  This is probably because the server sent us garbage, and
2740
 
      should not provoke a traceback.
 
2668
      - ErrorFromSmartServer was uncaught.  This is logic error in the client
 
2669
        and so should provoke a traceback to the user.
 
2670
      - ErrorFromSmartServer was caught but its error_tuple could not be
 
2671
        translated.  This is probably because the server sent us garbage, and
 
2672
        should not provoke a traceback.
2741
2673
    """
2742
2674
 
2743
2675
    _fmt = "Server sent an unexpected error: %(error_tuple)r"
2799
2731
    _fmt = "Container has multiple records with the same name: %(name)s"
2800
2732
 
2801
2733
    def __init__(self, name):
2802
 
        self.name = name.decode("utf-8")
 
2734
        self.name = name
2803
2735
 
2804
2736
 
2805
2737
class NoDestinationAddress(InternalBzrError):
3142
3074
    _fmt = "Shelf corrupt."
3143
3075
 
3144
3076
 
3145
 
class DecompressCorruption(BzrError):
3146
 
 
3147
 
    _fmt = "Corruption while decompressing repository file%(orig_error)s"
3148
 
 
3149
 
    def __init__(self, orig_error=None):
3150
 
        if orig_error is not None:
3151
 
            self.orig_error = ", %s" % (orig_error,)
3152
 
        else:
3153
 
            self.orig_error = ""
3154
 
        BzrError.__init__(self)
3155
 
 
3156
 
 
3157
3077
class NoSuchShelfId(BzrError):
3158
3078
 
3159
3079
    _fmt = 'No changes are shelved with id "%(shelf_id)d".'
3329
3249
    def __init__(self, name, string):
3330
3250
        self.name = name
3331
3251
        self.string = string
3332
 
 
3333
 
 
3334
 
class NoCompatibleInter(BzrError):
3335
 
 
3336
 
    _fmt = ('No compatible object available for operations from %(source)r '
3337
 
            'to %(target)r.')
3338
 
 
3339
 
    def __init__(self, source, target):
3340
 
        self.source = source
3341
 
        self.target = target
3342
 
 
3343
 
 
3344
 
class HpssVfsRequestNotAllowed(BzrError):
3345
 
 
3346
 
    _fmt = ("VFS requests over the smart server are not allowed. Encountered: "
3347
 
            "%(method)s, %(arguments)s.")
3348
 
 
3349
 
    def __init__(self, method, arguments):
3350
 
        self.method = method
3351
 
        self.arguments = arguments
3352
 
 
3353
 
 
3354
 
class UnsupportedKindChange(BzrError):
3355
 
 
3356
 
    _fmt = ("Kind change from %(from_kind)s to %(to_kind)s for "
3357
 
            "%(path)s not supported by format %(format)r")
3358
 
 
3359
 
    def __init__(self, path, from_kind, to_kind, format):
3360
 
        self.path = path
3361
 
        self.from_kind = from_kind
3362
 
        self.to_kind = to_kind
3363
 
        self.format = format
3364
 
 
3365
 
 
3366
 
class PatchSyntax(BzrError):
3367
 
    """Base class for patch syntax errors."""
3368
 
 
3369
 
 
3370
 
class BinaryFiles(BzrError):
3371
 
 
3372
 
    _fmt = 'Binary files section encountered.'
3373
 
 
3374
 
    def __init__(self, orig_name, mod_name):
3375
 
        self.orig_name = orig_name
3376
 
        self.mod_name = mod_name
3377
 
 
3378
 
 
3379
 
class MalformedPatchHeader(PatchSyntax):
3380
 
 
3381
 
    _fmt = "Malformed patch header.  %(desc)s\n%(line)r"
3382
 
 
3383
 
    def __init__(self, desc, line):
3384
 
        self.desc = desc
3385
 
        self.line = line
3386
 
 
3387
 
 
3388
 
class MalformedHunkHeader(PatchSyntax):
3389
 
 
3390
 
    _fmt = "Malformed hunk header.  %(desc)s\n%(line)r"
3391
 
 
3392
 
    def __init__(self, desc, line):
3393
 
        self.desc = desc
3394
 
        self.line = line
3395
 
 
3396
 
 
3397
 
class MalformedLine(PatchSyntax):
3398
 
 
3399
 
    _fmt = "Malformed line.  %(desc)s\n%(line)r"
3400
 
 
3401
 
    def __init__(self, desc, line):
3402
 
        self.desc = desc
3403
 
        self.line = line
3404
 
 
3405
 
 
3406
 
class PatchConflict(BzrError):
3407
 
 
3408
 
    _fmt = ('Text contents mismatch at line %(line_no)d.  Original has '
3409
 
            '"%(orig_line)s", but patch says it should be "%(patch_line)s"')
3410
 
 
3411
 
    def __init__(self, line_no, orig_line, patch_line):
3412
 
        self.line_no = line_no
3413
 
        self.orig_line = orig_line.rstrip('\n')
3414
 
        self.patch_line = patch_line.rstrip('\n')