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

Handle None lineno in get_source_context #3925

Merged
merged 1 commit into from
Jan 14, 2025
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
8 changes: 5 additions & 3 deletions sentry_sdk/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,7 @@ def get_lines_from_file(

def get_source_context(
frame, # type: FrameType
tb_lineno, # type: int
tb_lineno, # type: Optional[int]
max_value_length=None, # type: Optional[int]
):
# type: (...) -> Tuple[List[Annotated[str]], Optional[Annotated[str]], List[Annotated[str]]]
Expand All @@ -587,11 +587,13 @@ def get_source_context(
loader = frame.f_globals["__loader__"]
except Exception:
loader = None
lineno = tb_lineno - 1
if lineno is not None and abs_path:

if tb_lineno is not None and abs_path:
lineno = tb_lineno - 1
return get_lines_from_file(
abs_path, lineno, max_value_length, loader=loader, module=module
)

return [], None, []


Expand Down
Loading