~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/errors.py

  • Committer: Vincent Ladeuil
  • Date: 2010-10-07 06:08:01 UTC
  • mto: This revision was merged to the branch mainline in revision 5491.
  • Revision ID: v.ladeuil+lp@free.fr-20101007060801-wfdhizfhfmctl8qa
Fix some typos and propose a release planning.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005-2011 Canonical Ltd
 
1
# Copyright (C) 2005-2010 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
54
54
    Base class for errors raised by bzrlib.
55
55
 
56
56
    :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
59
 
        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.)
60
60
 
61
61
    :cvar _fmt: Format string to display the error; this is expanded
62
 
        by the instance's dict.
 
62
    by the instance's dict.
63
63
    """
64
64
 
65
65
    internal_error = False
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
 
713
713
       self.bzrdir = bzrdir
714
714
       PathError.__init__(self, path=path)
715
715
 
716
 
    def __repr__(self):
717
 
        return '<%s %r>' % (self.__class__.__name__, self.__dict__)
718
 
 
719
716
    def _format(self):
720
717
        # XXX: Ideally self.detail would be a property, but Exceptions in
721
718
        # Python 2.4 have to be old-style classes so properties don't work.
726
723
                    self.bzrdir.open_repository()
727
724
                except NoRepositoryPresent:
728
725
                    self.detail = ''
729
 
                except Exception:
730
 
                    # Just ignore unexpected errors.  Raising arbitrary errors
731
 
                    # during str(err) can provoke strange bugs.  Concretely
732
 
                    # Launchpad's codehosting managed to raise NotBranchError
733
 
                    # here, and then get stuck in an infinite loop/recursion
734
 
                    # trying to str() that error.  All this error really cares
735
 
                    # about that there's no working repository there, and if
736
 
                    # open_repository() fails, there probably isn't.
737
 
                    self.detail = ''
738
726
                else:
739
727
                    self.detail = ': location is a repository'
740
728
            else:
864
852
        """Construct a new AlreadyVersionedError.
865
853
 
866
854
        :param path: This is the path which is versioned,
867
 
            which should be in a user friendly form.
 
855
        which should be in a user friendly form.
868
856
        :param context_info: If given, this is information about the context,
869
 
            which could explain why this is expected to not be versioned.
 
857
        which could explain why this is expected to not be versioned.
870
858
        """
871
859
        BzrError.__init__(self)
872
860
        self.path = path
885
873
        """Construct a new NotVersionedError.
886
874
 
887
875
        :param path: This is the path which is not versioned,
888
 
            which should be in a user friendly form.
 
876
        which should be in a user friendly form.
889
877
        :param context_info: If given, this is information about the context,
890
 
            which could explain why this is expected to be versioned.
 
878
        which could explain why this is expected to be versioned.
891
879
        """
892
880
        BzrError.__init__(self)
893
881
        self.path = path
1140
1128
        BzrError.__init__(self, files=files, files_str=files_str)
1141
1129
 
1142
1130
 
1143
 
class ExcludesUnsupported(BzrError):
1144
 
 
1145
 
    _fmt = ('Excluding paths during commit is not supported by '
1146
 
            'repository at %(repository)r.')
1147
 
 
1148
 
    def __init__(self, repository):
1149
 
        BzrError.__init__(self, repository=repository)
1150
 
 
1151
 
 
1152
1131
class BadCommitMessageEncoding(BzrError):
1153
1132
 
1154
1133
    _fmt = 'The specified commit message contains characters unsupported by '\
1416
1395
 
1417
1396
class WeaveInvalidChecksum(WeaveError):
1418
1397
 
1419
 
    _fmt = "Text did not match its checksum: %(msg)s"
 
1398
    _fmt = "Text did not match it's checksum: %(msg)s"
1420
1399
 
1421
1400
 
1422
1401
class WeaveTextDiffers(WeaveError):
1715
1694
 
1716
1695
class InvalidHttpResponse(TransportError):
1717
1696
 
1718
 
    _fmt = "Invalid http response for %(path)s: %(msg)s%(orig_error)s"
 
1697
    _fmt = "Invalid http response for %(path)s: %(msg)s"
1719
1698
 
1720
1699
    def __init__(self, path, msg, orig_error=None):
1721
1700
        self.path = path
1722
 
        if orig_error is None:
1723
 
            orig_error = ''
1724
 
        else:
1725
 
            # This is reached for obscure and unusual errors so we want to
1726
 
            # preserve as much info as possible to ease debug.
1727
 
            orig_error = ': %r' % (orig_error,)
1728
1701
        TransportError.__init__(self, msg, orig_error=orig_error)
1729
1702
 
1730
1703
 
1737
1710
        InvalidHttpResponse.__init__(self, path, msg)
1738
1711
 
1739
1712
 
1740
 
class HttpBoundaryMissing(InvalidHttpResponse):
1741
 
    """A multipart response ends with no boundary marker.
1742
 
 
1743
 
    This is a special case caused by buggy proxies, described in
1744
 
    <https://bugs.launchpad.net/bzr/+bug/198646>.
