~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/errors.py

  • Committer: John Arbash Meinel
  • Date: 2011-05-11 11:35:28 UTC
  • mto: This revision was merged to the branch mainline in revision 5851.
  • Revision ID: john@arbash-meinel.com-20110511113528-qepibuwxicjrbb2h
Break compatibility with python <2.6.

This includes auditing the code for places where we were doing
explicit 'sys.version' checks and removing them as appropriate.

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
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
 
716
719
    def _format(self):
717
720
        # XXX: Ideally self.detail would be a property, but Exceptions in
718
721
        # Python 2.4 have to be old-style classes so properties don't work.
723
726
                    self.bzrdir.open_repository()
724
727
                except NoRepositoryPresent:
725
728
                    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 = ''
726
738
                else:
727
739
                    self.detail = ': location is a repository'
728
740
            else:
1072
1084
        self.target = target
1073
1085
 
1074
1086
 
 
1087
class LockCorrupt(LockError):
 
1088
 
 
1089
    _fmt = ("Lock is apparently held, but corrupted: %(corruption_info)s\n"
 
1090
            "Use 'bzr break-lock' to clear it")
 
1091
 
 
1092
    internal_error = False
 
1093
 
 
1094
    def __init__(self, corruption_info, file_data=None):
 
1095
        self.corruption_info = corruption_info
 
1096
        self.file_data = file_data
 
1097
 
 
1098
 
1075
1099
class LockNotHeld(LockError):
1076
1100
 
1077
1101
    _fmt = "Lock not held: %(lock)s"
1116
1140
        BzrError.__init__(self, files=files, files_str=files_str)
1117
1141
 
1118
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
 
1119
1152
class BadCommitMessageEncoding(BzrError):
1120
1153
 
1121
1154
    _fmt = 'The specified commit message contains characters unsupported by '\
1383
1416
 
1384
1417
class WeaveInvalidChecksum(WeaveError):
1385
1418
 
1386
 
    _fmt = "Text did not match it's checksum: %(msg)s"
 
1419
    _fmt = "Text did not match its checksum: %(msg)s"
1387
1420
 
1388
1421
 
1389
1422
class WeaveTextDiffers(WeaveError):
1733
1766
 
1734
1767
class ParseConfigError(BzrError):
1735
1768
 
 
1769
    _fmt = "Error(s) parsing config file %(filename)s:\n%(errors)s"
 
1770
 
1736
1771
    def __init__(self, errors, filename):
1737
 
        if filename is None:
1738
 
            filename = ""
1739
 
        message = "Error(s) parsing config file %s:\n%s" % \
1740
 
            (filename, ('\n'.join(e.msg for e in errors)))
1741
 
        BzrError.__init__(self, message)
 
1772
        BzrError.__init__(self)
 
1773
        self.filename = filename
 
1774
        self.errors = '\n'.join(e.msg for e in errors)
1742
1775
 
1743
1776
 
1744
1777
class NoEmailInUsername(BzrError):
1936
1969
 
1937
1970
class BzrMoveFailedError(BzrError):
1938
1971
 
1939
 
    _fmt = "Could not move %(from_path)s%(operator)s %(to_path)s%(extra)s"
 
1972
    _fmt = ("Could not move %(from_path)s%(operator)s %(to_path)s"
 
1973
        "%(_has_extra)s%(extra)s")
1940
1974
 
1941
1975
    def __init__(self, from_path='', to_path='', extra=None):
1942
1976
        from bzrlib.osutils import splitpath
1943
1977
        BzrError.__init__(self)
1944
1978
        if extra:
1945
 
            self.extra = ': ' + str(extra)
 
1979
            self.extra, self._has_extra = extra, ': '
1946
1980
        else:
1947
 
            self.extra = ''
 
1981
            self.extra = self._has_extra = ''
1948
1982
 
1949
1983
        has_from = len(from_path) > 0
1950
1984
        has_to = len(to_path) > 0
1971
2005
 
1972
2006
class BzrRenameFailedError(BzrMoveFailedError):
1973
2007
 
1974
 
    _fmt = "Could not rename %(from_path)s%(operator)s %(to_path)s%(extra)s"
 
2008
    _fmt = ("Could not rename %(from_path)s%(operator)s %(to_path)s"
 
2009
        "%(_has_extra)s%(extra)s")
1975
2010
 
1976
2011
    def __init__(self, from_path, to_path, extra=None):
1977
2012
        BzrMoveFailedError.__init__(self, from_path, to_path, extra)
1978
2013
 
 
2014
 
1979
2015
class BzrRemoveChangedFilesError(BzrError):
1980
2016
    """Used when user is trying to remove changed files."""
1981
2017
 
1999
2035
 
2000
2036
class BzrBadParameterMissing(BzrBadParameter):
2001
2037
 
2002
 
    _fmt = "Parameter $(param)s is required but not present."
 
2038
    _fmt = "Parameter %(param)s is required but not present."
2003
2039
 
2004
2040
 
2005
2041
class BzrBadParameterUnicode(BzrBadParameter):
2933
2969
        self.user_encoding = osutils.get_user_encoding()
2934
2970
 
2935
2971
 
 
2972
class NoSuchConfig(BzrError):
 
2973
 
 
2974
    _fmt = ('The "%(config_id)s" configuration does not exist.')
 
2975
 
 
2976
    def __init__(self, config_id):
 
2977
        BzrError.__init__(self, config_id=config_id)
 
2978
 
 
2979
 
 
2980
class NoSuchConfigOption(BzrError):
 
2981
 
 
2982
    _fmt = ('The "%(option_name)s" configuration option does not exist.')
 
2983
 
 
2984
    def __init__(self, option_name):
 
2985
        BzrError.__init__(self, option_name=option_name)
 
2986
 
 
2987
 
2936
2988
class NoSuchAlias(BzrError):
2937
2989
 
2938
2990
    _fmt = ('The alias "%(alias_name)s" does not exist.')
3178
3230
    def __init__(self, branch_url):
3179
3231
        self.branch_url = branch_url
3180
3232
 
 
3233
 
 
3234
# FIXME: I would prefer to define the config related exception classes in
 
3235
# config.py but the lazy import mechanism proscribes this -- vila 20101222
 
3236
class OptionExpansionLoop(BzrError):
 
3237
 
 
3238
    _fmt = 'Loop involving %(refs)r while expanding "%(string)s".'
 
3239
 
 
3240
    def __init__(self, string, refs):
 
3241
        self.string = string
 
3242
        self.refs = '->'.join(refs)
 
3243
 
 
3244
 
 
3245
class ExpandingUnknownOption(BzrError):
 
3246
 
 
3247
    _fmt = 'Option %(name)s is not defined while expanding "%(string)s".'
 
3248
 
 
3249
    def __init__(self, name, string):
 
3250
        self.name = name
 
3251
        self.string = string
 
3252
 
 
3253
 
 
3254
class NoCompatibleInter(BzrError):
 
3255
 
 
3256
    _fmt = ('No compatible object available for operations from %(source)r '
 
3257
            'to %(target)r.')
 
3258
 
 
3259
    def __init__(self, source, target):
 
3260
        self.source = source
 
3261
        self.target = target