diff options
author | Pratyush Shukla <ps4534@nyu.edu> | 2024-02-29 23:18:19 +0530 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-02-29 17:48:19 +0000 |
commit | ba18734f8e1db035bd6b5185e08be3876fa6e144 (patch) | |
tree | 6c92ae048b6b57f79ce05f0764227539fe06a5e4 | |
parent | b458d2f4ba9ddaca7cdd1dc54ce29bbe1a0ec218 (diff) |
[Enhancement] Show the source of error in exception traceback (#6153)
* show source of error
* restructure code for readability
-rw-r--r-- | openbb_platform/core/openbb_core/app/static/utils/decorators.py | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/openbb_platform/core/openbb_core/app/static/utils/decorators.py b/openbb_platform/core/openbb_core/app/static/utils/decorators.py index 7a9af5ead87..febb23cd3b5 100644 --- a/openbb_platform/core/openbb_core/app/static/utils/decorators.py +++ b/openbb_platform/core/openbb_core/app/static/utils/decorators.py @@ -48,8 +48,15 @@ def exception_handler(func: Callable[P, R]) -> Callable[P, R]: try: return func(*f_args, **f_kwargs) except (ValidationError, Exception) as e: + # If the DEBUG_MODE is enabled, raise the exception with complete traceback if Env().DEBUG_MODE: raise + + # Get the last traceback object from the exception + tb = e.__traceback__ + while tb.tb_next is not None: + tb = tb.tb_next + if isinstance(e, ValidationError): error_list = [] @@ -67,13 +74,14 @@ def exception_handler(func: Callable[P, R]) -> Callable[P, R]: error_list.insert(0, validation_error) error_str = "\n".join(error_list) + raise OpenBBError( f"\nType -> ValidationError \n\nDetails -> {error_str}" - ) from None + ).with_traceback(tb) from None # If the error is not a ValidationError, then it is a generic exception raise OpenBBError( - f"\nType -> {e.original.original.__class__.__name__}\n\nDetail -> {str(e)}" - ) from None + f"\nType -> {e.original.__class__.__name__}\n\nDetail -> {str(e)}" + ).with_traceback(tb) from None return wrapper |