Kuang-che Wu | e121fae | 2018-11-09 16:18:39 +0800 | [diff] [blame] | 1 | # -*- coding: utf-8 -*- |
| 2 | # Copyright 2018 The Chromium OS Authors. All rights reserved. |
| 3 | # Use of this source code is governed by a BSD-style license that can be |
| 4 | # found in the LICENSE file. |
| 5 | """Exception classes.""" |
| 6 | |
| 7 | |
| 8 | class ArgumentError(Exception): |
| 9 | """Bad command line argument.""" |
| 10 | |
| 11 | def __init__(self, argument_name, message): |
| 12 | self.argument_name = argument_name |
| 13 | self.message = message |
| 14 | super(ArgumentError, self).__init__(str(self)) |
| 15 | |
| 16 | def __str__(self): |
| 17 | if self.argument_name: |
| 18 | return 'argument %s: %s' % (self.argument_name, self.message) |
| 19 | return self.message |
| 20 | |
| 21 | |
| 22 | class ExecutionFatalError(Exception): |
| 23 | """Fatal error and bisect should not continue. |
| 24 | |
| 25 | Switch or eval commands return fatal exit code. |
| 26 | """ |
| 27 | |
| 28 | |
| 29 | class NoDutAvailable(Exception): |
| 30 | """Unable to allocate DUT from lab.""" |
| 31 | |
| 32 | |
| 33 | class WrongAssumption(Exception): |
| 34 | """Wrong assumption. |
| 35 | |
| 36 | For non-noisy binary search, the assumption is all versions with old behavior |
| 37 | occurs before all versions with new behavior. But the eval result contracted |
| 38 | this ordering assumption. |
| 39 | |
| 40 | p.s. This only happens (could be detected) if users marked versions 'old' and |
| 41 | 'new' manually. |
| 42 | |
| 43 | Suggestion: try noisy search instead (--noisy). |
| 44 | """ |
| 45 | |
| 46 | |
| 47 | class VerificationFailed(Exception): |
| 48 | """Bisection range is verified false.""" |
| 49 | |
| 50 | def __init__(self, rev, expect, actual, bad_times=1): |
| 51 | self.rev = rev |
| 52 | self.expect = expect |
| 53 | self.actual = actual |
| 54 | self.bad_times = bad_times |
| 55 | |
| 56 | msg = 'rev=%s expect "%s" but got "%s"' % (self.rev, self.expect, |
| 57 | self.actual) |
| 58 | if self.bad_times > 1: |
| 59 | msg += ' %d times' % self.bad_times |
| 60 | super(VerificationFailed, self).__init__(msg) |
| 61 | |
| 62 | |
Kuang-che Wu | 1dc5bd7 | 2019-01-19 00:14:46 +0800 | [diff] [blame] | 63 | class VerifyOldBehaviorFailed(VerificationFailed): |
Kuang-che Wu | e121fae | 2018-11-09 16:18:39 +0800 | [diff] [blame] | 64 | """Old version does not behave as old.""" |
| 65 | |
| 66 | def __init__(self, rev, bad_times=1): |
Kuang-che Wu | 1dc5bd7 | 2019-01-19 00:14:46 +0800 | [diff] [blame] | 67 | super(VerifyOldBehaviorFailed, self).__init__(rev, 'old', 'new', bad_times) |
Kuang-che Wu | e121fae | 2018-11-09 16:18:39 +0800 | [diff] [blame] | 68 | |
| 69 | |
Kuang-che Wu | 1dc5bd7 | 2019-01-19 00:14:46 +0800 | [diff] [blame] | 70 | class VerifyNewBehaviorFailed(VerificationFailed): |
Kuang-che Wu | e121fae | 2018-11-09 16:18:39 +0800 | [diff] [blame] | 71 | """New version does not behave as new.""" |
| 72 | |
| 73 | def __init__(self, rev, bad_times=1): |
Kuang-che Wu | 1dc5bd7 | 2019-01-19 00:14:46 +0800 | [diff] [blame] | 74 | super(VerifyNewBehaviorFailed, self).__init__(rev, 'new', 'old', bad_times) |
Kuang-che Wu | e121fae | 2018-11-09 16:18:39 +0800 | [diff] [blame] | 75 | |
| 76 | |
| 77 | class UnableToProceed(Exception): |
| 78 | """Unable to narrow bisect range further due to too many errors.""" |
| 79 | |
| 80 | |
| 81 | class InternalError(Exception): |
| 82 | """bisect-kit internal error. |
| 83 | |
| 84 | In general, it means something wrong or not implemented in bisect-kit and |
| 85 | needs fix. |
| 86 | """ |
| 87 | |
| 88 | |
| 89 | class ExternalError(Exception): |
Kuang-che Wu | 8b65409 | 2018-11-09 17:56:25 +0800 | [diff] [blame] | 90 | """Errors in external dependency. |
Kuang-che Wu | e121fae | 2018-11-09 16:18:39 +0800 | [diff] [blame] | 91 | |
| 92 | Like configuration errors, network errors, DUT issues, etc. |
| 93 | """ |