exceptions.py 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. # -*- coding: utf-8 -*-
  2. """
  3. plan.exceptions
  4. ~~~~~~~~~~~~~~~
  5. Plan exceptions.
  6. :copyright: (c) 2014 by Shipeng Feng.
  7. :license: BSD, see LICENSE for more details.
  8. """
  9. from ._compat import text_type, PY2
  10. class BaseError(Exception):
  11. """Baseclass for all Plan errors."""
  12. if PY2:
  13. def __init__(self, message=None):
  14. if message is not None:
  15. message = text_type(message).encode('utf-8')
  16. Exception.__init__(self, message)
  17. @property
  18. def message(self):
  19. if self.args:
  20. message = self.args[0]
  21. if message is not None:
  22. return message.decode('utf-8', 'replace')
  23. def __unicode__(self):
  24. return self.message or u''
  25. else:
  26. def __init__(self, message=None):
  27. Exception.__init__(self, message)
  28. @property
  29. def message(self):
  30. if self.args:
  31. message = self.args[0]
  32. if message is not None:
  33. return message
  34. class PlanError(BaseError):
  35. """Plan error.
  36. .. versionadded:: 0.4
  37. """
  38. class ParseError(BaseError):
  39. """Plan job every and at value parse error."""
  40. class ValidationError(BaseError):
  41. """Plan job every and at value validation error."""