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