]> git.walde.dev - punch/commitdiff
Add project exception class with errors
authorDustin Walde <redacted>
Sun, 10 Sep 2023 22:10:26 +0000 (15:10 -0700)
committerDustin Walde <redacted>
Sun, 10 Sep 2023 22:10:26 +0000 (15:10 -0700)
src/errors.py [new file with mode: 0644]

diff --git a/src/errors.py b/src/errors.py
new file mode 100644 (file)
index 0000000..47e6523
--- /dev/null
@@ -0,0 +1,43 @@
+ERR_NO_SUCH_CATEGORY = 1
+ERR_MISSING_ARG = 2
+ERR_UNKNOWN_COMMAND = 3
+ERR_ILLEGAL_STATE = 127
+
+class TimeTrackError(Exception):
+    @property
+    def exit_code(self) -> int:
+        return NotImplemented
+
+
+class IllegalStateError(TimeTrackError):
+    def exit_code(self) -> int:
+        return ERR_ILLEGAL_STATE
+
+
+class MissingArgumentError(TimeTrackError):
+    def __init__(self, *args: object) -> None:
+        super().__init__(
+                f"Missing argument: {args[0]}",
+                *args[1:])
+
+    def exit_code(self) -> int:
+        return ERR_MISSING_ARG
+
+
+class NoSuchCategoryError(TimeTrackError):
+    def __init__(self, category: str) -> None:
+        super().__init__(f"No such category: {category}")
+
+    def exit_code(self) -> int:
+        return ERR_NO_SUCH_CATEGORY
+
+
+class UnknownCommandError(TimeTrackError):
+    def __init__(self, *args: object) -> None:
+        super().__init__(
+                f"Unknown subcommand: {args[0]}",
+                *args[1:])
+
+    def exit_code(self) -> int:
+        return ERR_UNKNOWN_COMMAND
+