blob: 6825ae14ca8be603fef9f6e1ecacbed366cf0edf [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
apwf2c66602006-04-27 14:11:25 +00008class JobContinue(SystemExit):
mblighc86b0b42006-07-28 17:35:28 +00009 """Allow us to bail out requesting continuance."""
apwf2c66602006-04-27 14:11:25 +000010 pass
11
apw6c262cc2006-04-22 10:30:33 +000012class AutotestError(Exception):
mblighc86b0b42006-07-28 17:35:28 +000013 """The parent of all errors deliberatly thrown within the client code."""
apwfd2baa92006-04-04 08:48:59 +000014 pass
apw6c262cc2006-04-22 10:30:33 +000015
apw6c262cc2006-04-22 10:30:33 +000016class JobError(AutotestError):
mblighc86b0b42006-07-28 17:35:28 +000017 """Indicates an error which terminates and fails the whole job."""
apwfd2baa92006-04-04 08:48:59 +000018 pass
apw6c262cc2006-04-22 10:30:33 +000019
apw6c262cc2006-04-22 10:30:33 +000020class TestError(AutotestError):
mblighc86b0b42006-07-28 17:35:28 +000021 """Indicates an error which terminates and fails the test."""
apw6c262cc2006-04-22 10:30:33 +000022 pass
23
apwbc2867d2006-04-06 18:21:16 +000024class CmdError(TestError):
mblighc86b0b42006-07-28 17:35:28 +000025 """Indicates that a command failed, is fatal to the test unless caught."""
apwbc2867d2006-04-06 18:21:16 +000026 def __str__(self):
mbligh3a6d6ca2006-04-23 15:50:24 +000027 return "Command <" + self.args[0] + "> failed, rc=%d" % (self.args[1])
apw9b634582006-04-22 12:40:39 +000028
apw9b634582006-04-22 12:40:39 +000029class UnhandledError(TestError):
mblighc86b0b42006-07-28 17:35:28 +000030 """Indicates an unhandled exception in a test."""
apw9b634582006-04-22 12:40:39 +000031 def __init__(self, prefix):
32 t, o, tb = sys.exc_info()
33 trace = format_exception(t, o, tb)
34 # Clear the backtrace to prevent a circular reference
35 # in the heap -- as per tutorial
36 tb = ''
37
38 msg = prefix
39 for line in trace:
40 msg = msg + line
41
42 self.args = msg