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