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

[BugFix] Handle ValidationError Better #6955

Merged
merged 7 commits into from
Nov 25, 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
19 changes: 10 additions & 9 deletions openbb_platform/core/openbb_core/app/static/utils/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ def wrapper(*f_args, **f_kwargs):
while tb.tb_next is not None:
tb = tb.tb_next

if isinstance(e, ValidationError) and "Data" not in e.title:
error_list = []
if isinstance(e, ValidationError):
error_list: list = []
validation_error = f"{e.error_count()} validations error(s)"
for err in e.errors(include_url=False):
loc = ".".join(
Expand All @@ -80,25 +80,26 @@ def wrapper(*f_args, **f_kwargs):
if msg == "Missing required argument"
else err.get("input", "")
)
error_list.append(f"[Arg] {loc} -> input: {_input} -> {msg}")
prefix = f"[Data Model] {e.title}\n" if "Data" in e.title else ""
error_list.append(
f"{prefix}[Arg] {loc} -> input: {_input} -> {msg}"
)
error_list.insert(0, validation_error)
error_str = "\n".join(error_list)
raise OpenBBError(f"\n[Error] -> {error_str}").with_traceback(
tb
) from None
if isinstance(e, UnauthorizedError):
raise UnauthorizedError(f"\n[Error] -> {str(e)}").with_traceback(
raise UnauthorizedError(f"\n[Error] -> {e}").with_traceback(
tb
) from None
if isinstance(e, EmptyDataError):
raise EmptyDataError(f"\n[Empty] -> {str(e)}").with_traceback(
tb
) from None
raise EmptyDataError(f"\n[Empty] -> {e}").with_traceback(tb) from None
if isinstance(e, OpenBBError):
raise OpenBBError(f"\n[Error] -> {str(e)}").with_traceback(tb) from None
raise OpenBBError(f"\n[Error] -> {e}").with_traceback(tb) from None
if isinstance(e, Exception):
raise OpenBBError(
f"\n[Unexpected Error] -> {e.__class__.__name__} -> {str(e.args[0] or e.args)}"
f"\n[Unexpected Error] -> {e.__class__.__name__} -> {e}"
).with_traceback(tb) from None

return None
Expand Down