Source code for qubesadmin.exc

# -*- 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/>.

"""
Qubes OS exception hierarchy
"""


[docs] class QubesException(Exception): """Exception that can be shown to the user""" def __init__(self, message_format: str, *args, **kwargs): # TODO: handle translations super().__init__( message_format % tuple(int(d) if d.isdigit() else d for d in args), **kwargs )
[docs] class QubesVMNotFoundError(QubesException, KeyError): """Domain cannot be found in the system""" def __str__(self) -> str: # KeyError overrides __str__ method return QubesException.__str__(self)
[docs] class QubesVMInvalidUUIDError(QubesException): """Domain UUID is invalid"""
[docs] class QubesVMError(QubesException): """Some problem with domain state."""
[docs] class QubesVMInUseError(QubesVMError): """VM is in use, cannot remove."""
[docs] 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). """
[docs] class QubesVMNotRunningError(QubesVMNotStartedError): """Domain is not running. This exception is thrown when machine should be running but is either halted or paused. """
[docs] class QubesVMNotPausedError(QubesVMNotStartedError): """Domain is not paused. This exception is thrown when machine should be paused, but is not. """
[docs] class QubesVMNotSuspendedError(QubesVMError): """Domain is not suspended. This exception is thrown when machine should be suspended but is either halted or running. """
[docs] class QubesVMNotHaltedError(QubesVMError): """Domain is not halted. This exception is thrown when machine should be halted, but is not (either running or paused). """
[docs] class QubesVMShutdownTimeoutError(QubesVMError): """Domain shutdown timed out."""
[docs] class QubesNoTemplateError(QubesVMError): """Cannot start domain, because there is no template"""
[docs] class QubesVMAlreadyStartedError(QubesVMError): """Requested qube to start, but it's already running"""
[docs] class QubesPoolInUseError(QubesException): """VM is in use, cannot remove."""
[docs] class QubesValueError(QubesException, ValueError): """Cannot set some value, because it is invalid, out of bounds, etc."""
[docs] class QubesPropertyValueError(QubesValueError): """ Cannot set value of qubes.property, because user-supplied value is wrong. """
[docs] class QubesNoSuchPropertyError(QubesException, AttributeError): """Requested property does not exist"""
[docs] class QubesNotImplementedError(QubesException, NotImplementedError): """Thrown at user when some feature is not implemented"""
[docs] class BackupCancelledError(QubesException): """Thrown at user when backup was manually cancelled"""
[docs] class BackupAlreadyRunningError(QubesException): """Thrown at user when they try to run the same backup twice at the same time"""
[docs] class QubesMemoryError(QubesVMError, MemoryError): """Cannot start domain, because not enough memory is available"""
[docs] class QubesFeatureNotFoundError(QubesException, KeyError): """Feature not set for a given domain""" def __str__(self) -> str: # KeyError overrides __str__ method return QubesException.__str__(self)
[docs] class QubesTagNotFoundError(QubesException, KeyError): """Tag not set for a given domain""" def __str__(self) -> str: # KeyError overrides __str__ method return QubesException.__str__(self)
[docs] class QubesLabelNotFoundError(QubesException, KeyError): """Label does not exists""" def __str__(self) -> str: # KeyError overrides __str__ method return QubesException.__str__(self)
[docs] class ProtocolError(AssertionError): """Raised when something is wrong with data received"""
[docs] class PermissionDenied(Exception): """Raised deliberately by handlers when we decide not to cooperate"""
[docs] class DeviceNotAssigned(QubesException, KeyError): """ Trying to unassign not assigned device. """
[docs] class DeviceAlreadyAttached(QubesException, KeyError): """ Trying to attach already attached device. """
[docs] class DeviceAlreadyAssigned(QubesException, KeyError): """ Trying to assign already assigned device. """
[docs] class UnrecognizedDevice(QubesException, ValueError): """ Device identity is not as expected. """
[docs] class UnexpectedDeviceProperty(QubesException, ValueError): """ Device has unexpected property such as backend_domain, devclass etc. """
[docs] class StoragePoolException(QubesException): """A general storage exception"""
### core-admin-client specific exceptions:
[docs] class QubesDaemonCommunicationError(QubesException): """Error while communicating with qubesd, may mean insufficient permissions as well"""
[docs] class BackupRestoreError(QubesException): """Restoring a backup failed""" def __init__(self, msg: str, backup_log: bytes | None=None): super().__init__(msg) self.backup_log = backup_log
# pylint: disable=too-many-ancestors
[docs] class QubesDaemonAccessError(QubesDaemonCommunicationError): """Got empty response from qubesd. This can be lack of permission, or some server-side issue."""
[docs] class QubesPropertyAccessError(QubesDaemonAccessError, AttributeError): """Failed to read/write property value, cause is unknown (insufficient permissions, no such property, invalid value, other)""" def __init__(self, prop: str): super().__init__("Failed to access '%s' property" % prop)
[docs] class QubesNotesError(QubesException): """Some problem with qube notes."""
# legacy name QubesDaemonNoResponseError = QubesDaemonAccessError