Skip to content

Commit 88fbf74

Browse files
committed
Synchronize exc.py with core-admin
Especially, add new devices-related exceptions. This is needed for salt to properly handle assigning devices.
1 parent 3f22073 commit 88fbf74

1 file changed

Lines changed: 101 additions & 48 deletions

File tree

qubesadmin/exc.py

Lines changed: 101 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -18,166 +18,219 @@
1818
# You should have received a copy of the GNU Lesser General Public License along
1919
# with this program; if not, see <http://www.gnu.org/licenses/>.
2020

21-
'''Exception hierarchy.'''
21+
"""
22+
Qubes OS exception hierarchy
23+
"""
2224

2325

2426
class QubesException(Exception):
25-
'''Base exception for all Qubes-related errors.'''
27+
"""Exception that can be shown to the user"""
28+
2629
def __init__(self, message_format, *args, **kwargs):
2730
# TODO: handle translations
2831
super().__init__(
2932
message_format % tuple(int(d) if d.isdigit() else d for d in args),
30-
**kwargs)
33+
**kwargs
34+
)
3135

3236

3337
class QubesVMNotFoundError(QubesException, KeyError):
34-
'''Domain cannot be found in the system'''
38+
"""Domain cannot be found in the system"""
3539

3640
def __str__(self):
3741
# KeyError overrides __str__ method
3842
return QubesException.__str__(self)
3943

4044

45+
class QubesVMInvalidUUIDError(QubesException):
46+
"""Domain UUID is invalid"""
47+
48+
4149
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."""
4355

4456

4557
class QubesVMNotStartedError(QubesVMError):
46-
'''Domain is not started.
58+
"""Domain is not started.
4759
4860
This exception is thrown when machine is halted, but should be started
4961
(that is, either running or paused).
50-
'''
62+
"""
5163

5264

5365
class QubesVMNotRunningError(QubesVMNotStartedError):
54-
'''Domain is not running.
66+
"""Domain is not running.
5567
5668
This exception is thrown when machine should be running but is either
5769
halted or paused.
58-
'''
70+
"""
5971

6072

6173
class QubesVMNotPausedError(QubesVMNotStartedError):
62-
'''Domain is not paused.
74+
"""Domain is not paused.
6375
6476
This exception is thrown when machine should be paused, but is not.
65-
'''
77+
"""
6678

6779

6880
class QubesVMNotSuspendedError(QubesVMError):
69-
'''Domain is not suspended.
81+
"""Domain is not suspended.
7082
7183
This exception is thrown when machine should be suspended but is either
7284
halted or running.
73-
'''
85+
"""
7486

7587

7688
class QubesVMNotHaltedError(QubesVMError):
77-
'''Domain is not halted.
89+
"""Domain is not halted.
7890
7991
This exception is thrown when machine should be halted, but is not (either
8092
running or paused).
81-
'''
93+
"""
8294

8395

84-
class QubesVMShutdownTimeout(QubesVMError):
85-
''' Domain shutdown haven't completed in expected timeframe'''
96+
class QubesVMShutdownTimeoutError(QubesVMError):
97+
"""Domain shutdown timed out."""
8698

8799

88100
class QubesNoTemplateError(QubesVMError):
89-
'''Cannot start domain, because there is no template'''
101+
"""Cannot start domain, because there is no template"""
90102

91103

92-
class QubesVMInUseError(QubesVMError):
93-
'''VM is in use, cannot remove.'''
104+
class QubesPoolInUseError(QubesException):
105+
"""VM is in use, cannot remove."""
94106

95107

96108
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."""
98110

99111

100112
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+
"""
103116

104117

105118
class QubesNoSuchPropertyError(QubesException, AttributeError):
106-
'''Requested property does not exist
107-
'''
119+
"""Requested property does not exist"""
108120

109121

110122
class QubesNotImplementedError(QubesException, NotImplementedError):
111-
'''Thrown at user when some feature is not implemented'''
123+
"""Thrown at user when some feature is not implemented"""
112124

113125

114126
class BackupCancelledError(QubesException):
115-
'''Thrown at user when backup was manually cancelled'''
127+
"""Thrown at user when backup was manually cancelled"""
116128

117129

118130
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"""
121133

122134

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"""
125137

126138

127139
class QubesFeatureNotFoundError(QubesException, KeyError):
128-
'''Feature not set for a given domain'''
140+
"""Feature not set for a given domain"""
141+
129142
def __str__(self):
130143
# KeyError overrides __str__ method
131144
return QubesException.__str__(self)
132145

133146

134147
class QubesTagNotFoundError(QubesException, KeyError):
135-
'''Tag not set for a given domain'''
148+
"""Tag not set for a given domain"""
149+
136150
def __str__(self):
137151
# KeyError overrides __str__ method
138152
return QubesException.__str__(self)
139153

140154

141155
class QubesLabelNotFoundError(QubesException, KeyError):
142156
"""Label does not exists"""
157+
143158
def __str__(self):
144159
# KeyError overrides __str__ method
145160
return QubesException.__str__(self)
146161

147162

148-
class StoragePoolException(QubesException):
149-
''' A general storage exception '''
163+
class ProtocolError(AssertionError):
164+
"""Raised when something is wrong with data received"""
150165

151166

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+
"""
155175

156176

157177
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"""
162211

163212

164213
class BackupRestoreError(QubesException):
165-
'''Restoring a backup failed'''
214+
"""Restoring a backup failed"""
215+
166216
def __init__(self, msg, backup_log=None):
167217
super().__init__(msg)
168218
self.backup_log = backup_log
169219

220+
170221
# pylint: disable=too-many-ancestors
171222
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."""
174225

175226

176227
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+
179231
def __init__(self, prop):
180-
super().__init__('Failed to access \'%s\' property' % prop)
232+
super().__init__("Failed to access '%s' property" % prop)
233+
181234

182235
# legacy name
183236
QubesDaemonNoResponseError = QubesDaemonAccessError

0 commit comments

Comments
 (0)