##// END OF EJS Templates
py3: unimplement RevlogError.__str__()...
Yuya Nishihara -
r41008:2393c404 default
parent child Browse files
Show More
@@ -1,344 +1,336
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 def _tobytes(exc):
20 20 """Byte-stringify exception in the same way as BaseException_str()"""
21 21 if not exc.args:
22 22 return b''
23 23 if len(exc.args) == 1:
24 24 return pycompat.bytestr(exc.args[0])
25 25 return b'(%s)' % b', '.join(b"'%s'" % pycompat.bytestr(a) for a in exc.args)
26 26
27 27 class Hint(object):
28 28 """Mix-in to provide a hint of an error
29 29
30 30 This should come first in the inheritance list to consume a hint and
31 31 pass remaining arguments to the exception class.
32 32 """
33 33 def __init__(self, *args, **kw):
34 34 self.hint = kw.pop(r'hint', None)
35 35 super(Hint, self).__init__(*args, **kw)
36 36
37 37 class StorageError(Hint, Exception):
38 38 """Raised when an error occurs in a storage layer.
39 39
40 40 Usually subclassed by a storage-specific exception.
41 41 """
42 42 __bytes__ = _tobytes
43 43
44 44 class RevlogError(StorageError):
45 45 __bytes__ = _tobytes
46 46
47 def __str__(self):
48 # avoid cycle, and directly implement unimethod for this
49 # __str__ to allow delaying the import of encoding until
50 # someone actually wants the __str__ of a RevlogError (which
51 # should be very rare).
52 from . import encoding
53 return encoding.unifromlocal(_tobytes(self))
54
55 47 class FilteredIndexError(IndexError):
56 48 __bytes__ = _tobytes
57 49
58 50 class LookupError(RevlogError, KeyError):
59 51 def __init__(self, name, index, message):
60 52 self.name = name
61 53 self.index = index
62 54 # this can't be called 'message' because at least some installs of
63 55 # Python 2.6+ complain about the 'message' property being deprecated
64 56 self.lookupmessage = message
65 57 if isinstance(name, bytes) and len(name) == 20:
66 58 from .node import short
67 59 name = short(name)
68 60 RevlogError.__init__(self, '%s@%s: %s' % (index, name, message))
69 61
70 62 def __bytes__(self):
71 63 return RevlogError.__bytes__(self)
72 64
73 65 def __str__(self):
74 66 return RevlogError.__str__(self)
75 67
76 68 class AmbiguousPrefixLookupError(LookupError):
77 69 pass
78 70
79 71 class FilteredLookupError(LookupError):
80 72 pass
81 73
82 74 class ManifestLookupError(LookupError):
83 75 pass
84 76
85 77 class CommandError(Exception):
86 78 """Exception raised on errors in parsing the command line."""
87 79 __bytes__ = _tobytes
88 80
89 81 class InterventionRequired(Hint, Exception):
90 82 """Exception raised when a command requires human intervention."""
91 83 __bytes__ = _tobytes
92 84
93 85 class Abort(Hint, Exception):
94 86 """Raised if a command needs to print an error and exit."""
95 87 __bytes__ = _tobytes
96 88
97 89 class HookLoadError(Abort):
98 90 """raised when loading a hook fails, aborting an operation
99 91
100 92 Exists to allow more specialized catching."""
101 93
102 94 class HookAbort(Abort):
103 95 """raised when a validation hook fails, aborting an operation
104 96
105 97 Exists to allow more specialized catching."""
106 98
107 99 class ConfigError(Abort):
108 100 """Exception raised when parsing config files"""
109 101
110 102 class UpdateAbort(Abort):
111 103 """Raised when an update is aborted for destination issue"""
112 104
113 105 class MergeDestAbort(Abort):
114 106 """Raised when an update is aborted for destination issues"""
115 107
116 108 class NoMergeDestAbort(MergeDestAbort):
117 109 """Raised when an update is aborted because there is nothing to merge"""
118 110
119 111 class ManyMergeDestAbort(MergeDestAbort):
120 112 """Raised when an update is aborted because destination is ambiguous"""
121 113
122 114 class ResponseExpected(Abort):
123 115 """Raised when an EOF is received for a prompt"""
124 116 def __init__(self):
125 117 from .i18n import _
126 118 Abort.__init__(self, _('response expected'))
127 119
128 120 class OutOfBandError(Hint, Exception):
129 121 """Exception raised when a remote repo reports failure"""
130 122 __bytes__ = _tobytes
131 123
132 124 class ParseError(Hint, Exception):
133 125 """Raised when parsing config files and {rev,file}sets (msg[, pos])"""
134 126 __bytes__ = _tobytes
135 127
136 128 class PatchError(Exception):
137 129 __bytes__ = _tobytes
138 130
139 131 class UnknownIdentifier(ParseError):
140 132 """Exception raised when a {rev,file}set references an unknown identifier"""
141 133
142 134 def __init__(self, function, symbols):
143 135 from .i18n import _
144 136 ParseError.__init__(self, _("unknown identifier: %s") % function)
145 137 self.function = function
146 138 self.symbols = symbols
147 139
148 140 class RepoError(Hint, Exception):
149 141 __bytes__ = _tobytes
150 142
151 143 class RepoLookupError(RepoError):
152 144 pass
153 145
154 146 class FilteredRepoLookupError(RepoLookupError):
155 147 pass
156 148
157 149 class CapabilityError(RepoError):
158 150 pass
159 151
160 152 class RequirementError(RepoError):
161 153 """Exception raised if .hg/requires has an unknown entry."""
162 154
163 155 class StdioError(IOError):
164 156 """Raised if I/O to stdout or stderr fails"""
165 157
166 158 def __init__(self, err):
167 159 IOError.__init__(self, err.errno, err.strerror)
168 160
169 161 # no __bytes__() because error message is derived from the standard IOError
170 162
171 163 class UnsupportedMergeRecords(Abort):
172 164 def __init__(self, recordtypes):
173 165 from .i18n import _
174 166 self.recordtypes = sorted(recordtypes)
175 167 s = ' '.join(self.recordtypes)
176 168 Abort.__init__(
177 169 self, _('unsupported merge state records: %s') % s,
178 170 hint=_('see https://mercurial-scm.org/wiki/MergeStateRecords for '
179 171 'more information'))
180 172
181 173 class UnknownVersion(Abort):
182 174 """generic exception for aborting from an encounter with an unknown version
183 175 """
184 176
185 177 def __init__(self, msg, hint=None, version=None):
186 178 self.version = version
187 179 super(UnknownVersion, self).__init__(msg, hint=hint)
188 180
189 181 class LockError(IOError):
190 182 def __init__(self, errno, strerror, filename, desc):
191 183 IOError.__init__(self, errno, strerror, filename)
192 184 self.desc = desc
193 185
194 186 # no __bytes__() because error message is derived from the standard IOError
195 187
196 188 class LockHeld(LockError):
197 189 def __init__(self, errno, filename, desc, locker):
198 190 LockError.__init__(self, errno, 'Lock held', filename, desc)
199 191 self.locker = locker
200 192
201 193 class LockUnavailable(LockError):
202 194 pass
203 195
204 196 # LockError is for errors while acquiring the lock -- this is unrelated
205 197 class LockInheritanceContractViolation(RuntimeError):
206 198 __bytes__ = _tobytes
207 199
208 200 class ResponseError(Exception):
209 201 """Raised to print an error with part of output and exit."""
210 202 __bytes__ = _tobytes
211 203
212 204 class UnknownCommand(Exception):
213 205 """Exception raised if command is not in the command table."""
214 206 __bytes__ = _tobytes
215 207
216 208 class AmbiguousCommand(Exception):
217 209 """Exception raised if command shortcut matches more than one command."""
218 210 __bytes__ = _tobytes
219 211
220 212 # derived from KeyboardInterrupt to simplify some breakout code
221 213 class SignalInterrupt(KeyboardInterrupt):
222 214 """Exception raised on SIGTERM and SIGHUP."""
223 215
224 216 class SignatureError(Exception):
225 217 __bytes__ = _tobytes
226 218
227 219 class PushRaced(RuntimeError):
228 220 """An exception raised during unbundling that indicate a push race"""
229 221 __bytes__ = _tobytes
230 222
231 223 class ProgrammingError(Hint, RuntimeError):
232 224 """Raised if a mercurial (core or extension) developer made a mistake"""
233 225
234 226 def __init__(self, msg, *args, **kwargs):
235 227 # On Python 3, turn the message back into a string since this is
236 228 # an internal-only error that won't be printed except in a
237 229 # stack traces.
238 230 msg = pycompat.sysstr(msg)
239 231 super(ProgrammingError, self).__init__(msg, *args, **kwargs)
240 232
241 233 __bytes__ = _tobytes
242 234
243 235 class WdirUnsupported(Exception):
244 236 """An exception which is raised when 'wdir()' is not supported"""
245 237 __bytes__ = _tobytes
246 238
247 239 # bundle2 related errors
248 240 class BundleValueError(ValueError):
249 241 """error raised when bundle2 cannot be processed"""
250 242 __bytes__ = _tobytes
251 243
252 244 class BundleUnknownFeatureError(BundleValueError):
253 245 def __init__(self, parttype=None, params=(), values=()):
254 246 self.parttype = parttype
255 247 self.params = params
256 248 self.values = values
257 249 if self.parttype is None:
258 250 msg = 'Stream Parameter'
259 251 else:
260 252 msg = parttype
261 253 entries = self.params
262 254 if self.params and self.values:
263 255 assert len(self.params) == len(self.values)
264 256 entries = []
265 257 for idx, par in enumerate(self.params):
266 258 val = self.values[idx]
267 259 if val is None:
268 260 entries.append(val)
269 261 else:
270 262 entries.append("%s=%r" % (par, pycompat.maybebytestr(val)))
271 263 if entries:
272 264 msg = '%s - %s' % (msg, ', '.join(entries))
273 265 ValueError.__init__(self, msg)
274 266
275 267 class ReadOnlyPartError(RuntimeError):
276 268 """error raised when code tries to alter a part being generated"""
277 269 __bytes__ = _tobytes
278 270
279 271 class PushkeyFailed(Abort):
280 272 """error raised when a pushkey part failed to update a value"""
281 273
282 274 def __init__(self, partid, namespace=None, key=None, new=None, old=None,
283 275 ret=None):
284 276 self.partid = partid
285 277 self.namespace = namespace
286 278 self.key = key
287 279 self.new = new
288 280 self.old = old
289 281 self.ret = ret
290 282 # no i18n expected to be processed into a better message
291 283 Abort.__init__(self, 'failed to update value for "%s/%s"'
292 284 % (namespace, key))
293 285
294 286 class CensoredNodeError(StorageError):
295 287 """error raised when content verification fails on a censored node
296 288
297 289 Also contains the tombstone data substituted for the uncensored data.
298 290 """
299 291
300 292 def __init__(self, filename, node, tombstone):
301 293 from .node import short
302 294 StorageError.__init__(self, '%s:%s' % (filename, short(node)))
303 295 self.tombstone = tombstone
304 296
305 297 class CensoredBaseError(StorageError):
306 298 """error raised when a delta is rejected because its base is censored
307 299
308 300 A delta based on a censored revision must be formed as single patch
309 301 operation which replaces the entire base with new content. This ensures
310 302 the delta may be applied by clones which have not censored the base.
311 303 """
312 304
313 305 class InvalidBundleSpecification(Exception):
314 306 """error raised when a bundle specification is invalid.
315 307
316 308 This is used for syntax errors as opposed to support errors.
317 309 """
318 310 __bytes__ = _tobytes
319 311
320 312 class UnsupportedBundleSpecification(Exception):
321 313 """error raised when a bundle specification is not supported."""
322 314 __bytes__ = _tobytes
323 315
324 316 class CorruptedState(Exception):
325 317 """error raised when a command is not able to read its state from file"""
326 318 __bytes__ = _tobytes
327 319
328 320 class PeerTransportError(Abort):
329 321 """Transport-level I/O error when communicating with a peer repo."""
330 322
331 323 class InMemoryMergeConflictsError(Exception):
332 324 """Exception raised when merge conflicts arose during an in-memory merge."""
333 325 __bytes__ = _tobytes
334 326
335 327 class WireprotoCommandError(Exception):
336 328 """Represents an error during execution of a wire protocol command.
337 329
338 330 Should only be thrown by wire protocol version 2 commands.
339 331
340 332 The error is a formatter string and an optional iterable of arguments.
341 333 """
342 334 def __init__(self, message, args=None):
343 335 self.message = message
344 336 self.messageargs = args
General Comments 0
You need to be logged in to leave comments. Login now