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 | |
Kuang-che Wu | 96e4276 | 2020-07-01 16:38:37 +0800 | [diff] [blame] | 22 | class Uninitialized(Exception): |
| 23 | """'init' must succeed before other subcommands.""" |
| 24 | |
| 25 | |
Kuang-che Wu | e121fae | 2018-11-09 16:18:39 +0800 | [diff] [blame] | 26 | class ExecutionFatalError(Exception): |
| 27 | """Fatal error and bisect should not continue. |
| 28 | |
| 29 | Switch or eval commands return fatal exit code. |
| 30 | """ |
| 31 | |
| 32 | |
| 33 | class NoDutAvailable(Exception): |
| 34 | """Unable to allocate DUT from lab.""" |
| 35 | |
| 36 | |
Kuang-che Wu | 0c9b794 | 2019-10-30 16:55:39 +0800 | [diff] [blame] | 37 | class DutLeaseException(Exception): |
| 38 | """Issues of skylab DUT lease.""" |
| 39 | |
| 40 | |
Kuang-che Wu | e121fae | 2018-11-09 16:18:39 +0800 | [diff] [blame] | 41 | class WrongAssumption(Exception): |
| 42 | """Wrong assumption. |
| 43 | |
| 44 | For non-noisy binary search, the assumption is all versions with old behavior |
| 45 | occurs before all versions with new behavior. But the eval result contracted |
| 46 | this ordering assumption. |
| 47 | |
| 48 | p.s. This only happens (could be detected) if users marked versions 'old' and |
| 49 | 'new' manually. |
| 50 | |
| 51 | Suggestion: try noisy search instead (--noisy). |
| 52 | """ |
| 53 | |
| 54 | |
Kuang-che Wu | ec566f3 | 2019-03-07 16:53:32 +0800 | [diff] [blame] | 55 | class DiagnoseContradiction(Exception): |
| 56 | """Contradiction happened during diagnose. |
| 57 | |
| 58 | Test result of individual component/version is unreliable/untrustable |
| 59 | (something wrong and/or flakiness out of control). |
| 60 | """ |
| 61 | |
| 62 | |
Kuang-che Wu | e121fae | 2018-11-09 16:18:39 +0800 | [diff] [blame] | 63 | class VerificationFailed(Exception): |
| 64 | """Bisection range is verified false.""" |
| 65 | |
| 66 | def __init__(self, rev, expect, actual, bad_times=1): |
| 67 | self.rev = rev |
| 68 | self.expect = expect |
| 69 | self.actual = actual |
| 70 | self.bad_times = bad_times |
| 71 | |
| 72 | msg = 'rev=%s expect "%s" but got "%s"' % (self.rev, self.expect, |
| 73 | self.actual) |
| 74 | if self.bad_times > 1: |
| 75 | msg += ' %d times' % self.bad_times |
| 76 | super(VerificationFailed, self).__init__(msg) |
| 77 | |
| 78 | |
Kuang-che Wu | 1dc5bd7 | 2019-01-19 00:14:46 +0800 | [diff] [blame] | 79 | class VerifyOldBehaviorFailed(VerificationFailed): |
Kuang-che Wu | e121fae | 2018-11-09 16:18:39 +0800 | [diff] [blame] | 80 | """Old version does not behave as old.""" |
| 81 | |
Kuang-che Wu | 944fda4 | 2019-12-12 20:31:29 +0800 | [diff] [blame] | 82 | def __init__(self, rev, bad_times=1, term_old='OLD', term_new='NEW'): |
| 83 | super(VerifyOldBehaviorFailed, self).__init__(rev, term_old, term_new, |
| 84 | bad_times) |
Kuang-che Wu | e121fae | 2018-11-09 16:18:39 +0800 | [diff] [blame] | 85 | |
| 86 | |
Kuang-che Wu | 1dc5bd7 | 2019-01-19 00:14:46 +0800 | [diff] [blame] | 87 | class VerifyNewBehaviorFailed(VerificationFailed): |
Kuang-che Wu | e121fae | 2018-11-09 16:18:39 +0800 | [diff] [blame] | 88 | """New version does not behave as new.""" |
| 89 | |
Kuang-che Wu | 944fda4 | 2019-12-12 20:31:29 +0800 | [diff] [blame] | 90 | def __init__(self, rev, bad_times=1, term_old='OLD', term_new='NEW'): |
| 91 | super(VerifyNewBehaviorFailed, self).__init__(rev, term_new, term_old, |
| 92 | bad_times) |
Kuang-che Wu | e121fae | 2018-11-09 16:18:39 +0800 | [diff] [blame] | 93 | |
| 94 | |
| 95 | class UnableToProceed(Exception): |
| 96 | """Unable to narrow bisect range further due to too many errors.""" |
| 97 | |
| 98 | |
| 99 | class InternalError(Exception): |
| 100 | """bisect-kit internal error. |
| 101 | |
| 102 | In general, it means something wrong or not implemented in bisect-kit and |
| 103 | needs fix. |
| 104 | """ |
| 105 | |
| 106 | |
| 107 | class ExternalError(Exception): |
Kuang-che Wu | 8b65409 | 2018-11-09 17:56:25 +0800 | [diff] [blame] | 108 | """Errors in external dependency. |
Kuang-che Wu | e121fae | 2018-11-09 16:18:39 +0800 | [diff] [blame] | 109 | |
| 110 | Like configuration errors, network errors, DUT issues, etc. |
| 111 | """ |
Kuang-che Wu | 4427814 | 2019-03-04 11:33:57 +0800 | [diff] [blame] | 112 | |
| 113 | |
| 114 | class SshConnectionError(Exception): |
| 115 | """SSH connection error.""" |