2017-02-24 00:14:13 +01:00
|
|
|
# -*- encoding: utf8 -*-
|
|
|
|
#
|
|
|
|
# The Qubes OS Project, http://www.qubes-os.org
|
|
|
|
#
|
|
|
|
# Copyright (C) 2017 Marek Marczykowski-Górecki
|
|
|
|
# <marmarek@invisiblethingslab.com>
|
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
# the Free Software Foundation; either version 2.1 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU Lesser General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU Lesser General Public License along
|
|
|
|
# with this program; if not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
2017-02-25 20:56:31 +01:00
|
|
|
'''Exception hierarchy.'''
|
|
|
|
|
2017-02-24 00:14:13 +01:00
|
|
|
|
2017-02-25 20:56:31 +01:00
|
|
|
class QubesException(Exception):
|
|
|
|
'''Base exception for all Qubes-related errors.'''
|
2017-02-24 00:14:13 +01:00
|
|
|
def __init__(self, message_format, *args, **kwargs):
|
|
|
|
# TODO: handle translations
|
2020-08-23 03:31:39 +02:00
|
|
|
super().__init__(
|
2017-02-27 20:18:29 +01:00
|
|
|
message_format % tuple(int(d) if d.isdigit() else d for d in args),
|
|
|
|
**kwargs)
|
2017-03-09 02:25:10 +01:00
|
|
|
|
|
|
|
|
|
|
|
class QubesVMNotFoundError(QubesException, KeyError):
|
|
|
|
'''Domain cannot be found in the system'''
|
|
|
|
|
2019-12-09 21:05:18 +01:00
|
|
|
def __str__(self):
|
|
|
|
# KeyError overrides __str__ method
|
|
|
|
return QubesException.__str__(self)
|
|
|
|
|
2017-03-09 02:25:10 +01:00
|
|
|
|
|
|
|
class QubesVMError(QubesException):
|
|
|
|
'''Some problem with domain state.'''
|
|
|
|
|
|
|
|
|
|
|
|
class QubesVMNotStartedError(QubesVMError):
|
|
|
|
'''Domain is not started.
|
|
|
|
|
|
|
|
This exception is thrown when machine is halted, but should be started
|
|
|
|
(that is, either running or paused).
|
|
|
|
'''
|
|
|
|
|
|
|
|
|
|
|
|
class QubesVMNotRunningError(QubesVMNotStartedError):
|
|
|
|
'''Domain is not running.
|
|
|
|
|
|
|
|
This exception is thrown when machine should be running but is either
|
|
|
|
halted or paused.
|
|
|
|
'''
|
|
|
|
|
|
|
|
|
|
|
|
class QubesVMNotPausedError(QubesVMNotStartedError):
|
|
|
|
'''Domain is not paused.
|
|
|
|
|
|
|
|
This exception is thrown when machine should be paused, but is not.
|
|
|
|
'''
|
|
|
|
|
|
|
|
|
|
|
|
class QubesVMNotSuspendedError(QubesVMError):
|
|
|
|
'''Domain is not suspended.
|
|
|
|
|
|
|
|
This exception is thrown when machine should be suspended but is either
|
|
|
|
halted or running.
|
|
|
|
'''
|
|
|
|
|
|
|
|
|
|
|
|
class QubesVMNotHaltedError(QubesVMError):
|
|
|
|
'''Domain is not halted.
|
|
|
|
|
|
|
|
This exception is thrown when machine should be halted, but is not (either
|
|
|
|
running or paused).
|
|
|
|
'''
|
|
|
|
|
|
|
|
|
2017-05-25 12:51:10 +02:00
|
|
|
class QubesVMShutdownTimeout(QubesVMError):
|
|
|
|
''' Domain shutdown haven't completed in expected timeframe'''
|
|
|
|
|
|
|
|
|
2017-03-09 02:25:10 +01:00
|
|
|
class QubesNoTemplateError(QubesVMError):
|
|
|
|
'''Cannot start domain, because there is no template'''
|
|
|
|
|
|
|
|
|
2018-07-20 00:21:47 +02:00
|
|
|
class QubesVMInUseError(QubesVMError):
|
|
|
|
'''VM is in use, cannot remove.'''
|
|
|
|
|
|
|
|
|
2017-03-09 02:25:10 +01:00
|
|
|
class QubesValueError(QubesException, ValueError):
|
|
|
|
'''Cannot set some value, because it is invalid, out of bounds, etc.'''
|
|
|
|
|
|
|
|
|
|
|
|
class QubesPropertyValueError(QubesValueError):
|
|
|
|
'''Cannot set value of qubes.property, because user-supplied value is wrong.
|
|
|
|
'''
|
|
|
|
|
|
|
|
|
2017-05-23 04:31:41 +02:00
|
|
|
class QubesNoSuchPropertyError(QubesException, AttributeError):
|
|
|
|
'''Requested property does not exist
|
|
|
|
'''
|
|
|
|
|
|
|
|
|
2017-03-09 02:25:10 +01:00
|
|
|
class QubesNotImplementedError(QubesException, NotImplementedError):
|
|
|
|
'''Thrown at user when some feature is not implemented'''
|
|
|
|
|
|
|
|
|
|
|
|
class BackupCancelledError(QubesException):
|
|
|
|
'''Thrown at user when backup was manually cancelled'''
|
|
|
|
|
|
|
|
|
2019-11-11 17:17:07 +01:00
|
|
|
class BackupAlreadyRunningError(QubesException):
|
|
|
|
'''Thrown at user when they try to run the same backup twice at
|
|
|
|
the same time'''
|
|
|
|
|
|
|
|
|
2017-03-09 02:25:10 +01:00
|
|
|
class QubesMemoryError(QubesException, MemoryError):
|
|
|
|
'''Cannot start domain, because not enough memory is available'''
|
2017-03-11 01:41:58 +01:00
|
|
|
|
|
|
|
|
2017-04-15 13:53:40 +02:00
|
|
|
class QubesFeatureNotFoundError(QubesException, KeyError):
|
|
|
|
'''Feature not set for a given domain'''
|
2019-12-09 21:05:18 +01:00
|
|
|
def __str__(self):
|
|
|
|
# KeyError overrides __str__ method
|
|
|
|
return QubesException.__str__(self)
|
2017-04-15 13:53:40 +02:00
|
|
|
|
|
|
|
|
2017-06-19 01:55:49 +02:00
|
|
|
class QubesTagNotFoundError(QubesException, KeyError):
|
|
|
|
'''Tag not set for a given domain'''
|
2019-12-09 21:05:18 +01:00
|
|
|
def __str__(self):
|
|
|
|
# KeyError overrides __str__ method
|
|
|
|
return QubesException.__str__(self)
|
2017-06-19 01:55:49 +02:00
|
|
|
|
|
|
|
|
2020-08-13 20:07:19 +02:00
|
|
|
class QubesLabelNotFoundError(QubesException, KeyError):
|
|
|
|
"""Label does not exists"""
|
|
|
|
def __str__(self):
|
|
|
|
# KeyError overrides __str__ method
|
|
|
|
return QubesException.__str__(self)
|
|
|
|
|
|
|
|
|
2017-03-13 04:32:35 +01:00
|
|
|
class StoragePoolException(QubesException):
|
|
|
|
''' A general storage exception '''
|
|
|
|
|
|
|
|
|
2017-03-11 01:41:58 +01:00
|
|
|
class QubesDaemonCommunicationError(QubesException, IOError):
|
|
|
|
'''Error while communicating with qubesd, may mean insufficient
|
2017-08-12 15:15:52 +02:00
|
|
|
permissions as well'''
|
2017-03-11 01:41:58 +01:00
|
|
|
|
|
|
|
|
2017-05-20 16:40:33 +02:00
|
|
|
class DeviceAlreadyAttached(QubesException, KeyError):
|
|
|
|
'''Trying to attach already attached device'''
|
2019-12-09 21:05:18 +01:00
|
|
|
def __str__(self):
|
|
|
|
# KeyError overrides __str__ method
|
|
|
|
return QubesException.__str__(self)
|
2017-05-20 16:40:33 +02:00
|
|
|
|
|
|
|
|
2019-10-18 06:02:04 +02:00
|
|
|
class BackupRestoreError(QubesException):
|
|
|
|
'''Restoring a backup failed'''
|
|
|
|
def __init__(self, msg, backup_log=None):
|
2020-08-23 03:31:39 +02:00
|
|
|
super().__init__(msg)
|
2019-10-18 06:02:04 +02:00
|
|
|
self.backup_log = backup_log
|
|
|
|
|
2017-03-11 01:41:58 +01:00
|
|
|
# pylint: disable=too-many-ancestors
|
2020-08-11 01:33:11 +02:00
|
|
|
class QubesDaemonAccessError(QubesDaemonCommunicationError):
|
|
|
|
'''Got empty response from qubesd. This can be lack of permission,
|
|
|
|
or some server-side issue.'''
|
2017-03-11 01:44:06 +01:00
|
|
|
|
|
|
|
|
2020-08-11 01:33:11 +02:00
|
|
|
class QubesPropertyAccessError(QubesDaemonAccessError, AttributeError):
|
2017-03-11 01:44:06 +01:00
|
|
|
'''Failed to read/write property value, cause is unknown (insufficient
|
|
|
|
permissions, no such property, invalid value, other)'''
|
|
|
|
def __init__(self, prop):
|
2020-08-23 03:31:39 +02:00
|
|
|
super().__init__('Failed to access \'%s\' property' % prop)
|
2020-08-11 01:33:11 +02:00
|
|
|
|
|
|
|
# legacy name
|
|
|
|
QubesDaemonNoResponseError = QubesDaemonAccessError
|