Commit 65f0a44
Fix segfault when Ruby coverage is enabled with Rails 8.1 ERB templates
v4.2.0 introduced a fix for incorrect line numbers in stack traces on
Rails 8.1 by using negative lineno values (-1) in class_eval. However,
negative line numbers cause segmentation faults when Ruby's Coverage
module is enabled (e.g., when using SimpleCov in CI).
This is a known Ruby bug: https://bugs.ruby-lang.org/issues/19363
The fix detects whether coverage is running via Coverage.running? and
adapts the lineno value accordingly:
- Coverage OFF: Use -1 (correct line numbers in stack traces)
- Coverage ON: Use 1 (avoids segfault, line numbers off by ~2)
Note: lineno=0 was also tested but causes the same segfault, so 1 is
the minimum safe value when coverage is enabled.
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>1 parent 1722b70 commit 65f0a44
1 file changed
Lines changed: 14 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
24 | | - | |
25 | | - | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
26 | 28 | | |
27 | 29 | | |
28 | | - | |
| 30 | + | |
29 | 31 | | |
30 | 32 | | |
31 | 33 | | |
| |||
54 | 56 | | |
55 | 57 | | |
56 | 58 | | |
57 | | - | |
58 | | - | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
59 | 63 | | |
60 | 64 | | |
61 | | - | |
| 65 | + | |
62 | 66 | | |
63 | 67 | | |
64 | 68 | | |
| |||
126 | 130 | | |
127 | 131 | | |
128 | 132 | | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
129 | 137 | | |
130 | 138 | | |
131 | 139 | | |
| |||
0 commit comments