blob: 7cc0f6431f71e9d4f62c851c653162852a03bb80 [file] [log] [blame]
Kuang-che Wue121fae2018-11-09 16:18:39 +08001# -*- 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
8class 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
22class ExecutionFatalError(Exception):
23 """Fatal error and bisect should not continue.
24
25 Switch or eval commands return fatal exit code.
26 """
27
28
29class NoDutAvailable(Exception):
30 """Unable to allocate DUT from lab."""
31
32
33class 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
47class 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 Wu1dc5bd72019-01-19 00:14:46 +080063class VerifyOldBehaviorFailed(VerificationFailed):
Kuang-che Wue121fae2018-11-09 16:18:39 +080064 """Old version does not behave as old."""
65
66 def __init__(self, rev, bad_times=1):
Kuang-che Wu1dc5bd72019-01-19 00:14:46 +080067 super(VerifyOldBehaviorFailed, self).__init__(rev, 'old', 'new', bad_times)
Kuang-che Wue121fae2018-11-09 16:18:39 +080068
69
Kuang-che Wu1dc5bd72019-01-19 00:14:46 +080070class VerifyNewBehaviorFailed(VerificationFailed):
Kuang-che Wue121fae2018-11-09 16:18:39 +080071 """New version does not behave as new."""
72
73 def __init__(self, rev, bad_times=1):
Kuang-che Wu1dc5bd72019-01-19 00:14:46 +080074 super(VerifyNewBehaviorFailed, self).__init__(rev, 'new', 'old', bad_times)
Kuang-che Wue121fae2018-11-09 16:18:39 +080075
76
77class UnableToProceed(Exception):
78 """Unable to narrow bisect range further due to too many errors."""
79
80
81class 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
89class ExternalError(Exception):
Kuang-che Wu8b654092018-11-09 17:56:25 +080090 """Errors in external dependency.
Kuang-che Wue121fae2018-11-09 16:18:39 +080091
92 Like configuration errors, network errors, DUT issues, etc.
93 """
Kuang-che Wu44278142019-03-04 11:33:57 +080094
95
96class SshConnectionError(Exception):
97 """SSH connection error."""