~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/errors.py

  • Committer: Vincent Ladeuil
  • Date: 2011-07-06 09:22:00 UTC
  • mfrom: (6008 +trunk)
  • mto: (6012.1.1 trunk)
  • mto: This revision was merged to the branch mainline in revision 6013.
  • Revision ID: v.ladeuil+lp@free.fr-20110706092200-7iai2mwzc0sqdsvf
MergingĀ inĀ trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
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 details.
59
 
    (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
 
59
        details.  (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
 
        "record_entry_contents.")
 
307
        "the commit builder.")
308
308
 
309
309
 
310
310
class NoPublicBranch(BzrError):
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
1140
1140
        BzrError.__init__(self, files=files, files_str=files_str)
1141
1141
 
1142
1142
 
 
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
 
1143
1152
class BadCommitMessageEncoding(BzrError):
1144
1153
 
1145
1154
    _fmt = 'The specified commit message contains characters unsupported by '\
1706
1715
 
1707
1716
class InvalidHttpResponse(TransportError):
1708
1717
 
1709
 
    _fmt = "Invalid http response for %(path)s: %(msg)s"
 
1718
    _fmt = "Invalid http response for %(path)s: %(msg)s%(orig_error)s"
1710
1719
 
1711
1720
    def __init__(self, path, msg, orig_error=None):
1712
1721
        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,)
1713
1728
        TransportError.__init__(self, msg, orig_error=orig_error)
1714
1729
 
1715
1730
 
1755
1770
    _fmt = "Working tree has conflicts."
1756
1771
 
1757
1772
 
 
1773
class ConfigContentError(BzrError):
 
1774
 
 
1775
    _fmt = "Config file %(filename)s is not UTF-8 encoded\n"
 
1776
 
 
1777
    def __init__(self, filename):
 
1778
        BzrError.__init__(self)
 
1779
        self.filename = filename
 
1780
 
 
1781
 
1758
1782
class ParseConfigError(BzrError):
1759
1783
 
 
1784
    _fmt = "Error(s) parsing config file %(filename)s:\n%(errors)s"
 
1785
 
1760
1786
    def __init__(self, errors, filename):
1761
 
        if filename is None:
1762
 
            filename = ""
1763
 
        message = "Error(s) parsing config file %s:\n%s" % \
1764
 
            (filename, ('\n'.join(e.msg for e in errors)))
1765
 
        BzrError.__init__(self, message)
 
1787
        BzrError.__init__(self)
 
1788
        self.filename = filename
 
1789
        self.errors = '\n'.join(e.msg for e in errors)
1766
1790
 
1767
1791
 
1768
1792
class NoEmailInUsername(BzrError):
1776
1800
 
1777
1801
class SigningFailed(BzrError):
1778
1802
 
1779
 
    _fmt = 'Failed to gpg sign data with command "%(command_line)s"'
 
1803
    _fmt = 'Failed to GPG sign data with command "%(command_line)s"'
1780
1804
 
1781
1805
    def __init__(self, command_line):
1782
1806
        BzrError.__init__(self, command_line=command_line)
1783
1807
 
1784
1808
 
 
1809
class SignatureVerificationFailed(BzrError):
 
1810
 
 
1811
    _fmt = 'Failed to verify GPG signature data with error "%(error)s"'
 
1812
 
 
1813
    def __init__(self, error):
 
1814
        BzrError.__init__(self, error=error)
 
1815
 
 
1816
 
 
1817
class DependencyNotPresent(BzrError):
 
1818
 
 
1819
    _fmt = 'Unable to import library "%(library)s": %(error)s'
 
1820
 
 
1821
    def __init__(self, library, error):
 
1822
        BzrError.__init__(self, library=library, error=error)
 
1823
 
 
1824
 
 
1825
class GpgmeNotInstalled(DependencyNotPresent):
 
1826
 
 
1827
    _fmt = 'python-gpgme is not installed, it is needed to verify signatures'
 
1828
 
 
1829
    def __init__(self, error):
 
1830
        DependencyNotPresent.__init__(self, 'gpgme', error)
 
1831
 
 
1832
 
1785
1833
class WorkingTreeNotRevision(BzrError):
1786
1834
 
