##// END OF EJS Templates
error: use r-string to properly pop hints from **kw...
Augie Fackler -
r31503:0ca00905 default
parent child Browse files
Show More
@@ -1,248 +1,248 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 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('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 UnsupportedMergeRecords(Abort):
125 class UnsupportedMergeRecords(Abort):
126 def __init__(self, recordtypes):
126 def __init__(self, recordtypes):
127 from .i18n import _
127 from .i18n import _
128 self.recordtypes = sorted(recordtypes)
128 self.recordtypes = sorted(recordtypes)
129 s = ' '.join(self.recordtypes)
129 s = ' '.join(self.recordtypes)
130 Abort.__init__(
130 Abort.__init__(
131 self, _('unsupported merge state records: %s') % s,
131 self, _('unsupported merge state records: %s') % s,
132 hint=_('see https://mercurial-scm.org/wiki/MergeStateRecords for '
132 hint=_('see https://mercurial-scm.org/wiki/MergeStateRecords for '
133 'more information'))
133 'more information'))
134
134
135 class LockError(IOError):
135 class LockError(IOError):
136 def __init__(self, errno, strerror, filename, desc):
136 def __init__(self, errno, strerror, filename, desc):
137 IOError.__init__(self, errno, strerror, filename)
137 IOError.__init__(self, errno, strerror, filename)
138 self.desc = desc
138 self.desc = desc
139
139
140 class LockHeld(LockError):
140 class LockHeld(LockError):
141 def __init__(self, errno, filename, desc, locker):
141 def __init__(self, errno, filename, desc, locker):
142 LockError.__init__(self, errno, 'Lock held', filename, desc)
142 LockError.__init__(self, errno, 'Lock held', filename, desc)
143 self.locker = locker
143 self.locker = locker
144
144
145 class LockUnavailable(LockError):
145 class LockUnavailable(LockError):
146 pass
146 pass
147
147
148 # LockError is for errors while acquiring the lock -- this is unrelated
148 # LockError is for errors while acquiring the lock -- this is unrelated
149 class LockInheritanceContractViolation(RuntimeError):
149 class LockInheritanceContractViolation(RuntimeError):
150 pass
150 pass
151
151
152 class ResponseError(Exception):
152 class ResponseError(Exception):
153 """Raised to print an error with part of output and exit."""
153 """Raised to print an error with part of output and exit."""
154
154
155 class UnknownCommand(Exception):
155 class UnknownCommand(Exception):
156 """Exception raised if command is not in the command table."""
156 """Exception raised if command is not in the command table."""
157
157
158 class AmbiguousCommand(Exception):
158 class AmbiguousCommand(Exception):
159 """Exception raised if command shortcut matches more than one command."""
159 """Exception raised if command shortcut matches more than one command."""
160
160
161 # derived from KeyboardInterrupt to simplify some breakout code
161 # derived from KeyboardInterrupt to simplify some breakout code
162 class SignalInterrupt(KeyboardInterrupt):
162 class SignalInterrupt(KeyboardInterrupt):
163 """Exception raised on SIGTERM and SIGHUP."""
163 """Exception raised on SIGTERM and SIGHUP."""
164
164
165 class SignatureError(Exception):
165 class SignatureError(Exception):
166 pass
166 pass
167
167
168 class PushRaced(RuntimeError):
168 class PushRaced(RuntimeError):
169 """An exception raised during unbundling that indicate a push race"""
169 """An exception raised during unbundling that indicate a push race"""
170
170
171 class ProgrammingError(RuntimeError):
171 class ProgrammingError(RuntimeError):
172 """Raised if a mercurial (core or extension) developer made a mistake"""
172 """Raised if a mercurial (core or extension) developer made a mistake"""
173
173
174 # bundle2 related errors
174 # bundle2 related errors
175 class BundleValueError(ValueError):
175 class BundleValueError(ValueError):
176 """error raised when bundle2 cannot be processed"""
176 """error raised when bundle2 cannot be processed"""
177
177
178 class BundleUnknownFeatureError(BundleValueError):
178 class BundleUnknownFeatureError(BundleValueError):
179 def __init__(self, parttype=None, params=(), values=()):
179 def __init__(self, parttype=None, params=(), values=()):
180 self.parttype = parttype
180 self.parttype = parttype
181 self.params = params
181 self.params = params
182 self.values = values
182 self.values = values
183 if self.parttype is None:
183 if self.parttype is None:
184 msg = 'Stream Parameter'
184 msg = 'Stream Parameter'
185 else:
185 else:
186 msg = parttype
186 msg = parttype
187 entries = self.params
187 entries = self.params
188 if self.params and self.values:
188 if self.params and self.values:
189 assert len(self.params) == len(self.values)
189 assert len(self.params) == len(self.values)
190 entries = []
190 entries = []
191 for idx, par in enumerate(self.params):
191 for idx, par in enumerate(self.params):
192 val = self.values[idx]
192 val = self.values[idx]
193 if val is None:
193 if val is None:
194 entries.append(val)
194 entries.append(val)
195 else:
195 else:
196 entries.append("%s=%r" % (par, val))
196 entries.append("%s=%r" % (par, val))
197 if entries:
197 if entries:
198 msg = '%s - %s' % (msg, ', '.join(entries))
198 msg = '%s - %s' % (msg, ', '.join(entries))
199 ValueError.__init__(self, msg)
199 ValueError.__init__(self, msg)
200
200
201 class ReadOnlyPartError(RuntimeError):
201 class ReadOnlyPartError(RuntimeError):
202 """error raised when code tries to alter a part being generated"""
202 """error raised when code tries to alter a part being generated"""
203
203
204 class PushkeyFailed(Abort):
204 class PushkeyFailed(Abort):
205 """error raised when a pushkey part failed to update a value"""
205 """error raised when a pushkey part failed to update a value"""
206
206
207 def __init__(self, partid, namespace=None, key=None, new=None, old=None,
207 def __init__(self, partid, namespace=None, key=None, new=None, old=None,
208 ret=None):
208 ret=None):
209 self.partid = partid
209 self.partid = partid
210 self.namespace = namespace
210 self.namespace = namespace
211 self.key = key
211 self.key = key
212 self.new = new
212 self.new = new
213 self.old = old
213 self.old = old
214 self.ret = ret
214 self.ret = ret
215 # no i18n expected to be processed into a better message
215 # no i18n expected to be processed into a better message
216 Abort.__init__(self, 'failed to update value for "%s/%s"'
216 Abort.__init__(self, 'failed to update value for "%s/%s"'
217 % (namespace, key))
217 % (namespace, key))
218
218
219 class CensoredNodeError(RevlogError):
219 class CensoredNodeError(RevlogError):
220 """error raised when content verification fails on a censored node
220 """error raised when content verification fails on a censored node
221
221
222 Also contains the tombstone data substituted for the uncensored data.
222 Also contains the tombstone data substituted for the uncensored data.
223 """
223 """
224
224
225 def __init__(self, filename, node, tombstone):
225 def __init__(self, filename, node, tombstone):
226 from .node import short
226 from .node import short
227 RevlogError.__init__(self, '%s:%s' % (filename, short(node)))
227 RevlogError.__init__(self, '%s:%s' % (filename, short(node)))
228 self.tombstone = tombstone
228 self.tombstone = tombstone
229
229
230 class CensoredBaseError(RevlogError):
230 class CensoredBaseError(RevlogError):
231 """error raised when a delta is rejected because its base is censored
231 """error raised when a delta is rejected because its base is censored
232
232
233 A delta based on a censored revision must be formed as single patch
233 A delta based on a censored revision must be formed as single patch
234 operation which replaces the entire base with new content. This ensures
234 operation which replaces the entire base with new content. This ensures
235 the delta may be applied by clones which have not censored the base.
235 the delta may be applied by clones which have not censored the base.
236 """
236 """
237
237
238 class InvalidBundleSpecification(Exception):
238 class InvalidBundleSpecification(Exception):
239 """error raised when a bundle specification is invalid.
239 """error raised when a bundle specification is invalid.
240
240
241 This is used for syntax errors as opposed to support errors.
241 This is used for syntax errors as opposed to support errors.
242 """
242 """
243
243
244 class UnsupportedBundleSpecification(Exception):
244 class UnsupportedBundleSpecification(Exception):
245 """error raised when a bundle specification is not supported."""
245 """error raised when a bundle specification is not supported."""
246
246
247 class CorruptedState(Exception):
247 class CorruptedState(Exception):
248 """error raised when a command is not able to read its state from file"""
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