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