~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/errors.py

  • Committer: Martin Pool
  • Date: 2005-04-15 02:29:03 UTC
  • Revision ID: mbp@sourcefrog.net-20050415022903-a7f3567927641056
- Write less startup junk to .bzr.log
- Clean up trace.py code.
- Write pids into log to help with concurrent execution.

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
######################################################################
24
24
# exceptions 
25
25
class BzrError(StandardError):
26
 
    def __str__(self):
27
 
        if len(self.args) == 1:
28
 
            return self.args[0]
29
 
        elif len(self.args) == 2:
30
 
            # further explanation or suggestions
31
 
            return '\n  '.join([self.args[0]] + self.args[1])
32
 
        else:
33
 
            return `self.args`
34
 
 
 
26
    pass
35
27
 
36
28
class BzrCheckError(BzrError):
37
29
    pass
38
30
 
39
31
 
40
 
class InvalidRevisionNumber(BzrError):
41
 
    def __str__(self):
42
 
        return 'invalid revision number: %r' % self.args[0]
43
 
 
44
 
 
45
 
class InvalidRevisionId(BzrError):
46
 
    pass
47
 
 
48
 
 
49
 
class BzrCommandError(BzrError):
50
 
    # Error from malformed user command
51
 
    pass
52
 
 
53
 
 
54
 
class NotBranchError(BzrError):
55
 
    """Specified path is not in a branch"""
56
 
    pass
57
 
 
58
 
 
59
 
class NotVersionedError(BzrError):
60
 
    """Specified object is not versioned."""
61
 
 
62
 
 
63
 
class BadFileKindError(BzrError):
64
 
    """Specified file is of a kind that cannot be added.
65
 
 
66
 
    (For example a symlink or device file.)"""
67
 
    pass
68
 
 
69
 
 
70
 
class ForbiddenFileError(BzrError):
71
 
    """Cannot operate on a file because it is a control file."""
72
 
    pass
73
 
 
74
 
 
75
 
class LockError(Exception):
76
 
    """All exceptions from the lock/unlock functions should be from
77
 
    this exception class.  They will be translated as necessary. The
78
 
    original exception is available as e.original_error
79
 
    """
80
 
    def __init__(self, e=None):
81
 
        self.original_error = e
82
 
        if e:
83
 
            Exception.__init__(self, e)
84
 
        else:
85
 
            Exception.__init__(self)
86
 
 
87
 
 
88
 
class PointlessCommit(Exception):
89
 
    """Commit failed because nothing was changed."""
90
 
 
91
 
 
92
 
class NoSuchRevision(BzrError):
93
 
    def __init__(self, branch, revision):
94
 
        self.branch = branch
95
 
        self.revision = revision
96
 
        msg = "Branch %s has no revision %s" % (branch, revision)
97
 
        BzrError.__init__(self, msg)
98
 
 
99
 
 
100
 
class HistoryMissing(BzrError):
101
 
    def __init__(self, branch, object_type, object_id):
102
 
        self.branch = branch
103
 
        BzrError.__init__(self,
104
 
                          '%s is missing %s {%s}'
105
 
                          % (branch, object_type, object_id))
106
 
 
107
 
 
108
 
class UnrelatedBranches(BzrCommandError):
109
 
    def __init__(self):
110
 
        msg = "Branches have no common ancestor, and no base revision"\
111
 
            " specified."
112
 
        BzrCommandError.__init__(self, msg)
113
 
 
114
 
 
115
 
class NotAncestor(BzrError):
116
 
    def __init__(self, rev_id, not_ancestor_id):
117
 
        self.rev_id = rev_id
118
 
        self.not_ancestor_id = not_ancestor_id
119
 
        msg = "Revision %s is not an ancestor of %s" % (not_ancestor_id, 
120
 
                                                        rev_id)
121
 
        BzrError.__init__(self, msg)
122
 
 
123
 
 
124
 
class InstallFailed(BzrError):
125
 
    def __init__(self, revisions):
126
 
        self.revisions = revisions
127
 
        msg = "Could not install revisions:\n%s" % " ,".join(revisions)
128
 
        BzrError.__init__(self, msg)
129
 
 
130
 
 
131
 
class AmbiguousBase(BzrError):
132
 
    def __init__(self, bases):
133
 
        msg = "The correct base is unclear, becase %s are all equally close" %\
134
 
            ", ".join(bases)
135
 
        BzrError.__init__(self, msg)
136
 
        self.bases = bases
 
32
 
 
33
 
 
34
def bailout(msg, explanation=[]):
 
35
    ex = BzrError(msg, explanation)
 
36
    import trace
 
37
    trace._tracefile.write('* raising %s\n' % ex)
 
38
    raise ex
137
39