##// END OF EJS Templates
errors: let each Abort subclass define its error code...
Martin von Zweigbergk -
r48069:33c0c25d default
parent child Browse files
Show More
@@ -516,10 +516,8 class chgcmdserver(commandserver.server)
516 516 self.ui.error(_(b"(%s)\n") % inst.hint)
517 517 errorraised = True
518 518 except error.Abort as inst:
519 if isinstance(inst, error.InputError):
520 detailed_exit_code = 10
521 elif isinstance(inst, error.ConfigError):
522 detailed_exit_code = 30
519 if inst.detailed_exit_code is not None:
520 detailed_exit_code = inst.detailed_exit_code
523 521 self.ui.error(inst.format())
524 522 errorraised = True
525 523
@@ -185,10 +185,11 class ConflictResolutionRequired(Interve
185 185 class Abort(Hint, Exception):
186 186 """Raised if a command needs to print an error and exit."""
187 187
188 def __init__(self, message, hint=None):
188 def __init__(self, message, hint=None, detailed_exit_code=None):
189 189 # type: (bytes, Optional[bytes]) -> None
190 190 self.message = message
191 191 self.hint = hint
192 self.detailed_exit_code = detailed_exit_code
192 193 # Pass the message into the Exception constructor to help extensions
193 194 # that look for exc.args[0].
194 195 Exception.__init__(self, message)
@@ -220,6 +221,11 class InputError(Abort):
220 221 Examples: Invalid command, invalid flags, invalid revision.
221 222 """
222 223
224 def __init__(self, message, hint=None):
225 super(InputError, self).__init__(
226 message, hint=hint, detailed_exit_code=10
227 )
228
223 229
224 230 class StateError(Abort):
225 231 """Indicates that the operation might work if retried in a different state.
@@ -227,6 +233,11 class StateError(Abort):
227 233 Examples: Unresolved merge conflicts, unfinished operations.
228 234 """
229 235
236 def __init__(self, message, hint=None):
237 super(StateError, self).__init__(
238 message, hint=hint, detailed_exit_code=20
239 )
240
230 241
231 242 class CanceledError(Abort):
232 243 """Indicates that the user canceled the operation.
@@ -234,6 +245,11 class CanceledError(Abort):
234 245 Examples: Close commit editor with error status, quit chistedit.
235 246 """
236 247
248 def __init__(self, message, hint=None):
249 super(CanceledError, self).__init__(
250 message, hint=hint, detailed_exit_code=250
251 )
252
237 253
238 254 class SecurityError(Abort):
239 255 """Indicates that some aspect of security failed.
@@ -242,6 +258,11 class SecurityError(Abort):
242 258 filesystem, mismatched GPG signature, DoS protection.
243 259 """
244 260
261 def __init__(self, message, hint=None):
262 super(SecurityError, self).__init__(
263 message, hint=hint, detailed_exit_code=150
264 )
265
245 266
246 267 class HookLoadError(Abort):
247 268 """raised when loading a hook fails, aborting an operation
@@ -254,13 +275,20 class HookAbort(Abort):
254 275
255 276 Exists to allow more specialized catching."""
256 277
278 def __init__(self, message, hint=None):
279 super(HookAbort, self).__init__(
280 message, hint=hint, detailed_exit_code=40
281 )
282
257 283
258 284 class ConfigError(Abort):
259 285 """Exception raised when parsing config files"""
260 286
261 287 def __init__(self, message, location=None, hint=None):
262 288 # type: (bytes, Optional[bytes], Optional[bytes]) -> None
263 super(ConfigError, self).__init__(message, hint=hint)
289 super(ConfigError, self).__init__(
290 message, hint=hint, detailed_exit_code=30
291 )
264 292 self.location = location
265 293
266 294 def format(self):
@@ -307,6 +335,11 class ResponseExpected(Abort):
307 335 class RemoteError(Abort):
308 336 """Exception raised when interacting with a remote repo fails"""
309 337
338 def __init__(self, message, hint=None):
339 super(RemoteError, self).__init__(
340 message, hint=hint, detailed_exit_code=100
341 )
342
310 343
311 344 class OutOfBandError(RemoteError):
312 345 """Exception raised when a remote repo reports failure"""
@@ -327,7 +360,9 class ParseError(Abort):
327 360
328 361 def __init__(self, message, location=None, hint=None):
329 362 # type: (bytes, Optional[Union[bytes, int]], Optional[bytes]) -> None
330 super(ParseError, self).__init__(message, hint=hint)
363 super(ParseError, self).__init__(
364 message, hint=hint, detailed_exit_code=10
365 )
331 366 self.location = location
332 367
333 368 def format(self):
@@ -212,20 +212,8 def callcatch(ui, func):
212 212 except error.WdirUnsupported:
213 213 ui.error(_(b"abort: working directory revision cannot be specified\n"))
214 214 except error.Abort as inst:
215 if isinstance(inst, (error.InputError, error.ParseError)):
216 detailed_exit_code = 10
217 elif isinstance(inst, error.StateError):
218 detailed_exit_code = 20
219 elif isinstance(inst, error.ConfigError):
220 detailed_exit_code = 30
221 elif isinstance(inst, error.HookAbort):
222 detailed_exit_code = 40
223 elif isinstance(inst, error.RemoteError):
224 detailed_exit_code = 100
225 elif isinstance(inst, error.SecurityError):
226 detailed_exit_code = 150
227 elif isinstance(inst, error.CanceledError):
228 detailed_exit_code = 250
215 if inst.detailed_exit_code is not None:
216 detailed_exit_code = inst.detailed_exit_code
229 217 ui.error(inst.format())
230 218 except error.WorkerError as inst:
231 219 # Don't print a message -- the worker already should have
General Comments 0
You need to be logged in to leave comments. Login now