Show More
@@ -1,203 +1,203 | |||||
1 | # error.py - Mercurial exceptions |
|
1 | # error.py - Mercurial exceptions | |
2 | # |
|
2 | # | |
3 | # Copyright 2005-2008 Matt Mackall <mpm@selenic.com> |
|
3 | # Copyright 2005-2008 Matt Mackall <mpm@selenic.com> | |
4 | # |
|
4 | # | |
5 | # This software may be used and distributed according to the terms of the |
|
5 | # This software may be used and distributed according to the terms of the | |
6 | # GNU General Public License version 2 or any later version. |
|
6 | # GNU General Public License version 2 or any later version. | |
7 |
|
7 | |||
8 | """Mercurial exceptions. |
|
8 | """Mercurial exceptions. | |
9 |
|
9 | |||
10 | This allows us to catch exceptions at higher levels without forcing |
|
10 | This allows us to catch exceptions at higher levels without forcing | |
11 | imports. |
|
11 | imports. | |
12 | """ |
|
12 | """ | |
13 |
|
13 | |||
14 | from __future__ import absolute_import |
|
14 | from __future__ import absolute_import | |
15 |
|
15 | |||
16 | # Do not import anything here, please |
|
16 | # Do not import anything here, please | |
17 |
|
17 | |||
18 | class HintException(Exception): |
|
18 | class HintException(Exception): | |
19 | def __init__(self, *args, **kw): |
|
19 | def __init__(self, *args, **kw): | |
20 | Exception.__init__(self, *args) |
|
20 | Exception.__init__(self, *args) | |
21 | self.hint = kw.get('hint') |
|
21 | self.hint = kw.get('hint') | |
22 |
|
22 | |||
23 | class RevlogError(HintException): |
|
23 | class RevlogError(HintException): | |
24 | pass |
|
24 | pass | |
25 |
|
25 | |||
26 | class FilteredIndexError(IndexError): |
|
26 | class FilteredIndexError(IndexError): | |
27 | pass |
|
27 | pass | |
28 |
|
28 | |||
29 | class LookupError(RevlogError, KeyError): |
|
29 | class LookupError(RevlogError, KeyError): | |
30 | def __init__(self, name, index, message): |
|
30 | def __init__(self, name, index, message): | |
31 | self.name = name |
|
31 | self.name = name | |
32 | self.index = index |
|
32 | self.index = index | |
33 | # this can't be called 'message' because at least some installs of |
|
33 | # this can't be called 'message' because at least some installs of | |
34 | # Python 2.6+ complain about the 'message' property being deprecated |
|
34 | # Python 2.6+ complain about the 'message' property being deprecated | |
35 | self.lookupmessage = message |
|
35 | self.lookupmessage = message | |
36 | if isinstance(name, str) and len(name) == 20: |
|
36 | if isinstance(name, str) and len(name) == 20: | |
37 | from .node import short |
|
37 | from .node import short | |
38 | name = short(name) |
|
38 | name = short(name) | |
39 | RevlogError.__init__(self, '%s@%s: %s' % (index, name, message)) |
|
39 | RevlogError.__init__(self, '%s@%s: %s' % (index, name, message)) | |
40 |
|
40 | |||
41 | def __str__(self): |
|
41 | def __str__(self): | |
42 | return RevlogError.__str__(self) |
|
42 | return RevlogError.__str__(self) | |
43 |
|
43 | |||
44 | class FilteredLookupError(LookupError): |
|
44 | class FilteredLookupError(LookupError): | |
45 | pass |
|
45 | pass | |
46 |
|
46 | |||
47 | class ManifestLookupError(LookupError): |
|
47 | class ManifestLookupError(LookupError): | |
48 | pass |
|
48 | pass | |
49 |
|
49 | |||
50 | class CommandError(Exception): |
|
50 | class CommandError(Exception): | |
51 | """Exception raised on errors in parsing the command line.""" |
|
51 | """Exception raised on errors in parsing the command line.""" | |
52 |
|
52 | |||
53 | class InterventionRequired(Exception): |
|
53 | class InterventionRequired(Exception): | |
54 | """Exception raised when a command requires human intervention.""" |
|
54 | """Exception raised when a command requires human intervention.""" | |
55 |
|
55 | |||
56 | class Abort(HintException): |
|
56 | class Abort(HintException): | |
57 | """Raised if a command needs to print an error and exit.""" |
|
57 | """Raised if a command needs to print an error and exit.""" | |
58 | pass |
|
58 | pass | |
59 |
|
59 | |||
60 | class HookAbort(Abort): |
|
60 | class HookAbort(Abort): | |
61 | """raised when a validation hook fails, aborting an operation |
|
61 | """raised when a validation hook fails, aborting an operation | |
62 |
|
62 | |||
63 | Exists to allow more specialized catching.""" |
|
63 | Exists to allow more specialized catching.""" | |
64 | pass |
|
64 | pass | |
65 |
|
65 | |||
66 | class ConfigError(Abort): |
|
66 | class ConfigError(Abort): | |
67 | """Exception raised when parsing config files""" |
|
67 | """Exception raised when parsing config files""" | |
68 |
|
68 | |||
69 | class OutOfBandError(Exception): |
|
69 | class OutOfBandError(Exception): | |
70 | """Exception raised when a remote repo reports failure""" |
|
70 | """Exception raised when a remote repo reports failure""" | |
71 |
|
71 | |||
72 | def __init__(self, *args, **kw): |
|
72 | def __init__(self, *args, **kw): | |
73 | Exception.__init__(self, *args) |
|
73 | Exception.__init__(self, *args) | |
74 | self.hint = kw.get('hint') |
|
74 | self.hint = kw.get('hint') | |
75 |
|
75 | |||
76 | class ParseError(Exception): |
|
76 | class ParseError(Exception): | |
77 | """Raised when parsing config files and {rev,file}sets (msg[, pos])""" |
|
77 | """Raised when parsing config files and {rev,file}sets (msg[, pos])""" | |
78 |
|
78 | |||
79 | class UnknownIdentifier(ParseError): |
|
79 | class UnknownIdentifier(ParseError): | |
80 | """Exception raised when a {rev,file}set references an unknown identifier""" |
|
80 | """Exception raised when a {rev,file}set references an unknown identifier""" | |
81 |
|
81 | |||
82 | def __init__(self, function, symbols): |
|
82 | def __init__(self, function, symbols): | |
83 | from .i18n import _ |
|
83 | from .i18n import _ | |
84 | ParseError.__init__(self, _("unknown identifier: %s") % function) |
|
84 | ParseError.__init__(self, _("unknown identifier: %s") % function) | |
85 | self.function = function |
|
85 | self.function = function | |
86 | self.symbols = symbols |
|
86 | self.symbols = symbols | |
87 |
|
87 | |||
88 | class RepoError(HintException): |
|
88 | class RepoError(HintException): | |
89 | pass |
|
89 | pass | |
90 |
|
90 | |||
91 | class RepoLookupError(RepoError): |
|
91 | class RepoLookupError(RepoError): | |
92 | pass |
|
92 | pass | |
93 |
|
93 | |||
94 | class FilteredRepoLookupError(RepoLookupError): |
|
94 | class FilteredRepoLookupError(RepoLookupError): | |
95 | pass |
|
95 | pass | |
96 |
|
96 | |||
97 | class CapabilityError(RepoError): |
|
97 | class CapabilityError(RepoError): | |
98 | pass |
|
98 | pass | |
99 |
|
99 | |||
100 | class RequirementError(RepoError): |
|
100 | class RequirementError(RepoError): | |
101 | """Exception raised if .hg/requires has an unknown entry.""" |
|
101 | """Exception raised if .hg/requires has an unknown entry.""" | |
102 | pass |
|
102 | pass | |
103 |
|
103 | |||
104 | class LockError(IOError): |
|
104 | class LockError(IOError): | |
105 | def __init__(self, errno, strerror, filename, desc): |
|
105 | def __init__(self, errno, strerror, filename, desc): | |
106 | IOError.__init__(self, errno, strerror, filename) |
|
106 | IOError.__init__(self, errno, strerror, filename) | |
107 | self.desc = desc |
|
107 | self.desc = desc | |
108 |
|
108 | |||
109 | class LockHeld(LockError): |
|
109 | class LockHeld(LockError): | |
110 | def __init__(self, errno, filename, desc, locker): |
|
110 | def __init__(self, errno, filename, desc, locker): | |
111 | LockError.__init__(self, errno, 'Lock held', filename, desc) |
|
111 | LockError.__init__(self, errno, 'Lock held', filename, desc) | |
112 | self.locker = locker |
|
112 | self.locker = locker | |
113 |
|
113 | |||
114 | class LockUnavailable(LockError): |
|
114 | class LockUnavailable(LockError): | |
115 | pass |
|
115 | pass | |
116 |
|
116 | |||
117 | # LockError is for errors while acquiring the lock -- this is unrelated |
|
117 | # LockError is for errors while acquiring the lock -- this is unrelated | |
118 |
class LockInheritanceContractViolation( |
|
118 | class LockInheritanceContractViolation(RuntimeError): | |
119 | pass |
|
119 | pass | |
120 |
|
120 | |||
121 | class ResponseError(Exception): |
|
121 | class ResponseError(Exception): | |
122 | """Raised to print an error with part of output and exit.""" |
|
122 | """Raised to print an error with part of output and exit.""" | |
123 |
|
123 | |||
124 | class UnknownCommand(Exception): |
|
124 | class UnknownCommand(Exception): | |
125 | """Exception raised if command is not in the command table.""" |
|
125 | """Exception raised if command is not in the command table.""" | |
126 |
|
126 | |||
127 | class AmbiguousCommand(Exception): |
|
127 | class AmbiguousCommand(Exception): | |
128 | """Exception raised if command shortcut matches more than one command.""" |
|
128 | """Exception raised if command shortcut matches more than one command.""" | |
129 |
|
129 | |||
130 | # derived from KeyboardInterrupt to simplify some breakout code |
|
130 | # derived from KeyboardInterrupt to simplify some breakout code | |
131 | class SignalInterrupt(KeyboardInterrupt): |
|
131 | class SignalInterrupt(KeyboardInterrupt): | |
132 | """Exception raised on SIGTERM and SIGHUP.""" |
|
132 | """Exception raised on SIGTERM and SIGHUP.""" | |
133 |
|
133 | |||
134 | class SignatureError(Exception): |
|
134 | class SignatureError(Exception): | |
135 | pass |
|
135 | pass | |
136 |
|
136 | |||
137 | class PushRaced(RuntimeError): |
|
137 | class PushRaced(RuntimeError): | |
138 | """An exception raised during unbundling that indicate a push race""" |
|
138 | """An exception raised during unbundling that indicate a push race""" | |
139 |
|
139 | |||
140 | # bundle2 related errors |
|
140 | # bundle2 related errors | |
141 | class BundleValueError(ValueError): |
|
141 | class BundleValueError(ValueError): | |
142 | """error raised when bundle2 cannot be processed""" |
|
142 | """error raised when bundle2 cannot be processed""" | |
143 |
|
143 | |||
144 | class BundleUnknownFeatureError(BundleValueError): |
|
144 | class BundleUnknownFeatureError(BundleValueError): | |
145 | def __init__(self, parttype=None, params=(), values=()): |
|
145 | def __init__(self, parttype=None, params=(), values=()): | |
146 | self.parttype = parttype |
|
146 | self.parttype = parttype | |
147 | self.params = params |
|
147 | self.params = params | |
148 | self.values = values |
|
148 | self.values = values | |
149 | if self.parttype is None: |
|
149 | if self.parttype is None: | |
150 | msg = 'Stream Parameter' |
|
150 | msg = 'Stream Parameter' | |
151 | else: |
|
151 | else: | |
152 | msg = parttype |
|
152 | msg = parttype | |
153 | entries = self.params |
|
153 | entries = self.params | |
154 | if self.params and self.values: |
|
154 | if self.params and self.values: | |
155 | assert len(self.params) == len(self.values) |
|
155 | assert len(self.params) == len(self.values) | |
156 | entries = [] |
|
156 | entries = [] | |
157 | for idx, par in enumerate(self.params): |
|
157 | for idx, par in enumerate(self.params): | |
158 | val = self.values[idx] |
|
158 | val = self.values[idx] | |
159 | if val is None: |
|
159 | if val is None: | |
160 | entries.append(val) |
|
160 | entries.append(val) | |
161 | else: |
|
161 | else: | |
162 | entries.append("%s=%r" % (par, val)) |
|
162 | entries.append("%s=%r" % (par, val)) | |
163 | if entries: |
|
163 | if entries: | |
164 | msg = '%s - %s' % (msg, ', '.join(entries)) |
|
164 | msg = '%s - %s' % (msg, ', '.join(entries)) | |
165 | ValueError.__init__(self, msg) |
|
165 | ValueError.__init__(self, msg) | |
166 |
|
166 | |||
167 | class ReadOnlyPartError(RuntimeError): |
|
167 | class ReadOnlyPartError(RuntimeError): | |
168 | """error raised when code tries to alter a part being generated""" |
|
168 | """error raised when code tries to alter a part being generated""" | |
169 | pass |
|
169 | pass | |
170 |
|
170 | |||
171 | class PushkeyFailed(Abort): |
|
171 | class PushkeyFailed(Abort): | |
172 | """error raised when a pushkey part failed to update a value""" |
|
172 | """error raised when a pushkey part failed to update a value""" | |
173 |
|
173 | |||
174 | def __init__(self, partid, namespace=None, key=None, new=None, old=None, |
|
174 | def __init__(self, partid, namespace=None, key=None, new=None, old=None, | |
175 | ret=None): |
|
175 | ret=None): | |
176 | self.partid = partid |
|
176 | self.partid = partid | |
177 | self.namespace = namespace |
|
177 | self.namespace = namespace | |
178 | self.key = key |
|
178 | self.key = key | |
179 | self.new = new |
|
179 | self.new = new | |
180 | self.old = old |
|
180 | self.old = old | |
181 | self.ret = ret |
|
181 | self.ret = ret | |
182 | # no i18n expected to be processed into a better message |
|
182 | # no i18n expected to be processed into a better message | |
183 | Abort.__init__(self, 'failed to update value for "%s/%s"' |
|
183 | Abort.__init__(self, 'failed to update value for "%s/%s"' | |
184 | % (namespace, key)) |
|
184 | % (namespace, key)) | |
185 |
|
185 | |||
186 | class CensoredNodeError(RevlogError): |
|
186 | class CensoredNodeError(RevlogError): | |
187 | """error raised when content verification fails on a censored node |
|
187 | """error raised when content verification fails on a censored node | |
188 |
|
188 | |||
189 | Also contains the tombstone data substituted for the uncensored data. |
|
189 | Also contains the tombstone data substituted for the uncensored data. | |
190 | """ |
|
190 | """ | |
191 |
|
191 | |||
192 | def __init__(self, filename, node, tombstone): |
|
192 | def __init__(self, filename, node, tombstone): | |
193 | from .node import short |
|
193 | from .node import short | |
194 | RevlogError.__init__(self, '%s:%s' % (filename, short(node))) |
|
194 | RevlogError.__init__(self, '%s:%s' % (filename, short(node))) | |
195 | self.tombstone = tombstone |
|
195 | self.tombstone = tombstone | |
196 |
|
196 | |||
197 | class CensoredBaseError(RevlogError): |
|
197 | class CensoredBaseError(RevlogError): | |
198 | """error raised when a delta is rejected because its base is censored |
|
198 | """error raised when a delta is rejected because its base is censored | |
199 |
|
199 | |||
200 | A delta based on a censored revision must be formed as single patch |
|
200 | A delta based on a censored revision must be formed as single patch | |
201 | operation which replaces the entire base with new content. This ensures |
|
201 | operation which replaces the entire base with new content. This ensures | |
202 | the delta may be applied by clones which have not censored the base. |
|
202 | the delta may be applied by clones which have not censored the base. | |
203 | """ |
|
203 | """ |
General Comments 0
You need to be logged in to leave comments.
Login now