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