Browse Source

Bring over some good rollbot3 code

Kirk Trombley 4 years ago
parent
commit
8ec04579eb
2 changed files with 39 additions and 0 deletions
  1. 1 0
      lib/rollbot/command/__init__.py
  2. 38 0
      lib/rollbot/command/failure.py

+ 1 - 0
lib/rollbot/command/__init__.py

@@ -0,0 +1 @@
+from .failure import RollbotFailure

+ 38 - 0
lib/rollbot/command/failure.py

@@ -0,0 +1,38 @@
+from enum import Enum, auto
+
+
+class RollbotFailureException(BaseException):
+    def __init__(self, failure):
+        super().__init__()
+        self.failure = failure
+
+
+class RollbotFailure(Enum):
+    INVALID_COMMAND = auto()
+    MISSING_SUBCOMMAND = auto()
+    INVALID_SUBCOMMAND = auto()
+    INVALID_ARGUMENTS = auto()
+    SERVICE_DOWN = auto()
+    PERMISSIONS = auto()
+    INTERNAL_ERROR = auto()
+
+    def get_debugging(self):
+        debugging = {}
+        reason = getattr(self, "reason", None)
+        if reason is not None:
+            debugging["explain"] = reason
+        exception = getattr(self, "exception", None)
+        if exception is not None:
+            debugging["exception"] = exception
+        return debugging
+
+    def with_reason(self, reason):
+        self.reason = reason
+        return self
+
+    def with_exception(self, exception):
+        self.exception = exception
+        return self
+
+    def raise_exc(self):
+        raise RollbotFailureException(self)