~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/errors.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2011-04-18 04:55:00 UTC
  • mfrom: (5784.2.1 754188-apport-test)
  • Revision ID: pqm@pqm.ubuntu.com-20110418045500-ce6lkgyiq7f47q43
(mbp) Rewrite test_report_bug_legacy away from using doctest (see bug
 764188) (Martin Pool)

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:
1128
1140
        BzrError.__init__(self, files=files, files_str=files_str)
1129
1141
 
1130
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
 
1131
1152
class BadCommitMessageEncoding(BzrError):
1132
1153
 
1133
1154
    _fmt = 'The specified commit message contains characters unsupported by '\
1948
1969
 
1949
1970
class BzrMoveFailedError(BzrError):
1950
1971
 
1951
 
    _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")
1952
1974
 
1953
1975
    def __init__(self, from_path='', to_path='', extra=None):
1954
1976
        from bzrlib.osutils import splitpath
1955
1977
        BzrError.__init__(self)
1956
1978
        if extra:
1957
 
            self.extra = ': ' + str(extra)
 
1979
            self.extra, self._has_extra = extra, ': '
1958
1980
        else:
1959
 
            self.extra = ''
 
1981
            self.extra = self._has_extra = ''
1960
1982
 
1961
1983
        has_from = len(from_path) > 0
1962
1984
        has_to = len(to_path) > 0
1983
2005
 
1984
2006
class BzrRenameFailedError(BzrMoveFailedError):
1985
2007
 
1986
 
    _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")
1987
2010
 
1988
2011
    def __init__(self, from_path, to_path, extra=None):
1989
2012
        BzrMoveFailedError.__init__(self, from_path, to_path, extra)
1990
2013
 
 
2014
 
1991
2015
class BzrRemoveChangedFilesError(BzrError):
1992
2016
    """Used when user is trying to remove changed files."""
1993
2017
 
2011
2035
 
2012
2036
class BzrBadParameterMissing(BzrBadParameter):
2013
2037
 
2014
 
    _fmt = "Parameter $(param)s is required but not present."
 
2038
    _fmt = "Parameter %(param)s is required but not present."
2015
2039
 
2016
2040
 
2017
2041
class BzrBadParameterUnicode(BzrBadParameter):
3206
3230
    def __init__(self, branch_url):
3207
3231
        self.branch_url = branch_url
3208
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