blob: a40e44dc063e25cc14215839b47167a5446afc1b [file] [log] [blame]
mblighc86b0b42006-07-28 17:35:28 +00001"""
2Internal global error types
3"""
4
apw9b634582006-04-22 12:40:39 +00005import sys
6from traceback import format_exception
7
mbligh2045bd92007-08-29 14:01:51 +00008def format_error():
9 t, o, tb = sys.exc_info()
10 trace = format_exception(t, o, tb)
11 # Clear the backtrace to prevent a circular reference
12 # in the heap -- as per tutorial
13 tb = ''
14
15 return ''.join(trace)
16
apwf2c66602006-04-27 14:11:25 +000017class JobContinue(SystemExit):
mblighc86b0b42006-07-28 17:35:28 +000018 """Allow us to bail out requesting continuance."""
apwf2c66602006-04-27 14:11:25 +000019 pass
20
apw6c262cc2006-04-22 10:30:33 +000021class AutotestError(Exception):
mblighc86b0b42006-07-28 17:35:28 +000022 """The parent of all errors deliberatly thrown within the client code."""
apwfd2baa92006-04-04 08:48:59 +000023 pass
apw6c262cc2006-04-22 10:30:33 +000024
apw6c262cc2006-04-22 10:30:33 +000025class JobError(AutotestError):
mblighc86b0b42006-07-28 17:35:28 +000026 """Indicates an error which terminates and fails the whole job."""
apwfd2baa92006-04-04 08:48:59 +000027 pass
apw6c262cc2006-04-22 10:30:33 +000028
apw6c262cc2006-04-22 10:30:33 +000029class TestError(AutotestError):
mblighc86b0b42006-07-28 17:35:28 +000030 """Indicates an error which terminates and fails the test."""
apw6c262cc2006-04-22 10:30:33 +000031 pass
32
apwbc2867d2006-04-06 18:21:16 +000033class CmdError(TestError):
mblighc86b0b42006-07-28 17:35:28 +000034 """Indicates that a command failed, is fatal to the test unless caught."""
apwbc2867d2006-04-06 18:21:16 +000035 def __str__(self):
mbligh3a6d6ca2006-04-23 15:50:24 +000036 return "Command <" + self.args[0] + "> failed, rc=%d" % (self.args[1])
apw9b634582006-04-22 12:40:39 +000037
mblighf912c442007-11-05 16:31:08 +000038class PackageError(TestError):
39 """Indicates an error trying to perform a package operation."""
40
apw9b634582006-04-22 12:40:39 +000041class UnhandledError(TestError):
mblighc86b0b42006-07-28 17:35:28 +000042 """Indicates an unhandled exception in a test."""
apw9b634582006-04-22 12:40:39 +000043 def __init__(self, prefix):
mbligh2045bd92007-08-29 14:01:51 +000044 self.args = prefix + format_error()