mbligh | c86b0b4 | 2006-07-28 17:35:28 +0000 | [diff] [blame] | 1 | """ |
| 2 | Internal global error types |
| 3 | """ |
| 4 | |
apw | 9b63458 | 2006-04-22 12:40:39 +0000 | [diff] [blame] | 5 | import sys |
| 6 | from traceback import format_exception |
| 7 | |
mbligh | 2045bd9 | 2007-08-29 14:01:51 +0000 | [diff] [blame] | 8 | def 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 | |
apw | f2c6660 | 2006-04-27 14:11:25 +0000 | [diff] [blame] | 17 | class JobContinue(SystemExit): |
mbligh | c86b0b4 | 2006-07-28 17:35:28 +0000 | [diff] [blame] | 18 | """Allow us to bail out requesting continuance.""" |
apw | f2c6660 | 2006-04-27 14:11:25 +0000 | [diff] [blame] | 19 | pass |
| 20 | |
apw | b832e1b | 2007-11-24 20:24:38 +0000 | [diff] [blame^] | 21 | class JobComplete(SystemExit): |
| 22 | """Allow us to bail out indicating continuation not required.""" |
| 23 | pass |
| 24 | |
apw | 6c262cc | 2006-04-22 10:30:33 +0000 | [diff] [blame] | 25 | class AutotestError(Exception): |
mbligh | c86b0b4 | 2006-07-28 17:35:28 +0000 | [diff] [blame] | 26 | """The parent of all errors deliberatly thrown within the client code.""" |
apw | fd2baa9 | 2006-04-04 08:48:59 +0000 | [diff] [blame] | 27 | pass |
apw | 6c262cc | 2006-04-22 10:30:33 +0000 | [diff] [blame] | 28 | |
apw | 6c262cc | 2006-04-22 10:30:33 +0000 | [diff] [blame] | 29 | class JobError(AutotestError): |
mbligh | c86b0b4 | 2006-07-28 17:35:28 +0000 | [diff] [blame] | 30 | """Indicates an error which terminates and fails the whole job.""" |
apw | fd2baa9 | 2006-04-04 08:48:59 +0000 | [diff] [blame] | 31 | pass |
apw | 6c262cc | 2006-04-22 10:30:33 +0000 | [diff] [blame] | 32 | |
apw | 6c262cc | 2006-04-22 10:30:33 +0000 | [diff] [blame] | 33 | class TestError(AutotestError): |
mbligh | c86b0b4 | 2006-07-28 17:35:28 +0000 | [diff] [blame] | 34 | """Indicates an error which terminates and fails the test.""" |
apw | 6c262cc | 2006-04-22 10:30:33 +0000 | [diff] [blame] | 35 | pass |
| 36 | |
apw | bc2867d | 2006-04-06 18:21:16 +0000 | [diff] [blame] | 37 | class CmdError(TestError): |
mbligh | c86b0b4 | 2006-07-28 17:35:28 +0000 | [diff] [blame] | 38 | """Indicates that a command failed, is fatal to the test unless caught.""" |
apw | bc2867d | 2006-04-06 18:21:16 +0000 | [diff] [blame] | 39 | def __str__(self): |
mbligh | 3a6d6ca | 2006-04-23 15:50:24 +0000 | [diff] [blame] | 40 | return "Command <" + self.args[0] + "> failed, rc=%d" % (self.args[1]) |
apw | 9b63458 | 2006-04-22 12:40:39 +0000 | [diff] [blame] | 41 | |
mbligh | f912c44 | 2007-11-05 16:31:08 +0000 | [diff] [blame] | 42 | class PackageError(TestError): |
| 43 | """Indicates an error trying to perform a package operation.""" |
| 44 | |
apw | 9b63458 | 2006-04-22 12:40:39 +0000 | [diff] [blame] | 45 | class UnhandledError(TestError): |
mbligh | c86b0b4 | 2006-07-28 17:35:28 +0000 | [diff] [blame] | 46 | """Indicates an unhandled exception in a test.""" |
apw | 9b63458 | 2006-04-22 12:40:39 +0000 | [diff] [blame] | 47 | def __init__(self, prefix): |
mbligh | 2045bd9 | 2007-08-29 14:01:51 +0000 | [diff] [blame] | 48 | self.args = prefix + format_error() |