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

Fix thrown exceptions is within functions in WCI #26

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
18 changes: 16 additions & 2 deletions src/widget_code_input/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,27 @@ def format_generic_error_msg(exc, code_widget):

It will require also the code_widget instance, to get the actual source code.

:note: this must be called from withou the exception, as it will get the current traceback state.
:note: this must be called from without the exception, as it will get the current traceback state.

:param exc: The exception that is being processed.
:param code_widget: the instance of the code widget with the code that raised the exception.
"""
error_class, _, tb = sys.exc_info()
line_number = traceback.extract_tb(tb)[-1][1]
frame_summaries = traceback.extract_tb(tb)
# The correct frame summary corresponding to wci not allways at the end
# therefore we loop through all of them
wci_frame_summary = None
for frame_summary in frame_summaries:
if frame_summary.filename == "widget_code_input":
wci_frame_summary = frame_summary
if wci_frame_summary is None:
warning.warn(
"Could not find traceback frame corresponding to "
"widget_code_input, we output whole error message."
)

return exc
line_number = wci_frame_summary[1]
code_lines = code_widget.full_function_code.splitlines()

err_msg = f"{error_class.__name__} in code input: {str(exc)}\n"
Expand Down