1745
 
    """
1746
 
 
1747
 
    _fmt = "HTTP MIME Boundary missing for %(path)s: %(msg)s"
1748
 
 
1749
 
    def __init__(self, path, msg):
1750
 
        InvalidHttpResponse.__init__(self, path, msg)
1751
 
 
1752
 
 
1753
1713
class InvalidHttpContentType(InvalidHttpResponse):
1754
1714
 
1755
1715
    _fmt = 'Invalid http Content-type "%(ctype)s" for %(path)s: %(msg)s'
1783
1743
    _fmt = "Working tree has conflicts."
1784
1744
 
1785
1745
 
1786
 
class ConfigContentError(BzrError):
1787
 
 
1788
 
    _fmt = "Config file %(filename)s is not UTF-8 encoded\n"
1789
 
 
1790
 
    def __init__(self, filename):
1791
 
        BzrError.__init__(self)
1792
 
        self.filename = filename
1793
 
 
1794
 
 
1795
1746
class ParseConfigError(BzrError):
1796
1747
 
1797
 
    _fmt = "Error(s) parsing config file %(filename)s:\n%(errors)s"
1798
 
 
1799
1748
    def __init__(self, errors, filename):
1800
 
        BzrError.__init__(self)
1801
 
        self.filename = filename
1802
 
        self.errors = '\n'.join(e.msg for e in errors)
1803
 
 
1804
 
 
1805
 
class ConfigOptionValueError(BzrError):
1806
 
 
1807
 
    _fmt = """Bad value "%(value)s" for option "%(name)s"."""
1808
 
 
1809
 
    def __init__(self, name, value):
1810
 
        BzrError.__init__(self, name=name, value=value)
 
1749
        if filename is None:
 
1750
            filename = ""
 
1751
        message = "Error(s) parsing config file %s:\n%s" % \
 
1752
            (filename, ('\n'.join(e.msg for e in errors)))
 
1753
        BzrError.__init__(self, message)
1811
1754
 
1812
1755
 
1813
1756
class NoEmailInUsername(BzrError):
1821
1764
 
1822
1765
class SigningFailed(BzrError):
1823
1766
 
1824
 
    _fmt = 'Failed to GPG sign data with command "%(command_line)s"'
 
1767
    _fmt = 'Failed to gpg sign data with command "%(command_line)s"'
1825
1768
 
1826
1769
    def __init__(self, command_line):
1827
1770
        BzrError.__init__(self, command_line=command_line)
1828
1771
 
1829
1772
 
1830
 
class SignatureVerificationFailed(BzrError):
1831
 
 
1832
 
    _fmt = 'Failed to verify GPG signature data with error "%(error)s"'
1833
 
 
1834
 
    def __init__(self, error):
1835
 
        BzrError.__init__(self, error=error)
1836
 
 
1837
 
 
1838
 
class DependencyNotPresent(BzrError):
1839
 
 
1840
 
    _fmt = 'Unable to import library "%(library)s": %(error)s'
1841
 
 
1842
 
    def __init__(self, library, error):
1843
 
        BzrError.__init__(self, library=library, error=error)
1844
 
 
1845
 
 
1846
 
class GpgmeNotInstalled(DependencyNotPresent):
1847
 
 
1848
 
    _fmt = 'python-gpgme is not installed, it is needed to verify signatures'
1849
 
 
1850
 
    def __init__(self, error):
1851
 
        DependencyNotPresent.__init__(self, 'gpgme', error)
1852
 
 
1853
 
 
1854
1773
class WorkingTreeNotRevision(BzrError):
1855
1774
 
1856
1775
    _fmt = ("The working tree for %(basedir)s has changed since"
2029
1948
 
2030
1949
class BzrMoveFailedError(BzrError):
2031
1950
 
2032
 
    _fmt = ("Could not move %(from_path)s%(operator)s %(to_path)s"
2033
 
        "%(_has_extra)s%(extra)s")
 
1951
    _fmt = "Could not move %(from_path)s%(operator)s %(to_path)s%(extra)s"
2034
1952
 
2035
1953
    def __init__(self, from_path='', to_path='', extra=None):
2036
1954
        from bzrlib.osutils import splitpath
2037
1955
        BzrError.__init__(self)
2038
1956
        if extra:
2039
 
            self.extra, self._has_extra = extra, ': '
 
1957
            self.extra = ': ' + str(extra)
2040
1958
        else:
2041
 
            self.extra = self._has_extra = ''
 
1959
            self.extra = ''
2042
1960
 
2043
1961
        has_from = len(from_path) > 0
2044
1962
        has_to = len(to_path) > 0
2065
1983
 
2066
1984
class BzrRenameFailedError(BzrMoveFailedError):
2067
1985
 
2068
 
    _fmt = ("Could not rename %(from_path)s%(operator)s %(to_path)s"
2069
 
        "%(_has_extra)s%(extra)s")
 
1986
    _fmt = "Could not rename %(from_path)s%(operator)s %(to_path)s%(extra)s"
2070
1987
 
2071
1988
    def __init__(self, from_path, to_path, extra=None):
2072
1989
        BzrMoveFailedError.__init__(self, from_path, to_path, extra)
2073
1990
 
2074
 
 
2075
1991
class BzrRemoveChangedFilesError(BzrError):
2076
1992
    """Used when user is trying to remove changed files."""
2077
1993
 
2095
2011
 
2096
2012
class BzrBadParameterMissing(BzrBadParameter):
2097
2013
 
2098
 
    _fmt = "Parameter %(param)s is required but not present."
 
2014
    _fmt = "Parameter $(param)s is required but not present."
2099
2015
 
2100
2016
 
2101
2017
class BzrBadParameterUnicode(BzrBadParameter):
2109
2025
    _fmt = "Parameter %(param)s contains a newline."
2110
2026
 
2111
2027
 
 
2028
class DependencyNotPresent(BzrError):
 
2029
 
 
2030
    _fmt = 'Unable to import library "%(library)s": %(error)s'
 
2031
 
 
2032
    def __init__(self, library, error):
 
2033
        BzrError.__init__(self, library=library, error=error)
 
2034
 
 
2035
 
2112
2036
class ParamikoNotPresent(DependencyNotPresent):
2113
2037
 
2114
2038
    _fmt = "Unable to import paramiko (required for sftp support): %(error)s"
2717
2641
 
2718
2642
    This is distinct from ErrorFromSmartServer so that it is possible to
2719
2643
    distinguish between the following two cases:
2720
 
 
2721
 
    - ErrorFromSmartServer was uncaught.  This is logic error in the client
2722
 
      and so should provoke a traceback to the user.
2723
 
    - ErrorFromSmartServer was caught but its error_tuple could not be
2724
 
      translated.  This is probably because the server sent us garbage, and
2725
 
      should not provoke a traceback.
 
2644
      - ErrorFromSmartServer was uncaught.  This is logic error in the client
 
2645
        and so should provoke a traceback to the user.
 
2646
      - ErrorFromSmartServer was caught but its error_tuple could not be
 
2647
        translated.  This is probably because the server sent us garbage, and
 
2648
        should not provoke a traceback.
2726
2649
    """
