Skip to content

Fix crash in oneshot coverage when file is missing or not valid Ruby#1158

Open
skryukov wants to merge 1 commit intosimplecov-ruby:mainfrom
skryukov:fix-oneshot-line-stub-crash
Open

Fix crash in oneshot coverage when file is missing or not valid Ruby#1158
skryukov wants to merge 1 commit intosimplecov-ruby:mainfrom
skryukov:fix-oneshot-line-stub-crash

Conversation

@skryukov
Copy link

This PR fixes Coverage.line_stub raising Errno::ENOENT or SyntaxError during oneshot coverage adaptation.

Errno::ENOENT: In our case, gRPC proto stubs are auto-generated and gitignored. They exist when Ruby loads them (so Coverage tracks them), but may not exist on disk by the time SimpleCov's at_exit hook calls Coverage.line_stub. Since this happens during at_exit, it's hard to orchestrate the process. User-configured filters (add_filter) could be applied earlier in the pipeline, but BlockFilter requires SourceFile objects (which need the file on disk and parsed coverage data), so it can't work at the raw-path stage.

SyntaxError: Also fixes the issue reported in #1154 comments where Coverage.line_stub crashes on non-Ruby files (e.g. YAML) tracked via enable_coverage_for_eval.

The fix: when Coverage.line_stub fails, fall back to building the line array from the oneshot data alone. This preserves coverage results (with degraded nil/0 distinction for uncovered lines) instead of crashing.

@skryukov skryukov force-pushed the fix-oneshot-line-stub-crash branch 2 times, most recently from 0b34b91 to 8ca1908 Compare March 10, 2026 12:20
@skryukov skryukov force-pushed the fix-oneshot-line-stub-crash branch from 8ca1908 to be8c7d9 Compare March 10, 2026 12:24
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.

1 participant