exc.py 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. # -*- encoding: utf8 -*-
  2. #
  3. # The Qubes OS Project, http://www.qubes-os.org
  4. #
  5. # Copyright (C) 2017 Marek Marczykowski-Górecki
  6. # <marmarek@invisiblethingslab.com>
  7. #
  8. # This program is free software; you can redistribute it and/or modify
  9. # it under the terms of the GNU Lesser General Public License as published by
  10. # the Free Software Foundation; either version 2.1 of the License, or
  11. # (at your option) any later version.
  12. #
  13. # This program is distributed in the hope that it will be useful,
  14. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. # GNU Lesser General Public License for more details.
  17. #
  18. # You should have received a copy of the GNU Lesser General Public License along
  19. # with this program; if not, see <http://www.gnu.org/licenses/>.
  20. '''Exception hierarchy.'''
  21. class QubesException(Exception):
  22. '''Base exception for all Qubes-related errors.'''
  23. def __init__(self, message_format, *args, **kwargs):
  24. # TODO: handle translations
  25. super(QubesException, self).__init__(
  26. message_format % tuple(int(d) if d.isdigit() else d for d in args),
  27. **kwargs)
  28. class QubesVMNotFoundError(QubesException, KeyError):
  29. '''Domain cannot be found in the system'''
  30. class QubesVMError(QubesException):
  31. '''Some problem with domain state.'''
  32. class QubesVMNotStartedError(QubesVMError):
  33. '''Domain is not started.
  34. This exception is thrown when machine is halted, but should be started
  35. (that is, either running or paused).
  36. '''
  37. class QubesVMNotRunningError(QubesVMNotStartedError):
  38. '''Domain is not running.
  39. This exception is thrown when machine should be running but is either
  40. halted or paused.
  41. '''
  42. class QubesVMNotPausedError(QubesVMNotStartedError):
  43. '''Domain is not paused.
  44. This exception is thrown when machine should be paused, but is not.
  45. '''
  46. class QubesVMNotSuspendedError(QubesVMError):
  47. '''Domain is not suspended.
  48. This exception is thrown when machine should be suspended but is either
  49. halted or running.
  50. '''
  51. class QubesVMNotHaltedError(QubesVMError):
  52. '''Domain is not halted.
  53. This exception is thrown when machine should be halted, but is not (either
  54. running or paused).
  55. '''
  56. class QubesVMShutdownTimeout(QubesVMError):
  57. ''' Domain shutdown haven't completed in expected timeframe'''
  58. class QubesNoTemplateError(QubesVMError):
  59. '''Cannot start domain, because there is no template'''
  60. class QubesVMInUseError(QubesVMError):
  61. '''VM is in use, cannot remove.'''
  62. class QubesValueError(QubesException, ValueError):
  63. '''Cannot set some value, because it is invalid, out of bounds, etc.'''
  64. class QubesPropertyValueError(QubesValueError):
  65. '''Cannot set value of qubes.property, because user-supplied value is wrong.
  66. '''
  67. class QubesNoSuchPropertyError(QubesException, AttributeError):
  68. '''Requested property does not exist
  69. '''
  70. class QubesNotImplementedError(QubesException, NotImplementedError):
  71. '''Thrown at user when some feature is not implemented'''
  72. class BackupCancelledError(QubesException):
  73. '''Thrown at user when backup was manually cancelled'''
  74. class QubesMemoryError(QubesException, MemoryError):
  75. '''Cannot start domain, because not enough memory is available'''
  76. class QubesFeatureNotFoundError(QubesException, KeyError):
  77. '''Feature not set for a given domain'''
  78. class QubesTagNotFoundError(QubesException, KeyError):
  79. '''Tag not set for a given domain'''
  80. class StoragePoolException(QubesException):
  81. ''' A general storage exception '''
  82. class QubesDaemonCommunicationError(QubesException, IOError):
  83. '''Error while communicating with qubesd, may mean insufficient
  84. permissions as well'''
  85. class DeviceAlreadyAttached(QubesException, KeyError):
  86. '''Trying to attach already attached device'''
  87. # pylint: disable=too-many-ancestors
  88. class QubesDaemonNoResponseError(QubesDaemonCommunicationError):
  89. '''Got empty response from qubesd'''
  90. class QubesPropertyAccessError(QubesException, AttributeError):
  91. '''Failed to read/write property value, cause is unknown (insufficient
  92. permissions, no such property, invalid value, other)'''
  93. def __init__(self, prop):
  94. super(QubesPropertyAccessError, self).__init__(
  95. 'Failed to access \'%s\' property' % prop)