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 | |||||
apw | f2c6660 | 2006-04-27 14:11:25 +0000 | [diff] [blame] | 8 | class JobContinue(SystemExit): |
mbligh | c86b0b4 | 2006-07-28 17:35:28 +0000 | [diff] [blame] | 9 | """Allow us to bail out requesting continuance.""" |
apw | f2c6660 | 2006-04-27 14:11:25 +0000 | [diff] [blame] | 10 | pass |
11 | |||||
apw | 6c262cc | 2006-04-22 10:30:33 +0000 | [diff] [blame] | 12 | class AutotestError(Exception): |
mbligh | c86b0b4 | 2006-07-28 17:35:28 +0000 | [diff] [blame] | 13 | """The parent of all errors deliberatly thrown within the client code.""" |
apw | fd2baa9 | 2006-04-04 08:48:59 +0000 | [diff] [blame] | 14 | pass |
apw | 6c262cc | 2006-04-22 10:30:33 +0000 | [diff] [blame] | 15 | |
apw | 6c262cc | 2006-04-22 10:30:33 +0000 | [diff] [blame] | 16 | class JobError(AutotestError): |
mbligh | c86b0b4 | 2006-07-28 17:35:28 +0000 | [diff] [blame] | 17 | """Indicates an error which terminates and fails the whole job.""" |
apw | fd2baa9 | 2006-04-04 08:48:59 +0000 | [diff] [blame] | 18 | pass |
apw | 6c262cc | 2006-04-22 10:30:33 +0000 | [diff] [blame] | 19 | |
apw | 6c262cc | 2006-04-22 10:30:33 +0000 | [diff] [blame] | 20 | class TestError(AutotestError): |
mbligh | c86b0b4 | 2006-07-28 17:35:28 +0000 | [diff] [blame] | 21 | """Indicates an error which terminates and fails the test.""" |
apw | 6c262cc | 2006-04-22 10:30:33 +0000 | [diff] [blame] | 22 | pass |
23 | |||||
apw | bc2867d | 2006-04-06 18:21:16 +0000 | [diff] [blame] | 24 | class CmdError(TestError): |
mbligh | c86b0b4 | 2006-07-28 17:35:28 +0000 | [diff] [blame] | 25 | """Indicates that a command failed, is fatal to the test unless caught.""" |
apw | bc2867d | 2006-04-06 18:21:16 +0000 | [diff] [blame] | 26 | def __str__(self): |
mbligh | 3a6d6ca | 2006-04-23 15:50:24 +0000 | [diff] [blame] | 27 | return "Command <" + self.args[0] + "> failed, rc=%d" % (self.args[1]) |
apw | 9b63458 | 2006-04-22 12:40:39 +0000 | [diff] [blame] | 28 | |
apw | 9b63458 | 2006-04-22 12:40:39 +0000 | [diff] [blame] | 29 | class UnhandledError(TestError): |
mbligh | c86b0b4 | 2006-07-28 17:35:28 +0000 | [diff] [blame] | 30 | """Indicates an unhandled exception in a test.""" |
apw | 9b63458 | 2006-04-22 12:40:39 +0000 | [diff] [blame] | 31 | 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 |