Show More
@@ -1,221 +1,216 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 | pass |
|
|||
59 |
|
58 | |||
60 | class HookLoadError(Abort): |
|
59 | class HookLoadError(Abort): | |
61 | """raised when loading a hook fails, aborting an operation |
|
60 | """raised when loading a hook fails, aborting an operation | |
62 |
|
61 | |||
63 | Exists to allow more specialized catching.""" |
|
62 | Exists to allow more specialized catching.""" | |
64 | pass |
|
|||
65 |
|
63 | |||
66 | class HookAbort(Abort): |
|
64 | class HookAbort(Abort): | |
67 | """raised when a validation hook fails, aborting an operation |
|
65 | """raised when a validation hook fails, aborting an operation | |
68 |
|
66 | |||
69 | Exists to allow more specialized catching.""" |
|
67 | Exists to allow more specialized catching.""" | |
70 | pass |
|
|||
71 |
|
68 | |||
72 | class ConfigError(Abort): |
|
69 | class ConfigError(Abort): | |
73 | """Exception raised when parsing config files""" |
|
70 | """Exception raised when parsing config files""" | |
74 |
|
71 | |||
75 | class UpdateAbort(Abort): |
|
72 | class UpdateAbort(Abort): | |
76 | """Raised when an update is aborted for destination issue""" |
|
73 | """Raised when an update is aborted for destination issue""" | |
77 |
|
74 | |||
78 | class OutOfBandError(Exception): |
|
75 | class OutOfBandError(Exception): | |
79 | """Exception raised when a remote repo reports failure""" |
|
76 | """Exception raised when a remote repo reports failure""" | |
80 |
|
77 | |||
81 | def __init__(self, *args, **kw): |
|
78 | def __init__(self, *args, **kw): | |
82 | Exception.__init__(self, *args) |
|
79 | Exception.__init__(self, *args) | |
83 | self.hint = kw.get('hint') |
|
80 | self.hint = kw.get('hint') | |
84 |
|
81 | |||
85 | class ParseError(Exception): |
|
82 | class ParseError(Exception): | |
86 | """Raised when parsing config files and {rev,file}sets (msg[, pos])""" |
|
83 | """Raised when parsing config files and {rev,file}sets (msg[, pos])""" | |
87 |
|
84 | |||
88 | class UnknownIdentifier(ParseError): |
|
85 | class UnknownIdentifier(ParseError): | |
89 | """Exception raised when a {rev,file}set references an unknown identifier""" |
|
86 | """Exception raised when a {rev,file}set references an unknown identifier""" | |
90 |
|
87 | |||
91 | def __init__(self, function, symbols): |
|
88 | def __init__(self, function, symbols): | |
92 | from .i18n import _ |
|
89 | from .i18n import _ | |
93 | ParseError.__init__(self, _("unknown identifier: %s") % function) |
|
90 | ParseError.__init__(self, _("unknown identifier: %s") % function) | |
94 | self.function = function |
|
91 | self.function = function | |
95 | self.symbols = symbols |
|
92 | self.symbols = symbols | |
96 |
|
93 | |||
97 | class RepoError(HintException): |
|
94 | class RepoError(HintException): | |
98 | pass |
|
95 | pass | |
99 |
|
96 | |||
100 | class RepoLookupError(RepoError): |
|
97 | class RepoLookupError(RepoError): | |
101 | pass |
|
98 | pass | |
102 |
|
99 | |||
103 | class FilteredRepoLookupError(RepoLookupError): |
|
100 | class FilteredRepoLookupError(RepoLookupError): | |
104 | pass |
|
101 | pass | |
105 |
|
102 | |||
106 | class CapabilityError(RepoError): |
|
103 | class CapabilityError(RepoError): | |
107 | pass |
|
104 | pass | |
108 |
|
105 | |||
109 | class RequirementError(RepoError): |
|
106 | class RequirementError(RepoError): | |
110 | """Exception raised if .hg/requires has an unknown entry.""" |
|
107 | """Exception raised if .hg/requires has an unknown entry.""" | |
111 | pass |
|
|||
112 |
|
108 | |||
113 | class LockError(IOError): |
|
109 | class LockError(IOError): | |
114 | def __init__(self, errno, strerror, filename, desc): |
|
110 | def __init__(self, errno, strerror, filename, desc): | |
115 | IOError.__init__(self, errno, strerror, filename) |
|
111 | IOError.__init__(self, errno, strerror, filename) | |
116 | self.desc = desc |
|
112 | self.desc = desc | |
117 |
|
113 | |||
118 | class LockHeld(LockError): |
|
114 | class LockHeld(LockError): | |
119 | def __init__(self, errno, filename, desc, locker): |
|
115 | def __init__(self, errno, filename, desc, locker): | |
120 | LockError.__init__(self, errno, 'Lock held', filename, desc) |
|
116 | LockError.__init__(self, errno, 'Lock held', filename, desc) | |
121 | self.locker = locker |
|
117 | self.locker = locker | |
122 |
|
118 | |||
123 | class LockUnavailable(LockError): |
|
119 | class LockUnavailable(LockError): | |
124 | pass |
|
120 | pass | |
125 |
|
121 | |||
126 | # LockError is for errors while acquiring the lock -- this is unrelated |
|
122 | # LockError is for errors while acquiring the lock -- this is unrelated | |
127 | class LockInheritanceContractViolation(RuntimeError): |
|
123 | class LockInheritanceContractViolation(RuntimeError): | |
128 | pass |
|
124 | pass | |
129 |
|
125 | |||
130 | class ResponseError(Exception): |
|
126 | class ResponseError(Exception): | |
131 | """Raised to print an error with part of output and exit.""" |
|
127 | """Raised to print an error with part of output and exit.""" | |
132 |
|
128 | |||
133 | class UnknownCommand(Exception): |
|
129 | class UnknownCommand(Exception): | |
134 | """Exception raised if command is not in the command table.""" |
|
130 | """Exception raised if command is not in the command table.""" | |
135 |
|
131 | |||
136 | class AmbiguousCommand(Exception): |
|
132 | class AmbiguousCommand(Exception): | |
137 | """Exception raised if command shortcut matches more than one command.""" |
|
133 | """Exception raised if command shortcut matches more than one command.""" | |
138 |
|
134 | |||
139 | # derived from KeyboardInterrupt to simplify some breakout code |
|
135 | # derived from KeyboardInterrupt to simplify some breakout code | |
140 | class SignalInterrupt(KeyboardInterrupt): |
|
136 | class SignalInterrupt(KeyboardInterrupt): | |
141 | """Exception raised on SIGTERM and SIGHUP.""" |
|
137 | """Exception raised on SIGTERM and SIGHUP.""" | |
142 |
|
138 | |||
143 | class SignatureError(Exception): |
|
139 | class SignatureError(Exception): | |
144 | pass |
|
140 | pass | |
145 |
|
141 | |||
146 | class PushRaced(RuntimeError): |
|
142 | class PushRaced(RuntimeError): | |
147 | """An exception raised during unbundling that indicate a push race""" |
|
143 | """An exception raised during unbundling that indicate a push race""" | |
148 |
|
144 | |||
149 | # bundle2 related errors |
|
145 | # bundle2 related errors | |
150 | class BundleValueError(ValueError): |
|
146 | class BundleValueError(ValueError): | |
151 | """error raised when bundle2 cannot be processed""" |
|
147 | """error raised when bundle2 cannot be processed""" | |
152 |
|
148 | |||
153 | class BundleUnknownFeatureError(BundleValueError): |
|
149 | class BundleUnknownFeatureError(BundleValueError): | |
154 | def __init__(self, parttype=None, params=(), values=()): |
|
150 | def __init__(self, parttype=None, params=(), values=()): | |
155 | self.parttype = parttype |
|
151 | self.parttype = parttype | |
156 | self.params = params |
|
152 | self.params = params | |
157 | self.values = values |
|
153 | self.values = values | |
158 | if self.parttype is None: |
|
154 | if self.parttype is None: | |
159 | msg = 'Stream Parameter' |
|
155 | msg = 'Stream Parameter' | |
160 | else: |
|
156 | else: | |
161 | msg = parttype |
|
157 | msg = parttype | |
162 | entries = self.params |
|
158 | entries = self.params | |
163 | if self.params and self.values: |
|
159 | if self.params and self.values: | |
164 | assert len(self.params) == len(self.values) |
|
160 | assert len(self.params) == len(self.values) | |
165 | entries = [] |
|
161 | entries = [] | |
166 | for idx, par in enumerate(self.params): |
|
162 | for idx, par in enumerate(self.params): | |
167 | val = self.values[idx] |
|
163 | val = self.values[idx] | |
168 | if val is None: |
|
164 | if val is None: | |
169 | entries.append(val) |
|
165 | entries.append(val) | |
170 | else: |
|
166 | else: | |
171 | entries.append("%s=%r" % (par, val)) |
|
167 | entries.append("%s=%r" % (par, val)) | |
172 | if entries: |
|
168 | if entries: | |
173 | msg = '%s - %s' % (msg, ', '.join(entries)) |
|
169 | msg = '%s - %s' % (msg, ', '.join(entries)) | |
174 | ValueError.__init__(self, msg) |
|
170 | ValueError.__init__(self, msg) | |
175 |
|
171 | |||
176 | class ReadOnlyPartError(RuntimeError): |
|
172 | class ReadOnlyPartError(RuntimeError): | |
177 | """error raised when code tries to alter a part being generated""" |
|
173 | """error raised when code tries to alter a part being generated""" | |
178 | pass |
|
|||
179 |
|
174 | |||
180 | class PushkeyFailed(Abort): |
|
175 | class PushkeyFailed(Abort): | |
181 | """error raised when a pushkey part failed to update a value""" |
|
176 | """error raised when a pushkey part failed to update a value""" | |
182 |
|
177 | |||
183 | def __init__(self, partid, namespace=None, key=None, new=None, old=None, |
|
178 | def __init__(self, partid, namespace=None, key=None, new=None, old=None, | |
184 | ret=None): |
|
179 | ret=None): | |
185 | self.partid = partid |
|
180 | self.partid = partid | |
186 | self.namespace = namespace |
|
181 | self.namespace = namespace | |
187 | self.key = key |
|
182 | self.key = key | |
188 | self.new = new |
|
183 | self.new = new | |
189 | self.old = old |
|
184 | self.old = old | |
190 | self.ret = ret |
|
185 | self.ret = ret | |
191 | # no i18n expected to be processed into a better message |
|
186 | # no i18n expected to be processed into a better message | |
192 | Abort.__init__(self, 'failed to update value for "%s/%s"' |
|
187 | Abort.__init__(self, 'failed to update value for "%s/%s"' | |
193 | % (namespace, key)) |
|
188 | % (namespace, key)) | |
194 |
|
189 | |||
195 | class CensoredNodeError(RevlogError): |
|
190 | class CensoredNodeError(RevlogError): | |
196 | """error raised when content verification fails on a censored node |
|
191 | """error raised when content verification fails on a censored node | |
197 |
|
192 | |||
198 | Also contains the tombstone data substituted for the uncensored data. |
|
193 | Also contains the tombstone data substituted for the uncensored data. | |
199 | """ |
|
194 | """ | |
200 |
|
195 | |||
201 | def __init__(self, filename, node, tombstone): |
|
196 | def __init__(self, filename, node, tombstone): | |
202 | from .node import short |
|
197 | from .node import short | |
203 | RevlogError.__init__(self, '%s:%s' % (filename, short(node))) |
|
198 | RevlogError.__init__(self, '%s:%s' % (filename, short(node))) | |
204 | self.tombstone = tombstone |
|
199 | self.tombstone = tombstone | |
205 |
|
200 | |||
206 | class CensoredBaseError(RevlogError): |
|
201 | class CensoredBaseError(RevlogError): | |
207 | """error raised when a delta is rejected because its base is censored |
|
202 | """error raised when a delta is rejected because its base is censored | |
208 |
|
203 | |||
209 | A delta based on a censored revision must be formed as single patch |
|
204 | A delta based on a censored revision must be formed as single patch | |
210 | operation which replaces the entire base with new content. This ensures |
|
205 | operation which replaces the entire base with new content. This ensures | |
211 | the delta may be applied by clones which have not censored the base. |
|
206 | the delta may be applied by clones which have not censored the base. | |
212 | """ |
|
207 | """ | |
213 |
|
208 | |||
214 | class InvalidBundleSpecification(Exception): |
|
209 | class InvalidBundleSpecification(Exception): | |
215 | """error raised when a bundle specification is invalid. |
|
210 | """error raised when a bundle specification is invalid. | |
216 |
|
211 | |||
217 | This is used for syntax errors as opposed to support errors. |
|
212 | This is used for syntax errors as opposed to support errors. | |
218 | """ |
|
213 | """ | |
219 |
|
214 | |||
220 | class UnsupportedBundleSpecification(Exception): |
|
215 | class UnsupportedBundleSpecification(Exception): | |
221 | """error raised when a bundle specification is not supported.""" |
|
216 | """error raised when a bundle specification is not supported.""" |
General Comments 0
You need to be logged in to leave comments.
Login now