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(utils): Avoid pre_context and context_line overlap if frame lineno is out of bounds #8722

Merged
merged 2 commits into from
Aug 2, 2023

Conversation

Lms24
Copy link
Member

@Lms24 Lms24 commented Aug 2, 2023

When adding context lines to a stack frame we need to handle the edge case that the frame's lineno is greater than the length of source code lines we obtained (this can happen for various reasons). We do this by assigning the last line of the source code lines array to the context_line and assigning the preceding lines as pre_context.

However, I noticed while finishing up #8699 that, that in addContextToFrame we were off by one for the pre_context line determination, causing overlap between pre_context and context_line. I'm pretty sure we want to avoid this, so this PR removes the overlap by fixing the off-by one error.

Adjusted the overlap test to show the change in behaviour and added a new one to ensure we correctly truncate too long lines.

Note, this concerns both, Node and Browser ContextLines integrations.

@Lms24 Lms24 merged commit 85effab into develop Aug 2, 2023
78 checks passed
@Lms24 Lms24 deleted the lms/fix-addContextToFrame-overshoot branch August 2, 2023 16:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants