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