From 231a662907c035032666d109e5445e952214019e Mon Sep 17 00:00:00 2001 From: Pratyush Shukla Date: Thu, 29 Feb 2024 22:55:50 +0530 Subject: [PATCH 1/2] show source of error --- .../openbb_core/app/static/utils/decorators.py | 14 +++++++++++--- 1 file 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 7a9af5ead87e..a0f50725f906 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 wrapper(*f_args, **f_kwargs): try: return func(*f_args, **f_kwargs) except (ValidationError, Exception) as e: + # Get the last traceback object from the exception + tb = e.original.__traceback__ + while tb.tb_next is not None: + tb = tb.tb_next + + # If the DEBUG_MODE is enabled, raise the exception with complete traceback if Env().DEBUG_MODE: raise + if isinstance(e, ValidationError): error_list = [] @@ -67,13 +74,14 @@ def wrapper(*f_args, **f_kwargs): 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 From 5b74bac8cccf3facd5956d1a766372c150790ba4 Mon Sep 17 00:00:00 2001 From: Pratyush Shukla Date: Thu, 29 Feb 2024 23:13:39 +0530 Subject: [PATCH 2/2] restructure code for readability --- .../core/openbb_core/app/static/utils/decorators.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 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 a0f50725f906..febb23cd3b5d 100644 --- a/openbb_platform/core/openbb_core/app/static/utils/decorators.py +++ b/openbb_platform/core/openbb_core/app/static/utils/decorators.py @@ -48,15 +48,15 @@ def wrapper(*f_args, **f_kwargs): try: return func(*f_args, **f_kwargs) except (ValidationError, Exception) as e: - # Get the last traceback object from the exception - tb = e.original.__traceback__ - while tb.tb_next is not None: - tb = tb.tb_next - # 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 = []