failure.py 984 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. from enum import Enum, auto
  2. class RollbotFailureException(BaseException):
  3. def __init__(self, failure):
  4. super().__init__()
  5. self.failure = failure
  6. class RollbotFailure(Enum):
  7. INVALID_COMMAND = auto()
  8. MISSING_SUBCOMMAND = auto()
  9. INVALID_SUBCOMMAND = auto()
  10. INVALID_ARGUMENTS = auto()
  11. SERVICE_DOWN = auto()
  12. PERMISSIONS = auto()
  13. INTERNAL_ERROR = auto()
  14. def get_debugging(self):
  15. debugging = {}
  16. reason = getattr(self, "reason", None)
  17. if reason is not None:
  18. debugging["explain"] = reason
  19. exception = getattr(self, "exception", None)
  20. if exception is not None:
  21. debugging["exception"] = exception
  22. return debugging
  23. def with_reason(self, reason):
  24. self.reason = reason
  25. return self
  26. def with_exception(self, exception):
  27. self.exception = exception
  28. return self
  29. def raise_exc(self):
  30. raise RollbotFailureException(self)