Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Enhancement] Show the source of error in exception traceback #6153

Merged
merged 3 commits into from
Feb 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions openbb_platform/core/openbb_core/app/static/utils/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,15 @@ def wrapper(*f_args, **f_kwargs):
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 = []

Expand All @@ -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
Loading