1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
|
from __future__ import annotations
from typing import NoReturn, cast, overload
class CruException(Exception):
"""Base exception class of all exceptions in cru."""
@overload
def __init__(
self,
message: None = None,
*args,
user_message: str,
**kwargs,
): ...
@overload
def __init__(
self,
message: str,
*args,
user_message: str | None = None,
**kwargs,
): ...
def __init__(
self,
message: str | None = None,
*args,
user_message: str | None = None,
**kwargs,
):
if message is None:
message = user_message
super().__init__(
message,
*args,
**kwargs,
)
self._message: str
self._message = cast(str, message)
self._user_message = user_message
@property
def message(self) -> str:
return self._message
def get_user_message(self) -> str | None:
return self._user_message
def get_message(self, use_user: bool = True) -> str:
if use_user and self._user_message is not None:
return self._user_message
else:
return self._message
@property
def is_internal(self) -> bool:
return False
@property
def is_logic_error(self) -> bool:
return False
class CruLogicError(CruException):
"""Raised when a logic error occurs."""
@property
def is_logic_error(self) -> bool:
return True
class CruInternalError(CruException):
"""Raised when an internal error occurs."""
@property
def is_internal(self) -> bool:
return True
class CruUnreachableError(CruInternalError):
"""Raised when a code path is unreachable."""
def cru_unreachable() -> NoReturn:
raise CruUnreachableError("Code should not reach here!")
|