Repository navigation
Closed
Milestone
Description
Your environment
ruby -v:ruby 3.1.0p0 (2021-12-25 revision fb4df44d16) [x86_64-darwin21]rdbg -v:1.5.0
Description
I spotted a weird behavior when using catch Exception or catch StandardError and then causing an exception in the console. Example:
❯ exe/rdbg -e "catch Exception do: 'debugger spotted an error' ;; raise 'foo' ;; " target.rb
[1, 1] in target.rb
=> 1| puts(123)
=>#0 <main> at target.rb:1
(rdbg:commands) catch Exception do: 'debugger spotted an error'
#0 BP - Catch "Exception"
(rdbg:commands) raise 'foo'
[1, 1] in (rdbg)/target.rb
=> 1| raise 'foo'
=>#0 <main> at (rdbg)/target.rb:1
#1 [C] Binding#eval at ~/projects/debug/lib/debug/thread_client.rb:369
# and 2 frames (use `bt' command for all frames)
Stop by #0 BP - Catch "Exception"
(rdbg:catch) 'debugger spotted an error'
"debugger spotted an error"
eval error: foo
(rdbg)/target.rb:1:in `<main>'
nil
# catch breakpoint is triggered and performed command as expected, so far so good.
# let's run some other commands
(rdbg) ls # outline command
Object.methods: inspect to_s
# for some reason, the catch bp's command is triggered again
(rdbg:catch) 'debugger spotted an error'
"debugger spotted an error"
# and it exits the current bp for no apparent reason
123
Reproduction
Scripit
puts(123)Command and output
$ exe/rdbg -e "catch Exception do: 'debugger spotted an error' ;; raise 'foo' ;; " target.rb- Run arbitrary debugger command, like
ls
Expected Behavior
- The
'debugger spotted an error'message is only printed once. - The arbitrary command doesn't exit the debugging session.
Actual Behavior
- The
do:command is executed for the second time when no new exception is raised. - When 1 happens, it also tries to leave the current debugging session without being told to do so.
However, if we use a more specific exception name, like catch RuntimeError, neither the problem occurs.
Therefore, I suspect that debugger has some internal exceptions happening between step 1 and 2, which triggered the catch breakpoint unexpectedly.
Metadata
Metadata
Assignees
Labels
No labels
Activity
st0012 commentedon Mar 31, 2022
Yeah there is an exception raised from
relinethat triggered the breakpoint:It's
Errno::ENOENTraised byFile.readline.st0012 commentedon Mar 31, 2022
@ko1 I think the straightforward solution is to mark
reline's code as internal in theskip_internal_path?method. Which should look like this?path.match?(/lib\/reline[\/\.]/).The drawback would be that developers working with
relinewon't be able to catch the errors it raises. But I think it's worth the tradeoff to makecatch Exceptionorcatch StandardErrorwork. Because users don't always know what's the exception that changes their application's behavior (raised and rescued). I personally use the later very often.Of course, the ideal solution would be something like:
But I can't come up with an implementation that doesn't need to use a global state for that, which I think would be thread/ractor unsafe?
ko1 commentedon Apr 1, 2022
on 1.5.0 only? (not on 1.4.0?)
ko1 commentedon Apr 1, 2022
repro on 1.4.0.
st0012 commentedon Apr 1, 2022
Yeah I think it's been there for a while, not something new. I'm not sure why I didn't notice it though.
skip if `ThreadClient.current.management?`
skip if `ThreadClient.current.management?`