|
18 | 18 | # You should have received a copy of the GNU Lesser General Public License along |
19 | 19 | # with this program; if not, see <http://www.gnu.org/licenses/>. |
20 | 20 |
|
21 | | -'''Exception hierarchy.''' |
| 21 | +""" |
| 22 | +Qubes OS exception hierarchy |
| 23 | +""" |
22 | 24 |
|
23 | 25 |
|
24 | 26 | class QubesException(Exception): |
25 | | - '''Base exception for all Qubes-related errors.''' |
| 27 | + """Exception that can be shown to the user""" |
| 28 | + |
26 | 29 | def __init__(self, message_format, *args, **kwargs): |
27 | 30 | # TODO: handle translations |
28 | 31 | super().__init__( |
29 | 32 | message_format % tuple(int(d) if d.isdigit() else d for d in args), |
30 | | - **kwargs) |
| 33 | + **kwargs |
| 34 | + ) |
31 | 35 |
|
32 | 36 |
|
33 | 37 | class QubesVMNotFoundError(QubesException, KeyError): |
34 | | - '''Domain cannot be found in the system''' |
| 38 | + """Domain cannot be found in the system""" |
35 | 39 |
|
36 | 40 | def __str__(self): |
37 | 41 | # KeyError overrides __str__ method |
38 | 42 | return QubesException.__str__(self) |
39 | 43 |
|
40 | 44 |
|
| 45 | +class QubesVMInvalidUUIDError(QubesException): |
| 46 | + """Domain UUID is invalid""" |
| 47 | + |
| 48 | + |
41 | 49 | class QubesVMError(QubesException): |
42 | | - '''Some problem with domain state.''' |
| 50 | + """Some problem with domain state.""" |
| 51 | + |
| 52 | + |
| 53 | +class QubesVMInUseError(QubesVMError): |
| 54 | + """VM is in use, cannot remove.""" |
43 | 55 |
|
44 | 56 |
|
45 | 57 | class QubesVMNotStartedError(QubesVMError): |
46 | | - '''Domain is not started. |
| 58 | + """Domain is not started. |
47 | 59 |
|
48 | 60 | This exception is thrown when machine is halted, but should be started |
49 | 61 | (that is, either running or paused). |
50 | | - ''' |
| 62 | + """ |
51 | 63 |
|
52 | 64 |
|
53 | 65 | class QubesVMNotRunningError(QubesVMNotStartedError): |
54 | | - '''Domain is not running. |
| 66 | + """Domain is not running. |
55 | 67 |
|
56 | 68 | This exception is thrown when machine should be running but is either |
57 | 69 | halted or paused. |
58 | | - ''' |
| 70 | + """ |
59 | 71 |
|
60 | 72 |
|
61 | 73 | class QubesVMNotPausedError(QubesVMNotStartedError): |
62 | | - '''Domain is not paused. |
| 74 | + """Domain is not paused. |
63 | 75 |
|
64 | 76 | This exception is thrown when machine should be paused, but is not. |
65 | | - ''' |
| 77 | + """ |
66 | 78 |
|
67 | 79 |
|
68 | 80 | class QubesVMNotSuspendedError(QubesVMError): |
69 | | - '''Domain is not suspended. |
| 81 | + """Domain is not suspended. |
70 | 82 |
|
71 | 83 | This exception is thrown when machine should be suspended but is either |
72 | 84 | halted or running. |
73 | | - ''' |
| 85 | + """ |
74 | 86 |
|
75 | 87 |
|
76 | 88 | class QubesVMNotHaltedError(QubesVMError): |
77 | | - '''Domain is not halted. |
| 89 | + """Domain is not halted. |
78 | 90 |
|
79 | 91 | This exception is thrown when machine should be halted, but is not (either |
80 | 92 | running or paused). |
81 | | - ''' |
| 93 | + """ |
82 | 94 |
|
83 | 95 |
|
84 | | -class QubesVMShutdownTimeout(QubesVMError): |
85 | | - ''' Domain shutdown haven't completed in expected timeframe''' |
| 96 | +class QubesVMShutdownTimeoutError(QubesVMError): |
| 97 | + """Domain shutdown timed out.""" |
86 | 98 |
|
87 | 99 |
|
88 | 100 | class QubesNoTemplateError(QubesVMError): |
89 | | - '''Cannot start domain, because there is no template''' |
| 101 | + """Cannot start domain, because there is no template""" |
90 | 102 |
|
91 | 103 |
|
92 | | -class QubesVMInUseError(QubesVMError): |
93 | | - '''VM is in use, cannot remove.''' |
| 104 | +class QubesPoolInUseError(QubesException): |
| 105 | + """VM is in use, cannot remove.""" |
94 | 106 |
|
95 | 107 |
|
96 | 108 | class QubesValueError(QubesException, ValueError): |
97 | | - '''Cannot set some value, because it is invalid, out of bounds, etc.''' |
| 109 | + """Cannot set some value, because it is invalid, out of bounds, etc.""" |
98 | 110 |
|
99 | 111 |
|
100 | 112 | class QubesPropertyValueError(QubesValueError): |
101 | | - '''Cannot set value of qubes.property, because user-supplied value is wrong. |
102 | | - ''' |
| 113 | + """ |
| 114 | + Cannot set value of qubes.property, because user-supplied value is wrong. |
| 115 | + """ |
103 | 116 |
|
104 | 117 |
|
105 | 118 | class QubesNoSuchPropertyError(QubesException, AttributeError): |
106 | | - '''Requested property does not exist |
107 | | - ''' |
| 119 | + """Requested property does not exist""" |
108 | 120 |
|
109 | 121 |
|
110 | 122 | class QubesNotImplementedError(QubesException, NotImplementedError): |
111 | | - '''Thrown at user when some feature is not implemented''' |
| 123 | + """Thrown at user when some feature is not implemented""" |
112 | 124 |
|
113 | 125 |
|
114 | 126 | class BackupCancelledError(QubesException): |
115 | | - '''Thrown at user when backup was manually cancelled''' |
| 127 | + """Thrown at user when backup was manually cancelled""" |
116 | 128 |
|
117 | 129 |
|
118 | 130 | class BackupAlreadyRunningError(QubesException): |
119 | | - '''Thrown at user when they try to run the same backup twice at |
120 | | - the same time''' |
| 131 | + """Thrown at user when they try to run the same backup twice at |
| 132 | + the same time""" |
121 | 133 |
|
122 | 134 |
|
123 | | -class QubesMemoryError(QubesException, MemoryError): |
124 | | - '''Cannot start domain, because not enough memory is available''' |
| 135 | +class QubesMemoryError(QubesVMError, MemoryError): |
| 136 | + """Cannot start domain, because not enough memory is available""" |
125 | 137 |
|
126 | 138 |
|
127 | 139 | class QubesFeatureNotFoundError(QubesException, KeyError): |
128 | | - '''Feature not set for a given domain''' |
| 140 | + """Feature not set for a given domain""" |
| 141 | + |
129 | 142 | def __str__(self): |
130 | 143 | # KeyError overrides __str__ method |
131 | 144 | return QubesException.__str__(self) |
132 | 145 |
|
133 | 146 |
|
134 | 147 | class QubesTagNotFoundError(QubesException, KeyError): |
135 | | - '''Tag not set for a given domain''' |
| 148 | + """Tag not set for a given domain""" |
| 149 | + |
136 | 150 | def __str__(self): |
137 | 151 | # KeyError overrides __str__ method |
138 | 152 | return QubesException.__str__(self) |
139 | 153 |
|
140 | 154 |
|
141 | 155 | class QubesLabelNotFoundError(QubesException, KeyError): |
142 | 156 | """Label does not exists""" |
| 157 | + |
143 | 158 | def __str__(self): |
144 | 159 | # KeyError overrides __str__ method |
145 | 160 | return QubesException.__str__(self) |
146 | 161 |
|
147 | 162 |
|
148 | | -class StoragePoolException(QubesException): |
149 | | - ''' A general storage exception ''' |
| 163 | +class ProtocolError(AssertionError): |
| 164 | + """Raised when something is wrong with data received""" |
150 | 165 |
|
151 | 166 |
|
152 | | -class QubesDaemonCommunicationError(QubesException): |
153 | | - '''Error while communicating with qubesd, may mean insufficient |
154 | | - permissions as well''' |
| 167 | +class PermissionDenied(Exception): |
| 168 | + """Raised deliberately by handlers when we decide not to cooperate""" |
| 169 | + |
| 170 | + |
| 171 | +class DeviceNotAssigned(QubesException, KeyError): |
| 172 | + """ |
| 173 | + Trying to unassign not assigned device. |
| 174 | + """ |
155 | 175 |
|
156 | 176 |
|
157 | 177 | class DeviceAlreadyAttached(QubesException, KeyError): |
158 | | - '''Trying to attach already attached device''' |
159 | | - def __str__(self): |
160 | | - # KeyError overrides __str__ method |
161 | | - return QubesException.__str__(self) |
| 178 | + """ |
| 179 | + Trying to attach already attached device. |
| 180 | + """ |
| 181 | + |
| 182 | + |
| 183 | +class DeviceAlreadyAssigned(QubesException, KeyError): |
| 184 | + """ |
| 185 | + Trying to assign already assigned device. |
| 186 | + """ |
| 187 | + |
| 188 | + |
| 189 | +class UnrecognizedDevice(QubesException, ValueError): |
| 190 | + """ |
| 191 | + Device identity is not as expected. |
| 192 | + """ |
| 193 | + |
| 194 | + |
| 195 | +class UnexpectedDeviceProperty(QubesException, ValueError): |
| 196 | + """ |
| 197 | + Device has unexpected property such as backend_domain, devclass etc. |
| 198 | + """ |
| 199 | + |
| 200 | + |
| 201 | +class StoragePoolException(QubesException): |
| 202 | + """A general storage exception""" |
| 203 | + |
| 204 | + |
| 205 | +### core-admin-client specific exceptions: |
| 206 | + |
| 207 | + |
| 208 | +class QubesDaemonCommunicationError(QubesException): |
| 209 | + """Error while communicating with qubesd, may mean insufficient |
| 210 | + permissions as well""" |
162 | 211 |
|
163 | 212 |
|
164 | 213 | class BackupRestoreError(QubesException): |
165 | | - '''Restoring a backup failed''' |
| 214 | + """Restoring a backup failed""" |
| 215 | + |
166 | 216 | def __init__(self, msg, backup_log=None): |
167 | 217 | super().__init__(msg) |
168 | 218 | self.backup_log = backup_log |
169 | 219 |
|
| 220 | + |
170 | 221 | # pylint: disable=too-many-ancestors |
171 | 222 | class QubesDaemonAccessError(QubesDaemonCommunicationError): |
172 | | - '''Got empty response from qubesd. This can be lack of permission, |
173 | | - or some server-side issue.''' |
| 223 | + """Got empty response from qubesd. This can be lack of permission, |
| 224 | + or some server-side issue.""" |
174 | 225 |
|
175 | 226 |
|
176 | 227 | class QubesPropertyAccessError(QubesDaemonAccessError, AttributeError): |
177 | | - '''Failed to read/write property value, cause is unknown (insufficient |
178 | | - permissions, no such property, invalid value, other)''' |
| 228 | + """Failed to read/write property value, cause is unknown (insufficient |
| 229 | + permissions, no such property, invalid value, other)""" |
| 230 | + |
179 | 231 | def __init__(self, prop): |
180 | | - super().__init__('Failed to access \'%s\' property' % prop) |
| 232 | + super().__init__("Failed to access '%s' property" % prop) |
| 233 | + |
181 | 234 |
|
182 | 235 | # legacy name |
183 | 236 | QubesDaemonNoResponseError = QubesDaemonAccessError |
0 commit comments