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