Skip to content
New issue

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

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

Already on GitHub? # to your account

Ensure context lines option is used (fixes #740) #743

Merged
merged 4 commits into from
Feb 8, 2019
Merged

Ensure context lines option is used (fixes #740) #743

merged 4 commits into from
Feb 8, 2019

Conversation

mattzuba
Copy link
Contributor

Tests included, ensures that the context options that are set are used, rather than being hard-coded to a constant.

@ste93cry ste93cry self-requested a review January 22, 2019 17:35
@ste93cry ste93cry added this to the Release 2.0 milestone Jan 22, 2019
@mattzuba
Copy link
Contributor Author

Looks like the get/setContextLines methods allow for possible null, but the OptionsResolver only allows an int, do you mind if I change the method signatures of these to be int only?

@ste93cry
Copy link
Collaborator

Looks like the get/setContextLines methods allow for possible null, but the OptionsResolver only allows an int

That's indeed another bug and I agree that the parameter should not be nullable. Maybe we can also optimize a bit the code in Stacktrace::getSourceCodeExcerpt() by checking if $maxLinesToFetch is greater than 0 and if not return early instead of opening the file anyway to read nothing. There is also another bug I'm seeing right now that is being reported by Scrutinizer: we're calling that method as if it was a static one but it's not

$sourceCodeExcerpt = self::getSourceCodeExcerpt($file, $line, self::CONTEXT_NUM_LINES);

@mattzuba
Copy link
Contributor Author

Even if $maxLinesToFetch was 0, you'd still want to open the file to read the line that was a part of the stack though, right?

Copy link
Collaborator

@Jean85 Jean85 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very good changes, thanks for spotting this bug!

I'm requesting just a little test improvement.

src/Options.php Show resolved Hide resolved
tests/StacktraceTest.php Outdated Show resolved Hide resolved
@ste93cry
Copy link
Collaborator

Even if $maxLinesToFetch was 0, you'd still want to open the file to read the line that was a part of the stack though, right?

As a user I would expect no lines to be sent to Sentry if the value of that option is set to 0. I may be wrong but I think that actually the number of lines also includes the line that originated the frame itself

@HazAT
Copy link
Member

HazAT commented Jan 23, 2019

Setting it to 0 should just remove the pre and post context lines, the line of the frame in the stacktrace should still be there.
btw thanks for the work 👍

@mattzuba
Copy link
Contributor Author

I didn't forget about this guys, just been busy at work. I'll try to get a data provider setup on the test and merge the other test and update the PR today or tomorrow.

@ste93cry
Copy link
Collaborator

ste93cry commented Feb 6, 2019

@mattzuba are you willing to make the requested changes? We would like to release beta 2 asap and it would be cool if this bugfix was part of that version

tests/StacktraceTest.php Outdated Show resolved Hide resolved
tests/StacktraceTest.php Outdated Show resolved Hide resolved
tests/StacktraceTest.php Outdated Show resolved Hide resolved
tests/StacktraceTest.php Outdated Show resolved Hide resolved
Copy link
Collaborator

@Jean85 Jean85 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with @ste93cry review comments. Apart from those, LGTM! 👍

@mattzuba
Copy link
Contributor Author

mattzuba commented Feb 7, 2019

Made the requested changes and rebased against master as well.

Copy link
Collaborator

@Jean85 Jean85 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot for your contribution!

I should have to add this to the changelog, but since I haven't merged #769 yet, I'll do it myself there.

@Jean85 Jean85 merged commit ebf78d0 into getsentry:master Feb 8, 2019
Jean85 added a commit that referenced this pull request Feb 8, 2019
# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants