exc.py 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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 QubesNoTemplateError(QubesVMError):
  57. '''Cannot start domain, because there is no template'''
  58. class QubesValueError(QubesException, ValueError):
  59. '''Cannot set some value, because it is invalid, out of bounds, etc.'''
  60. pass
  61. class QubesPropertyValueError(QubesValueError):
  62. '''Cannot set value of qubes.property, because user-supplied value is wrong.
  63. '''
  64. class QubesNotImplementedError(QubesException, NotImplementedError):
  65. '''Thrown at user when some feature is not implemented'''
  66. class BackupCancelledError(QubesException):
  67. '''Thrown at user when backup was manually cancelled'''
  68. class QubesMemoryError(QubesException, MemoryError):
  69. '''Cannot start domain, because not enough memory is available'''
  70. class QubesFeatureNotFoundError(QubesException, KeyError):
  71. '''Feature not set for a given domain'''
  72. class StoragePoolException(QubesException):
  73. ''' A general storage exception '''
  74. class QubesDaemonCommunicationError(QubesException, IOError):
  75. '''Error while communicating with qubesd, may mean insufficient
  76. permissions, as well'''
  77. # pylint: disable=too-many-ancestors
  78. class QubesDaemonNoResponseError(QubesDaemonCommunicationError):
  79. '''Got empty response from qubesd'''
  80. class QubesPropertyAccessError(QubesException, AttributeError):
  81. '''Failed to read/write property value, cause is unknown (insufficient
  82. permissions, no such property, invalid value, other)'''
  83. def __init__(self, prop):
  84. super(QubesPropertyAccessError, self).__init__(
  85. 'Failed to access \'%s\' property' % prop)