2727
2650
 
2728
2651
    _fmt = "Server sent an unexpected error: %(error_tuple)r"
3022
2945
        self.user_encoding = osutils.get_user_encoding()
3023
2946
 
3024
2947
 
3025
 
class NoSuchConfig(BzrError):
3026
 
 
3027
 
    _fmt = ('The "%(config_id)s" configuration does not exist.')
3028
 
 
3029
 
    def __init__(self, config_id):
3030
 
        BzrError.__init__(self, config_id=config_id)
3031
 
 
3032
 
 
3033
 
class NoSuchConfigOption(BzrError):
3034
 
 
3035
 
    _fmt = ('The "%(option_name)s" configuration option does not exist.')
3036
 
 
3037
 
    def __init__(self, option_name):
3038
 
        BzrError.__init__(self, option_name=option_name)
3039
 
 
3040
 
 
3041
2948
class NoSuchAlias(BzrError):
3042
2949
 
3043
2950
    _fmt = ('The alias "%(alias_name)s" does not exist.')
3127
3034
    _fmt = "Shelf corrupt."
3128
3035
 
3129
3036
 
3130
 
class DecompressCorruption(BzrError):
3131
 
 
3132
 
    _fmt = "Corruption while decompressing repository file%(orig_error)s"
3133
 
 
3134
 
    def __init__(self, orig_error=None):
3135
 
        if orig_error is not None:
3136
 
            self.orig_error = ", %s" % (orig_error,)
3137
 
        else:
3138
 
            self.orig_error = ""
3139
 
        BzrError.__init__(self)
3140
 
 
3141
 
 
3142
3037
class NoSuchShelfId(BzrError):
3143
3038
 
3144
3039
    _fmt = 'No changes are shelved with id "%(shelf_id)d".'
3295
3190
    def __init__(self, branch_url):
3296
3191
        self.branch_url = branch_url
3297
3192
 
3298
 
 
3299
 
# FIXME: I would prefer to define the config related exception classes in
3300
 
# config.py but the lazy import mechanism proscribes this -- vila 20101222
3301
 
class OptionExpansionLoop(BzrError):
3302
 
 
3303
 
    _fmt = 'Loop involving %(refs)r while expanding "%(string)s".'
3304
 
 
3305
 
    def __init__(self, string, refs):
3306
 
        self.string = string
3307
 
        self.refs = '->'.join(refs)
3308
 
 
3309
 
 
3310
 
class ExpandingUnknownOption(BzrError):
3311
 
 
3312
 
    _fmt = 'Option %(name)s is not defined while expanding "%(string)s".'
3313
 
 
3314
 
    def __init__(self, name, string):
3315
 
        self.name = name
3316
 
        self.string = string
3317
 
 
3318
 
 
3319
 
class NoCompatibleInter(BzrError):
3320
 
 
3321
 
    _fmt = ('No compatible object available for operations from %(source)r '
3322
 
            'to %(target)r.')
3323
 
 
3324
 
    def __init__(self, source, target):
3325
 
        self.source = source
3326
 
        self.target = target