11import traceback
2- from typing import Any , Optional
2+ from typing import Any , Optional , Sequence , Tuple
33
44
55class ThreadErrorBase (Exception ):
@@ -20,17 +20,37 @@ class ThreadNotRunningError(ThreadErrorBase):
2020
2121class ThreadNotInitializedError (ThreadErrorBase ):
2222 """Exception class for attempting to invoke a method which requires the thread to be initialized, but isn't"""
23- message : str = 'Thread is not initialized, unable to invoke method. Have you ran `Thread.start()` at least once? '
23+ message : str = 'Thread is not initialized, unable to invoke method.'
2424
2525class HookRuntimeError (ThreadErrorBase ):
2626 """Exception class for hook runtime errors"""
2727 message : str = 'Encountered runtime errors in hooks'
2828 count : int = 0
2929
30- def add_exception_case (self , func_name : str , error : Exception ):
31- self .count += 1
32- trace = '\n ' .join (traceback .format_stack ())
33-
34- self .add_note (f'\n { self .count } . { func_name } \n >>>>>>>>>>' )
35- self .add_note (f'{ trace } \n { error } ' )
36- self .add_note ('<<<<<<<<<<' )
30+ def __init__ (self , message : Optional [str ] = '' , extra : Sequence [Tuple [Exception , str ]] = []) -> None :
31+ """
32+ Extra for parsing all hooks that errored
33+
34+ Parameters
35+ ----------
36+ :param message: The message to be parsed, can be left blank
37+ :param extra: Tuple of (Exception_Raised, function_name)
38+ """
39+ new_message : str = message or self .message
40+
41+ for i , v in enumerate (extra ):
42+ trace = '\n ' .join (traceback .format_stack ())
43+ new_message += f'\n \n { i } . { v [1 ]} \n >>>>>>>>>>'
44+ new_message += f'{ trace } \n { v [0 ]} '
45+ new_message += '<<<<<<<<<<'
46+ super ().__init__ (new_message )
47+
48+
49+ # Python 3.9 doesn't support Exception.add_note()
50+ # def add_exception_case(self, func_name: str, error: Exception):
51+ # self.count += 1
52+ # trace = '\n'.join(traceback.format_stack())
53+
54+ # self.add_note(f'\n{self.count}. {func_name}\n>>>>>>>>>>')
55+ # self.add_note(f'{trace}\n{error}')
56+ # self.add_note('<<<<<<<<<<')
0 commit comments