[ruby-core:116935] [Ruby master Bug#18743] Enumerator#next / peek re-use each others stacktraces
From:
"nagachika (Tomoyuki Chikanaga) via ruby-core" <ruby-core@...>
Date:
2024-02-25 09:29:33 UTC
List:
ruby-core #116935
Issue #18743 has been updated by nagachika (Tomoyuki Chikanaga).
Backport changed from 3.0: REQUIRED, 3.1: REQUIRED, 3.2: REQUIRED to 3.0: R=
EQUIRED, 3.1: REQUIRED, 3.2: DONE
ruby_3_2 5e4606423da96c2e26b00981c22bddfce0d970bf merged revision(s) f15123=
c34ce80f3928612befe2a9aaf4c9d27fda.
----------------------------------------
Bug #18743: Enumerator#next / peek re-use each others stacktraces
https://bugs.ruby-lang.org/issues/18743#change-106970
* Author: sos4nt (Stefan Sch=FC=DFler)
* Status: Closed
* Assignee: ko1 (Koichi Sasada)
* Backport: 3.0: REQUIRED, 3.1: REQUIRED, 3.2: DONE
----------------------------------------
I encountered an odd behavior.
If I rescue the `StopIteration` exception from `peek` and call `next` after=
wards: (or vice-versa)
```ruby
# enum.rb # 1
# 2
enum =3D [].each # 3
enum.peek rescue nil # 4
enum.next # 5
```
it will show the stacktrace from the rescued `peek` call:
```
$ ruby enum.rb
enum.rb:4:in `peek': iteration reached an end (StopIteration)
from enum.rb:4:in `<main>'
```
Whereas the error should refer to `next` on line number 5.
The same happens when calling `peek` after `next` or when having muliple `p=
eek` / `next` calls:
```ruby
# enum.rb # 1
# 2
enum =3D [].each # 3
enum.peek rescue nil # 4
enum.next rescue nil # 5
enum.peek rescue nil # 6
puts "line #{__LINE__}" # 7
enum.next # 8
```
The stacktrace from the first (rescued) `peek` or `next` call will be shown=
which doesn't reflect the actual error location:
```
$ ruby enum.rb
line 7
enum.rb:4:in `peek': iteration reached an end (StopIteration)
from enum.rb:4:in `<main>'
```
This is very confusing when debugging code.
---Files--------------------------------
01-Recreate-stacktrace-enumerator.patch (1.29 KB)
--=20
https://bugs.ruby-lang.org/
______________________________________________
ruby-core mailing list -- ruby-core@ml.ruby-lang.org
To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
ruby-core info -- https://ml.ruby-lang.org/mailman3/postorius/lists/ruby-c=
ore.ml.ruby-lang.org/