diff options
Diffstat (limited to 'tools/cru-py/cru/_error.py')
-rw-r--r-- | tools/cru-py/cru/_error.py | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/tools/cru-py/cru/_error.py b/tools/cru-py/cru/_error.py new file mode 100644 index 0000000..0d2bf79 --- /dev/null +++ b/tools/cru-py/cru/_error.py @@ -0,0 +1,27 @@ +from typing import NoReturn + + +class CruException(Exception): + """Base exception class of all exceptions in cru.""" + + +class CruUnreachableError(CruException): + """Raised when a code path is unreachable.""" + + +def cru_unreachable() -> NoReturn: + raise CruUnreachableError() + + +class CruInternalError(CruException): + """Raised when an internal logic error occurs.""" + + +class CruUserFriendlyException(CruException): + def __init__(self, message: str, user_message: str, *args, **kwargs) -> None: + super().__init__(message, *args, **kwargs) + self._user_message = user_message + + @property + def user_message(self) -> str: + return self._user_message |