From: Dustin Walde Date: Sun, 10 Sep 2023 22:10:26 +0000 (-0700) Subject: Add project exception class with errors X-Git-Url: https://git.walde.dev/?a=commitdiff_plain;h=6f95f02f2561c1485bb585cf22eca10e3b598af5;p=punch Add project exception class with errors --- diff --git a/src/errors.py b/src/errors.py new file mode 100644 index 0000000..47e6523 --- /dev/null +++ b/src/errors.py @@ -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 +