__init__.py 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. # -*- coding: utf-8 -*-
  2. import subprocess
  3. class DBError(Exception):
  4. pass
  5. class FatalError(Exception):
  6. pass
  7. class FlagError(Exception):
  8. pass
  9. class GrassError(Exception):
  10. pass
  11. class ImplementationError(Exception):
  12. pass
  13. class OpenError(Exception):
  14. pass
  15. class ParameterError(Exception):
  16. pass
  17. class ScriptError(Exception):
  18. """Raised during script execution. ::
  19. >>> error = ScriptError('My error message!')
  20. >>> error.value
  21. 'My error message!'
  22. >>> print(error)
  23. My error message!
  24. """
  25. def __init__(self, value):
  26. self.value = value
  27. def __str__(self):
  28. return str(self.value)
  29. class Usage(Exception):
  30. pass
  31. # TODO: we inherit from subprocess to be aligned with check_call but it is needed?
  32. class CalledModuleError(subprocess.CalledProcessError):
  33. """Raised when a called module ends with error (non-zero return code)
  34. :param module: module name
  35. :param code: some code snipped which contains parameters
  36. :param rc: process returncode
  37. :param error: errors provided by the module (stderr)
  38. """
  39. def __init__(self, module, code, returncode, errors=None):
  40. super(CalledModuleError, self).__init__(returncode, module)
  41. msg = _("Module run %s %s ended with error") % (module, code)
  42. msg += _("\nProcess ended with non-zero return code %s") % returncode
  43. if errors:
  44. msg += _(". See the following errors:\n%s") % errors
  45. else:
  46. # here could be written "above" but it wouldn't work in some cases
  47. # e.g., for testing framework
  48. msg += _(". See errors in the (error) output.")
  49. self.msg = msg
  50. # TODO: handle other parameters
  51. def __str__(self):
  52. return self.msg