1787
1835
    _fmt = ("The working tree for %(basedir)s has changed since"
1960
2008
 
1961
2009
class BzrMoveFailedError(BzrError):
1962
2010
 
1963
 
    _fmt = "Could not move %(from_path)s%(operator)s %(to_path)s%(extra)s"
 
2011
    _fmt = ("Could not move %(from_path)s%(operator)s %(to_path)s"
 
2012
        "%(_has_extra)s%(extra)s")
1964
2013
 
1965
2014
    def __init__(self, from_path='', to_path='', extra=None):
1966
2015
        from bzrlib.osutils import splitpath
1967
2016
        BzrError.__init__(self)
1968
2017
        if extra:
1969
 
            self.extra = ': ' + str(extra)
 
2018
            self.extra, self._has_extra = extra, ': '
1970
2019
        else:
1971
 
            self.extra = ''
 
2020
            self.extra = self._has_extra = ''
1972
2021
 
1973
2022
        has_from = len(from_path) > 0
1974
2023
        has_to = len(to_path) > 0
1995
2044
 
1996
2045
class BzrRenameFailedError(BzrMoveFailedError):
1997
2046
 
1998
 
    _fmt = "Could not rename %(from_path)s%(operator)s %(to_path)s%(extra)s"
 
2047
    _fmt = ("Could not rename %(from_path)s%(operator)s %(to_path)s"
 
2048
        "%(_has_extra)s%(extra)s")
1999
2049
 
2000
2050
    def __init__(self, from_path, to_path, extra=None):
2001
2051
        BzrMoveFailedError.__init__(self, from_path, to_path, extra)
2002
2052
 
 
2053
 
2003
2054
class BzrRemoveChangedFilesError(BzrError):
2004
2055
    """Used when user is trying to remove changed files."""
2005
2056
 
2037
2088
    _fmt = "Parameter %(param)s contains a newline."
2038
2089
 
2039
2090
 
2040
 
class DependencyNotPresent(BzrError):
2041
 
 
2042
 
    _fmt = 'Unable to import library "%(library)s": %(error)s'
2043
 
 
2044
 
    def __init__(self, library, error):
2045
 
        BzrError.__init__(self, library=library, error=error)
2046
 
 
2047
 
 
2048
2091
class ParamikoNotPresent(DependencyNotPresent):
2049
2092
 
2050
2093
    _fmt = "Unable to import paramiko (required for sftp support): %(error)s"
2653
2696
 
2654
2697
    This is distinct from ErrorFromSmartServer so that it is possible to
2655
2698
    distinguish between the following two cases:
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.
 
2699
 
 
2700
    - ErrorFromSmartServer was uncaught.  This is logic error in the client
 
2701
      and so should provoke a traceback to the user.
 
2702
    - ErrorFromSmartServer was caught but its error_tuple could not be
 
2703
      translated.  This is probably because the server sent us garbage, and
 
2704
      should not provoke a traceback.
2661
2705
    """
2662
2706
 
2663
2707
    _fmt = "Server sent an unexpected error: %(error_tuple)r"
3062
3106
    _fmt = "Shelf corrupt."
3063
3107
 
3064
3108
 
 
3109
class DecompressCorruption(BzrError):
 
3110
 
 
3111
    _fmt = "Corruption while decompressing repository file%(orig_error)s"
 
3112
 
 
3113
    def __init__(self, orig_error=None):
 
3114
        if orig_error is not None:
 
3115
            self.orig_error = ", %s" % (orig_error,)
 
3116
        else:
 
3117
            self.orig_error = ""
 
3118
        BzrError.__init__(self)
 
3119
 
 
3120
 
3065
3121
class NoSuchShelfId(BzrError):
3066
3122
 
3067
3123
    _fmt = 'No changes are shelved with id "%(shelf_id)d".'
3218
3274
    def __init__(self, branch_url):
3219
3275
        self.branch_url = branch_url
3220
3276
 
 
3277
 
 
3278
# FIXME: I would prefer to define the config related exception classes in
 
3279
# config.py but the lazy import mechanism proscribes this -- vila 20101222
 
3280
class OptionExpansionLoop(BzrError):
 
3281
 
 
3282
    _fmt = 'Loop involving %(refs)r while expanding "%(string)s".'
 
3283
 
 
3284
    def __init__(self, string, refs):
 
3285
        self.string = string
 
3286
        self.refs = '->'.join(refs)
 
3287
 
 
3288
 
 
3289
class ExpandingUnknownOption(BzrError):
 
3290
 
 
3291
    _fmt = 'Option %(name)s is not defined while expanding "%(string)s".'
 
3292
 
 
3293
    def __init__(self, name, string):
 
3294
        self.name = name
 
3295
        self.string = string
 
3296
 
 
3297
 
 
3298
class NoCompatibleInter(BzrError):
 
3299
 
 
3300
    _fmt = ('No compatible object available for operations from %(source)r '
 
3301
            'to %(target)r.')
 
3302
 
 
3303
    def __init__(self, source, target):
 
3304
        self.source = source
 
3305
        self.target = target