Commit 81a1bcf
committed
Fix
`Thread::Backtrace::Location#path` returns nil for the Enumerator frames
(e.g. "Enumerator::Generator#each") that appear in `caller_locations` during
an external iteration of Enumerator (e.g. `Enumerator#next`).
When a `TracePoint` callback fires inside such an iteration,
`PowerAssert.internal_file?` raises `NoMethodError` and the callback reports:
```
power_assert: [BUG] Failed to trace: NoMethodError: undefined method 'start_with?' for nil
```
This happens in practice when a block-style assertion drives Capybara,
whose `Capybara::Result` iterates matched elements with `Enumerator#next`.
While #31 originally suspected a CRuby issue,
the type signature of `Thread::Backtrace::Location#path` in ruby/rbs allows nil
(`() -> String?`), and this nil case is observable at least on Ruby 2.6.10, 2.7.8, 3.1.5,
3.3.10, 3.4.10, and 4.0.6, so it seems reasonable for power_assert to tolerate nil either way.
Since `internal_file?` answers whether the given file belongs to the power_assert
library, treat locations without a path as non-internal ones.
Also guard `app_context?`, which walks caller locations the same way.
Closes #31.NoMethodError when a caller location has no path1 parent 583705a commit 81a1bcf
2 files changed
Lines changed: 24 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
37 | 37 | | |
38 | 38 | | |
39 | 39 | | |
40 | | - | |
| 40 | + | |
41 | 41 | | |
42 | 42 | | |
43 | 43 | | |
44 | 44 | | |
45 | 45 | | |
46 | 46 | | |
| 47 | + | |
| 48 | + | |
47 | 49 | | |
48 | 50 | | |
49 | 51 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
0 commit comments