Skip to content

Commit cf0cbee

Browse files
+ Decorator exceptions
1 parent cf9dfbb commit cf0cbee

1 file changed

Lines changed: 18 additions & 12 deletions

File tree

src/thread/exceptions.py

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,27 +8,29 @@
88
from typing import Any, Optional, Sequence, Tuple
99

1010

11-
class ThreadErrorBase(Exception):
11+
class ErrorBase(Exception):
1212
"""Base exception class for all errors within this library"""
1313
message: str = 'Something went wrong!'
1414
def __init__(self, message: Optional[str] = None, *args: Any, **kwargs: Any) -> None:
1515
message = message or self.message
1616
super().__init__(message, *args, **kwargs)
1717

1818

19-
class ThreadStillRunningError(ThreadErrorBase):
19+
20+
# THREAD ERRORS #
21+
class ThreadStillRunningError(ErrorBase):
2022
"""Exception class for attempting to invoke a method which requries the thread not be running, but isn't"""
2123
message: str = 'Thread is still running, unable to invoke method. You can wait for the thread to terminate with `Thread.join()` or check with `Thread.is_alive()`'
2224

23-
class ThreadNotRunningError(ThreadErrorBase):
25+
class ThreadNotRunningError(ErrorBase):
2426
"""Exception class for attempting to invoke a method which requires the thread to be running, but isn't"""
2527
message: str = 'Thread is not running, unable to invoke method. Have you ran `Thread.start()`?'
2628

27-
class ThreadNotInitializedError(ThreadErrorBase):
29+
class ThreadNotInitializedError(ErrorBase):
2830
"""Exception class for attempting to invoke a method which requires the thread to be initialized, but isn't"""
2931
message: str = 'Thread is not initialized, unable to invoke method.'
3032

31-
class HookRuntimeError(ThreadErrorBase):
33+
class HookRuntimeError(ErrorBase):
3234
"""Exception class for hook runtime errors"""
3335
message: str = 'Encountered runtime errors in hooks'
3436
count: int = 0
@@ -52,11 +54,15 @@ def __init__(self, message: Optional[str] = '', extra: Sequence[Tuple[Exception,
5254
super().__init__(new_message)
5355

5456

55-
# Python 3.9 doesn't support Exception.add_note()
56-
# def add_exception_case(self, func_name: str, error: Exception):
57-
# self.count += 1
58-
# trace = '\n'.join(traceback.format_stack())
5957

60-
# self.add_note(f'\n{self.count}. {func_name}\n>>>>>>>>>>')
61-
# self.add_note(f'{trace}\n{error}')
62-
# self.add_note('<<<<<<<<<<')
58+
# DECORATOR ERRORS #
59+
class AbstractInvokationError(ErrorBase):
60+
"""Exception class for attempting to invoke an abstract method which is only accessible from inheriting classes"""
61+
message: str = 'Attempt to invoke abstract method [{method_name}]!'
62+
63+
def __init__(self, method_name: str) -> None:
64+
super().__init__(self.message.format(method_name = method_name))
65+
66+
class ArgumentValidationError(ErrorBase):
67+
"""Exception class for when validating arguments passed to the wrapped method fails"""
68+
message: str = 'Validation for arguments passed to the wrapped method failed'

0 commit comments

Comments
 (0)