Show More
@@ -1,480 +1,480 b'' | |||||
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 but pycompat here, please |
|
16 | # Do not import anything but pycompat here, please | |
17 | from . import pycompat |
|
17 | from . import pycompat | |
18 |
|
18 | |||
19 |
|
19 | |||
20 | def _tobytes(exc): |
|
20 | def _tobytes(exc): | |
21 | """Byte-stringify exception in the same way as BaseException_str()""" |
|
21 | """Byte-stringify exception in the same way as BaseException_str()""" | |
22 | if not exc.args: |
|
22 | if not exc.args: | |
23 | return b'' |
|
23 | return b'' | |
24 | if len(exc.args) == 1: |
|
24 | if len(exc.args) == 1: | |
25 | return pycompat.bytestr(exc.args[0]) |
|
25 | return pycompat.bytestr(exc.args[0]) | |
26 | return b'(%s)' % b', '.join(b"'%s'" % pycompat.bytestr(a) for a in exc.args) |
|
26 | return b'(%s)' % b', '.join(b"'%s'" % pycompat.bytestr(a) for a in exc.args) | |
27 |
|
27 | |||
28 |
|
28 | |||
29 | class Hint(object): |
|
29 | class Hint(object): | |
30 | """Mix-in to provide a hint of an error |
|
30 | """Mix-in to provide a hint of an error | |
31 |
|
31 | |||
32 | This should come first in the inheritance list to consume a hint and |
|
32 | This should come first in the inheritance list to consume a hint and | |
33 | pass remaining arguments to the exception class. |
|
33 | pass remaining arguments to the exception class. | |
34 | """ |
|
34 | """ | |
35 |
|
35 | |||
36 | def __init__(self, *args, **kw): |
|
36 | def __init__(self, *args, **kw): | |
37 | self.hint = kw.pop('hint', None) |
|
37 | self.hint = kw.pop('hint', None) | |
38 | super(Hint, self).__init__(*args, **kw) |
|
38 | super(Hint, self).__init__(*args, **kw) | |
39 |
|
39 | |||
40 |
|
40 | |||
41 | class StorageError(Hint, Exception): |
|
41 | class StorageError(Hint, Exception): | |
42 | """Raised when an error occurs in a storage layer. |
|
42 | """Raised when an error occurs in a storage layer. | |
43 |
|
43 | |||
44 | Usually subclassed by a storage-specific exception. |
|
44 | Usually subclassed by a storage-specific exception. | |
45 | """ |
|
45 | """ | |
46 |
|
46 | |||
47 | __bytes__ = _tobytes |
|
47 | __bytes__ = _tobytes | |
48 |
|
48 | |||
49 |
|
49 | |||
50 | class RevlogError(StorageError): |
|
50 | class RevlogError(StorageError): | |
51 | __bytes__ = _tobytes |
|
51 | pass | |
52 |
|
52 | |||
53 |
|
53 | |||
54 | class SidedataHashError(RevlogError): |
|
54 | class SidedataHashError(RevlogError): | |
55 | def __init__(self, key, expected, got): |
|
55 | def __init__(self, key, expected, got): | |
56 | self.sidedatakey = key |
|
56 | self.sidedatakey = key | |
57 | self.expecteddigest = expected |
|
57 | self.expecteddigest = expected | |
58 | self.actualdigest = got |
|
58 | self.actualdigest = got | |
59 |
|
59 | |||
60 |
|
60 | |||
61 | class FilteredIndexError(IndexError): |
|
61 | class FilteredIndexError(IndexError): | |
62 | __bytes__ = _tobytes |
|
62 | __bytes__ = _tobytes | |
63 |
|
63 | |||
64 |
|
64 | |||
65 | class LookupError(RevlogError, KeyError): |
|
65 | class LookupError(RevlogError, KeyError): | |
66 | def __init__(self, name, index, message): |
|
66 | def __init__(self, name, index, message): | |
67 | self.name = name |
|
67 | self.name = name | |
68 | self.index = index |
|
68 | self.index = index | |
69 | # this can't be called 'message' because at least some installs of |
|
69 | # this can't be called 'message' because at least some installs of | |
70 | # Python 2.6+ complain about the 'message' property being deprecated |
|
70 | # Python 2.6+ complain about the 'message' property being deprecated | |
71 | self.lookupmessage = message |
|
71 | self.lookupmessage = message | |
72 | if isinstance(name, bytes) and len(name) == 20: |
|
72 | if isinstance(name, bytes) and len(name) == 20: | |
73 | from .node import short |
|
73 | from .node import short | |
74 |
|
74 | |||
75 | name = short(name) |
|
75 | name = short(name) | |
76 | # if name is a binary node, it can be None |
|
76 | # if name is a binary node, it can be None | |
77 | RevlogError.__init__( |
|
77 | RevlogError.__init__( | |
78 | self, b'%s@%s: %s' % (index, pycompat.bytestr(name), message) |
|
78 | self, b'%s@%s: %s' % (index, pycompat.bytestr(name), message) | |
79 | ) |
|
79 | ) | |
80 |
|
80 | |||
81 | def __bytes__(self): |
|
81 | def __bytes__(self): | |
82 | return RevlogError.__bytes__(self) |
|
82 | return RevlogError.__bytes__(self) | |
83 |
|
83 | |||
84 | def __str__(self): |
|
84 | def __str__(self): | |
85 | return RevlogError.__str__(self) |
|
85 | return RevlogError.__str__(self) | |
86 |
|
86 | |||
87 |
|
87 | |||
88 | class AmbiguousPrefixLookupError(LookupError): |
|
88 | class AmbiguousPrefixLookupError(LookupError): | |
89 | pass |
|
89 | pass | |
90 |
|
90 | |||
91 |
|
91 | |||
92 | class FilteredLookupError(LookupError): |
|
92 | class FilteredLookupError(LookupError): | |
93 | pass |
|
93 | pass | |
94 |
|
94 | |||
95 |
|
95 | |||
96 | class ManifestLookupError(LookupError): |
|
96 | class ManifestLookupError(LookupError): | |
97 | pass |
|
97 | pass | |
98 |
|
98 | |||
99 |
|
99 | |||
100 | class CommandError(Exception): |
|
100 | class CommandError(Exception): | |
101 | """Exception raised on errors in parsing the command line.""" |
|
101 | """Exception raised on errors in parsing the command line.""" | |
102 |
|
102 | |||
103 | def __init__(self, command, message): |
|
103 | def __init__(self, command, message): | |
104 | self.command = command |
|
104 | self.command = command | |
105 | self.message = message |
|
105 | self.message = message | |
106 | super(CommandError, self).__init__() |
|
106 | super(CommandError, self).__init__() | |
107 |
|
107 | |||
108 | __bytes__ = _tobytes |
|
108 | __bytes__ = _tobytes | |
109 |
|
109 | |||
110 |
|
110 | |||
111 | class UnknownCommand(Exception): |
|
111 | class UnknownCommand(Exception): | |
112 | """Exception raised if command is not in the command table.""" |
|
112 | """Exception raised if command is not in the command table.""" | |
113 |
|
113 | |||
114 | def __init__(self, command, all_commands=None): |
|
114 | def __init__(self, command, all_commands=None): | |
115 | self.command = command |
|
115 | self.command = command | |
116 | self.all_commands = all_commands |
|
116 | self.all_commands = all_commands | |
117 | super(UnknownCommand, self).__init__() |
|
117 | super(UnknownCommand, self).__init__() | |
118 |
|
118 | |||
119 | __bytes__ = _tobytes |
|
119 | __bytes__ = _tobytes | |
120 |
|
120 | |||
121 |
|
121 | |||
122 | class AmbiguousCommand(Exception): |
|
122 | class AmbiguousCommand(Exception): | |
123 | """Exception raised if command shortcut matches more than one command.""" |
|
123 | """Exception raised if command shortcut matches more than one command.""" | |
124 |
|
124 | |||
125 | def __init__(self, prefix, matches): |
|
125 | def __init__(self, prefix, matches): | |
126 | self.prefix = prefix |
|
126 | self.prefix = prefix | |
127 | self.matches = matches |
|
127 | self.matches = matches | |
128 | super(AmbiguousCommand, self).__init__() |
|
128 | super(AmbiguousCommand, self).__init__() | |
129 |
|
129 | |||
130 | __bytes__ = _tobytes |
|
130 | __bytes__ = _tobytes | |
131 |
|
131 | |||
132 |
|
132 | |||
133 | class InterventionRequired(Hint, Exception): |
|
133 | class InterventionRequired(Hint, Exception): | |
134 | """Exception raised when a command requires human intervention.""" |
|
134 | """Exception raised when a command requires human intervention.""" | |
135 |
|
135 | |||
136 | __bytes__ = _tobytes |
|
136 | __bytes__ = _tobytes | |
137 |
|
137 | |||
138 |
|
138 | |||
139 | class ConflictResolutionRequired(InterventionRequired): |
|
139 | class ConflictResolutionRequired(InterventionRequired): | |
140 | """Exception raised when a continuable command required merge conflict resolution.""" |
|
140 | """Exception raised when a continuable command required merge conflict resolution.""" | |
141 |
|
141 | |||
142 | def __init__(self, opname): |
|
142 | def __init__(self, opname): | |
143 | from .i18n import _ |
|
143 | from .i18n import _ | |
144 |
|
144 | |||
145 | self.opname = opname |
|
145 | self.opname = opname | |
146 | InterventionRequired.__init__( |
|
146 | InterventionRequired.__init__( | |
147 | self, |
|
147 | self, | |
148 | _( |
|
148 | _( | |
149 | b"unresolved conflicts (see 'hg resolve', then 'hg %s --continue')" |
|
149 | b"unresolved conflicts (see 'hg resolve', then 'hg %s --continue')" | |
150 | ) |
|
150 | ) | |
151 | % opname, |
|
151 | % opname, | |
152 | ) |
|
152 | ) | |
153 |
|
153 | |||
154 |
|
154 | |||
155 | class Abort(Hint, Exception): |
|
155 | class Abort(Hint, Exception): | |
156 | """Raised if a command needs to print an error and exit.""" |
|
156 | """Raised if a command needs to print an error and exit.""" | |
157 |
|
157 | |||
158 | def __init__(self, message, hint=None): |
|
158 | def __init__(self, message, hint=None): | |
159 | self.message = message |
|
159 | self.message = message | |
160 | self.hint = hint |
|
160 | self.hint = hint | |
161 | # Pass the message into the Exception constructor to help extensions |
|
161 | # Pass the message into the Exception constructor to help extensions | |
162 | # that look for exc.args[0]. |
|
162 | # that look for exc.args[0]. | |
163 | Exception.__init__(self, message) |
|
163 | Exception.__init__(self, message) | |
164 |
|
164 | |||
165 | def __bytes__(self): |
|
165 | def __bytes__(self): | |
166 | return self.message |
|
166 | return self.message | |
167 |
|
167 | |||
168 | if pycompat.ispy3: |
|
168 | if pycompat.ispy3: | |
169 |
|
169 | |||
170 | def __str__(self): |
|
170 | def __str__(self): | |
171 | # the output would be unreadable if the message was translated, |
|
171 | # the output would be unreadable if the message was translated, | |
172 | # but do not replace it with encoding.strfromlocal(), which |
|
172 | # but do not replace it with encoding.strfromlocal(), which | |
173 | # may raise another exception. |
|
173 | # may raise another exception. | |
174 | return pycompat.sysstr(self.__bytes__()) |
|
174 | return pycompat.sysstr(self.__bytes__()) | |
175 |
|
175 | |||
176 |
|
176 | |||
177 | class HookLoadError(Abort): |
|
177 | class HookLoadError(Abort): | |
178 | """raised when loading a hook fails, aborting an operation |
|
178 | """raised when loading a hook fails, aborting an operation | |
179 |
|
179 | |||
180 | Exists to allow more specialized catching.""" |
|
180 | Exists to allow more specialized catching.""" | |
181 |
|
181 | |||
182 |
|
182 | |||
183 | class HookAbort(Abort): |
|
183 | class HookAbort(Abort): | |
184 | """raised when a validation hook fails, aborting an operation |
|
184 | """raised when a validation hook fails, aborting an operation | |
185 |
|
185 | |||
186 | Exists to allow more specialized catching.""" |
|
186 | Exists to allow more specialized catching.""" | |
187 |
|
187 | |||
188 |
|
188 | |||
189 | class ConfigError(Abort): |
|
189 | class ConfigError(Abort): | |
190 | """Exception raised when parsing config files""" |
|
190 | """Exception raised when parsing config files""" | |
191 |
|
191 | |||
192 |
|
192 | |||
193 | class UpdateAbort(Abort): |
|
193 | class UpdateAbort(Abort): | |
194 | """Raised when an update is aborted for destination issue""" |
|
194 | """Raised when an update is aborted for destination issue""" | |
195 |
|
195 | |||
196 |
|
196 | |||
197 | class MergeDestAbort(Abort): |
|
197 | class MergeDestAbort(Abort): | |
198 | """Raised when an update is aborted for destination issues""" |
|
198 | """Raised when an update is aborted for destination issues""" | |
199 |
|
199 | |||
200 |
|
200 | |||
201 | class NoMergeDestAbort(MergeDestAbort): |
|
201 | class NoMergeDestAbort(MergeDestAbort): | |
202 | """Raised when an update is aborted because there is nothing to merge""" |
|
202 | """Raised when an update is aborted because there is nothing to merge""" | |
203 |
|
203 | |||
204 |
|
204 | |||
205 | class ManyMergeDestAbort(MergeDestAbort): |
|
205 | class ManyMergeDestAbort(MergeDestAbort): | |
206 | """Raised when an update is aborted because destination is ambiguous""" |
|
206 | """Raised when an update is aborted because destination is ambiguous""" | |
207 |
|
207 | |||
208 |
|
208 | |||
209 | class ResponseExpected(Abort): |
|
209 | class ResponseExpected(Abort): | |
210 | """Raised when an EOF is received for a prompt""" |
|
210 | """Raised when an EOF is received for a prompt""" | |
211 |
|
211 | |||
212 | def __init__(self): |
|
212 | def __init__(self): | |
213 | from .i18n import _ |
|
213 | from .i18n import _ | |
214 |
|
214 | |||
215 | Abort.__init__(self, _(b'response expected')) |
|
215 | Abort.__init__(self, _(b'response expected')) | |
216 |
|
216 | |||
217 |
|
217 | |||
218 | class OutOfBandError(Hint, Exception): |
|
218 | class OutOfBandError(Hint, Exception): | |
219 | """Exception raised when a remote repo reports failure""" |
|
219 | """Exception raised when a remote repo reports failure""" | |
220 |
|
220 | |||
221 | __bytes__ = _tobytes |
|
221 | __bytes__ = _tobytes | |
222 |
|
222 | |||
223 |
|
223 | |||
224 | class ParseError(Hint, Exception): |
|
224 | class ParseError(Hint, Exception): | |
225 | """Raised when parsing config files and {rev,file}sets (msg[, pos])""" |
|
225 | """Raised when parsing config files and {rev,file}sets (msg[, pos])""" | |
226 |
|
226 | |||
227 | __bytes__ = _tobytes |
|
227 | __bytes__ = _tobytes | |
228 |
|
228 | |||
229 |
|
229 | |||
230 | class PatchError(Exception): |
|
230 | class PatchError(Exception): | |
231 | __bytes__ = _tobytes |
|
231 | __bytes__ = _tobytes | |
232 |
|
232 | |||
233 |
|
233 | |||
234 | class UnknownIdentifier(ParseError): |
|
234 | class UnknownIdentifier(ParseError): | |
235 | """Exception raised when a {rev,file}set references an unknown identifier""" |
|
235 | """Exception raised when a {rev,file}set references an unknown identifier""" | |
236 |
|
236 | |||
237 | def __init__(self, function, symbols): |
|
237 | def __init__(self, function, symbols): | |
238 | from .i18n import _ |
|
238 | from .i18n import _ | |
239 |
|
239 | |||
240 | ParseError.__init__(self, _(b"unknown identifier: %s") % function) |
|
240 | ParseError.__init__(self, _(b"unknown identifier: %s") % function) | |
241 | self.function = function |
|
241 | self.function = function | |
242 | self.symbols = symbols |
|
242 | self.symbols = symbols | |
243 |
|
243 | |||
244 |
|
244 | |||
245 | class RepoError(Hint, Exception): |
|
245 | class RepoError(Hint, Exception): | |
246 | __bytes__ = _tobytes |
|
246 | __bytes__ = _tobytes | |
247 |
|
247 | |||
248 |
|
248 | |||
249 | class RepoLookupError(RepoError): |
|
249 | class RepoLookupError(RepoError): | |
250 | pass |
|
250 | pass | |
251 |
|
251 | |||
252 |
|
252 | |||
253 | class FilteredRepoLookupError(RepoLookupError): |
|
253 | class FilteredRepoLookupError(RepoLookupError): | |
254 | pass |
|
254 | pass | |
255 |
|
255 | |||
256 |
|
256 | |||
257 | class CapabilityError(RepoError): |
|
257 | class CapabilityError(RepoError): | |
258 | pass |
|
258 | pass | |
259 |
|
259 | |||
260 |
|
260 | |||
261 | class RequirementError(RepoError): |
|
261 | class RequirementError(RepoError): | |
262 | """Exception raised if .hg/requires has an unknown entry.""" |
|
262 | """Exception raised if .hg/requires has an unknown entry.""" | |
263 |
|
263 | |||
264 |
|
264 | |||
265 | class StdioError(IOError): |
|
265 | class StdioError(IOError): | |
266 | """Raised if I/O to stdout or stderr fails""" |
|
266 | """Raised if I/O to stdout or stderr fails""" | |
267 |
|
267 | |||
268 | def __init__(self, err): |
|
268 | def __init__(self, err): | |
269 | IOError.__init__(self, err.errno, err.strerror) |
|
269 | IOError.__init__(self, err.errno, err.strerror) | |
270 |
|
270 | |||
271 | # no __bytes__() because error message is derived from the standard IOError |
|
271 | # no __bytes__() because error message is derived from the standard IOError | |
272 |
|
272 | |||
273 |
|
273 | |||
274 | class UnsupportedMergeRecords(Abort): |
|
274 | class UnsupportedMergeRecords(Abort): | |
275 | def __init__(self, recordtypes): |
|
275 | def __init__(self, recordtypes): | |
276 | from .i18n import _ |
|
276 | from .i18n import _ | |
277 |
|
277 | |||
278 | self.recordtypes = sorted(recordtypes) |
|
278 | self.recordtypes = sorted(recordtypes) | |
279 | s = b' '.join(self.recordtypes) |
|
279 | s = b' '.join(self.recordtypes) | |
280 | Abort.__init__( |
|
280 | Abort.__init__( | |
281 | self, |
|
281 | self, | |
282 | _(b'unsupported merge state records: %s') % s, |
|
282 | _(b'unsupported merge state records: %s') % s, | |
283 | hint=_( |
|
283 | hint=_( | |
284 | b'see https://mercurial-scm.org/wiki/MergeStateRecords for ' |
|
284 | b'see https://mercurial-scm.org/wiki/MergeStateRecords for ' | |
285 | b'more information' |
|
285 | b'more information' | |
286 | ), |
|
286 | ), | |
287 | ) |
|
287 | ) | |
288 |
|
288 | |||
289 |
|
289 | |||
290 | class UnknownVersion(Abort): |
|
290 | class UnknownVersion(Abort): | |
291 | """generic exception for aborting from an encounter with an unknown version |
|
291 | """generic exception for aborting from an encounter with an unknown version | |
292 | """ |
|
292 | """ | |
293 |
|
293 | |||
294 | def __init__(self, msg, hint=None, version=None): |
|
294 | def __init__(self, msg, hint=None, version=None): | |
295 | self.version = version |
|
295 | self.version = version | |
296 | super(UnknownVersion, self).__init__(msg, hint=hint) |
|
296 | super(UnknownVersion, self).__init__(msg, hint=hint) | |
297 |
|
297 | |||
298 |
|
298 | |||
299 | class LockError(IOError): |
|
299 | class LockError(IOError): | |
300 | def __init__(self, errno, strerror, filename, desc): |
|
300 | def __init__(self, errno, strerror, filename, desc): | |
301 | IOError.__init__(self, errno, strerror, filename) |
|
301 | IOError.__init__(self, errno, strerror, filename) | |
302 | self.desc = desc |
|
302 | self.desc = desc | |
303 |
|
303 | |||
304 | # no __bytes__() because error message is derived from the standard IOError |
|
304 | # no __bytes__() because error message is derived from the standard IOError | |
305 |
|
305 | |||
306 |
|
306 | |||
307 | class LockHeld(LockError): |
|
307 | class LockHeld(LockError): | |
308 | def __init__(self, errno, filename, desc, locker): |
|
308 | def __init__(self, errno, filename, desc, locker): | |
309 | LockError.__init__(self, errno, b'Lock held', filename, desc) |
|
309 | LockError.__init__(self, errno, b'Lock held', filename, desc) | |
310 | self.locker = locker |
|
310 | self.locker = locker | |
311 |
|
311 | |||
312 |
|
312 | |||
313 | class LockUnavailable(LockError): |
|
313 | class LockUnavailable(LockError): | |
314 | pass |
|
314 | pass | |
315 |
|
315 | |||
316 |
|
316 | |||
317 | # LockError is for errors while acquiring the lock -- this is unrelated |
|
317 | # LockError is for errors while acquiring the lock -- this is unrelated | |
318 | class LockInheritanceContractViolation(RuntimeError): |
|
318 | class LockInheritanceContractViolation(RuntimeError): | |
319 | __bytes__ = _tobytes |
|
319 | __bytes__ = _tobytes | |
320 |
|
320 | |||
321 |
|
321 | |||
322 | class ResponseError(Exception): |
|
322 | class ResponseError(Exception): | |
323 | """Raised to print an error with part of output and exit.""" |
|
323 | """Raised to print an error with part of output and exit.""" | |
324 |
|
324 | |||
325 | __bytes__ = _tobytes |
|
325 | __bytes__ = _tobytes | |
326 |
|
326 | |||
327 |
|
327 | |||
328 | # derived from KeyboardInterrupt to simplify some breakout code |
|
328 | # derived from KeyboardInterrupt to simplify some breakout code | |
329 | class SignalInterrupt(KeyboardInterrupt): |
|
329 | class SignalInterrupt(KeyboardInterrupt): | |
330 | """Exception raised on SIGTERM and SIGHUP.""" |
|
330 | """Exception raised on SIGTERM and SIGHUP.""" | |
331 |
|
331 | |||
332 |
|
332 | |||
333 | class SignatureError(Exception): |
|
333 | class SignatureError(Exception): | |
334 | __bytes__ = _tobytes |
|
334 | __bytes__ = _tobytes | |
335 |
|
335 | |||
336 |
|
336 | |||
337 | class PushRaced(RuntimeError): |
|
337 | class PushRaced(RuntimeError): | |
338 | """An exception raised during unbundling that indicate a push race""" |
|
338 | """An exception raised during unbundling that indicate a push race""" | |
339 |
|
339 | |||
340 | __bytes__ = _tobytes |
|
340 | __bytes__ = _tobytes | |
341 |
|
341 | |||
342 |
|
342 | |||
343 | class ProgrammingError(Hint, RuntimeError): |
|
343 | class ProgrammingError(Hint, RuntimeError): | |
344 | """Raised if a mercurial (core or extension) developer made a mistake""" |
|
344 | """Raised if a mercurial (core or extension) developer made a mistake""" | |
345 |
|
345 | |||
346 | def __init__(self, msg, *args, **kwargs): |
|
346 | def __init__(self, msg, *args, **kwargs): | |
347 | # On Python 3, turn the message back into a string since this is |
|
347 | # On Python 3, turn the message back into a string since this is | |
348 | # an internal-only error that won't be printed except in a |
|
348 | # an internal-only error that won't be printed except in a | |
349 | # stack traces. |
|
349 | # stack traces. | |
350 | msg = pycompat.sysstr(msg) |
|
350 | msg = pycompat.sysstr(msg) | |
351 | super(ProgrammingError, self).__init__(msg, *args, **kwargs) |
|
351 | super(ProgrammingError, self).__init__(msg, *args, **kwargs) | |
352 |
|
352 | |||
353 | __bytes__ = _tobytes |
|
353 | __bytes__ = _tobytes | |
354 |
|
354 | |||
355 |
|
355 | |||
356 | class WdirUnsupported(Exception): |
|
356 | class WdirUnsupported(Exception): | |
357 | """An exception which is raised when 'wdir()' is not supported""" |
|
357 | """An exception which is raised when 'wdir()' is not supported""" | |
358 |
|
358 | |||
359 | __bytes__ = _tobytes |
|
359 | __bytes__ = _tobytes | |
360 |
|
360 | |||
361 |
|
361 | |||
362 | # bundle2 related errors |
|
362 | # bundle2 related errors | |
363 | class BundleValueError(ValueError): |
|
363 | class BundleValueError(ValueError): | |
364 | """error raised when bundle2 cannot be processed""" |
|
364 | """error raised when bundle2 cannot be processed""" | |
365 |
|
365 | |||
366 | __bytes__ = _tobytes |
|
366 | __bytes__ = _tobytes | |
367 |
|
367 | |||
368 |
|
368 | |||
369 | class BundleUnknownFeatureError(BundleValueError): |
|
369 | class BundleUnknownFeatureError(BundleValueError): | |
370 | def __init__(self, parttype=None, params=(), values=()): |
|
370 | def __init__(self, parttype=None, params=(), values=()): | |
371 | self.parttype = parttype |
|
371 | self.parttype = parttype | |
372 | self.params = params |
|
372 | self.params = params | |
373 | self.values = values |
|
373 | self.values = values | |
374 | if self.parttype is None: |
|
374 | if self.parttype is None: | |
375 | msg = b'Stream Parameter' |
|
375 | msg = b'Stream Parameter' | |
376 | else: |
|
376 | else: | |
377 | msg = parttype |
|
377 | msg = parttype | |
378 | entries = self.params |
|
378 | entries = self.params | |
379 | if self.params and self.values: |
|
379 | if self.params and self.values: | |
380 | assert len(self.params) == len(self.values) |
|
380 | assert len(self.params) == len(self.values) | |
381 | entries = [] |
|
381 | entries = [] | |
382 | for idx, par in enumerate(self.params): |
|
382 | for idx, par in enumerate(self.params): | |
383 | val = self.values[idx] |
|
383 | val = self.values[idx] | |
384 | if val is None: |
|
384 | if val is None: | |
385 | entries.append(val) |
|
385 | entries.append(val) | |
386 | else: |
|
386 | else: | |
387 | entries.append(b"%s=%r" % (par, pycompat.maybebytestr(val))) |
|
387 | entries.append(b"%s=%r" % (par, pycompat.maybebytestr(val))) | |
388 | if entries: |
|
388 | if entries: | |
389 | msg = b'%s - %s' % (msg, b', '.join(entries)) |
|
389 | msg = b'%s - %s' % (msg, b', '.join(entries)) | |
390 | ValueError.__init__(self, msg) |
|
390 | ValueError.__init__(self, msg) | |
391 |
|
391 | |||
392 |
|
392 | |||
393 | class ReadOnlyPartError(RuntimeError): |
|
393 | class ReadOnlyPartError(RuntimeError): | |
394 | """error raised when code tries to alter a part being generated""" |
|
394 | """error raised when code tries to alter a part being generated""" | |
395 |
|
395 | |||
396 | __bytes__ = _tobytes |
|
396 | __bytes__ = _tobytes | |
397 |
|
397 | |||
398 |
|
398 | |||
399 | class PushkeyFailed(Abort): |
|
399 | class PushkeyFailed(Abort): | |
400 | """error raised when a pushkey part failed to update a value""" |
|
400 | """error raised when a pushkey part failed to update a value""" | |
401 |
|
401 | |||
402 | def __init__( |
|
402 | def __init__( | |
403 | self, partid, namespace=None, key=None, new=None, old=None, ret=None |
|
403 | self, partid, namespace=None, key=None, new=None, old=None, ret=None | |
404 | ): |
|
404 | ): | |
405 | self.partid = partid |
|
405 | self.partid = partid | |
406 | self.namespace = namespace |
|
406 | self.namespace = namespace | |
407 | self.key = key |
|
407 | self.key = key | |
408 | self.new = new |
|
408 | self.new = new | |
409 | self.old = old |
|
409 | self.old = old | |
410 | self.ret = ret |
|
410 | self.ret = ret | |
411 | # no i18n expected to be processed into a better message |
|
411 | # no i18n expected to be processed into a better message | |
412 | Abort.__init__( |
|
412 | Abort.__init__( | |
413 | self, b'failed to update value for "%s/%s"' % (namespace, key) |
|
413 | self, b'failed to update value for "%s/%s"' % (namespace, key) | |
414 | ) |
|
414 | ) | |
415 |
|
415 | |||
416 |
|
416 | |||
417 | class CensoredNodeError(StorageError): |
|
417 | class CensoredNodeError(StorageError): | |
418 | """error raised when content verification fails on a censored node |
|
418 | """error raised when content verification fails on a censored node | |
419 |
|
419 | |||
420 | Also contains the tombstone data substituted for the uncensored data. |
|
420 | Also contains the tombstone data substituted for the uncensored data. | |
421 | """ |
|
421 | """ | |
422 |
|
422 | |||
423 | def __init__(self, filename, node, tombstone): |
|
423 | def __init__(self, filename, node, tombstone): | |
424 | from .node import short |
|
424 | from .node import short | |
425 |
|
425 | |||
426 | StorageError.__init__(self, b'%s:%s' % (filename, short(node))) |
|
426 | StorageError.__init__(self, b'%s:%s' % (filename, short(node))) | |
427 | self.tombstone = tombstone |
|
427 | self.tombstone = tombstone | |
428 |
|
428 | |||
429 |
|
429 | |||
430 | class CensoredBaseError(StorageError): |
|
430 | class CensoredBaseError(StorageError): | |
431 | """error raised when a delta is rejected because its base is censored |
|
431 | """error raised when a delta is rejected because its base is censored | |
432 |
|
432 | |||
433 | A delta based on a censored revision must be formed as single patch |
|
433 | A delta based on a censored revision must be formed as single patch | |
434 | operation which replaces the entire base with new content. This ensures |
|
434 | operation which replaces the entire base with new content. This ensures | |
435 | the delta may be applied by clones which have not censored the base. |
|
435 | the delta may be applied by clones which have not censored the base. | |
436 | """ |
|
436 | """ | |
437 |
|
437 | |||
438 |
|
438 | |||
439 | class InvalidBundleSpecification(Exception): |
|
439 | class InvalidBundleSpecification(Exception): | |
440 | """error raised when a bundle specification is invalid. |
|
440 | """error raised when a bundle specification is invalid. | |
441 |
|
441 | |||
442 | This is used for syntax errors as opposed to support errors. |
|
442 | This is used for syntax errors as opposed to support errors. | |
443 | """ |
|
443 | """ | |
444 |
|
444 | |||
445 | __bytes__ = _tobytes |
|
445 | __bytes__ = _tobytes | |
446 |
|
446 | |||
447 |
|
447 | |||
448 | class UnsupportedBundleSpecification(Exception): |
|
448 | class UnsupportedBundleSpecification(Exception): | |
449 | """error raised when a bundle specification is not supported.""" |
|
449 | """error raised when a bundle specification is not supported.""" | |
450 |
|
450 | |||
451 | __bytes__ = _tobytes |
|
451 | __bytes__ = _tobytes | |
452 |
|
452 | |||
453 |
|
453 | |||
454 | class CorruptedState(Exception): |
|
454 | class CorruptedState(Exception): | |
455 | """error raised when a command is not able to read its state from file""" |
|
455 | """error raised when a command is not able to read its state from file""" | |
456 |
|
456 | |||
457 | __bytes__ = _tobytes |
|
457 | __bytes__ = _tobytes | |
458 |
|
458 | |||
459 |
|
459 | |||
460 | class PeerTransportError(Abort): |
|
460 | class PeerTransportError(Abort): | |
461 | """Transport-level I/O error when communicating with a peer repo.""" |
|
461 | """Transport-level I/O error when communicating with a peer repo.""" | |
462 |
|
462 | |||
463 |
|
463 | |||
464 | class InMemoryMergeConflictsError(Exception): |
|
464 | class InMemoryMergeConflictsError(Exception): | |
465 | """Exception raised when merge conflicts arose during an in-memory merge.""" |
|
465 | """Exception raised when merge conflicts arose during an in-memory merge.""" | |
466 |
|
466 | |||
467 | __bytes__ = _tobytes |
|
467 | __bytes__ = _tobytes | |
468 |
|
468 | |||
469 |
|
469 | |||
470 | class WireprotoCommandError(Exception): |
|
470 | class WireprotoCommandError(Exception): | |
471 | """Represents an error during execution of a wire protocol command. |
|
471 | """Represents an error during execution of a wire protocol command. | |
472 |
|
472 | |||
473 | Should only be thrown by wire protocol version 2 commands. |
|
473 | Should only be thrown by wire protocol version 2 commands. | |
474 |
|
474 | |||
475 | The error is a formatter string and an optional iterable of arguments. |
|
475 | The error is a formatter string and an optional iterable of arguments. | |
476 | """ |
|
476 | """ | |
477 |
|
477 | |||
478 | def __init__(self, message, args=None): |
|
478 | def __init__(self, message, args=None): | |
479 | self.message = message |
|
479 | self.message = message | |
480 | self.messageargs = args |
|
480 | self.messageargs = args |
General Comments 0
You need to be logged in to leave comments.
Login now