From 480ee90b6fa7610b6f012a631063e1134360fe84 Mon Sep 17 00:00:00 2001 From: Koichi Sasada Date: Fri, 5 Dec 2025 17:18:23 +0900 Subject: [PATCH] catch any exception on `singletonclass` fix https://github.com/ruby/debug/issues/1162 --- lib/debug/frame_info.rb | 2 +- test/console/backtrace_test.rb | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/lib/debug/frame_info.rb b/lib/debug/frame_info.rb index 8fab332de..558f5466b 100644 --- a/lib/debug/frame_info.rb +++ b/lib/debug/frame_info.rb @@ -171,7 +171,7 @@ def parameters_info private def get_singleton_class obj obj.singleton_class # TODO: don't use it - rescue TypeError + rescue Exception nil end diff --git a/test/console/backtrace_test.rb b/test/console/backtrace_test.rb index 570d66c80..8c6056a6a 100644 --- a/test/console/backtrace_test.rb +++ b/test/console/backtrace_test.rb @@ -229,4 +229,31 @@ def test_backtrace_prints_without_hanging end end end + + class BrokenSingletonMethodBacktraceTest < ConsoleTestCase + def program + <<~RUBY + 1| class C + 2| def self.foo + 3| debugger + 4| end + 5| def singleton_class + 6| raise + 7| end + 8| def self.singleton_class + 9| eval(")") # SyntaxError + 10| end + 11| end + 12| C.foo + RUBY + end + + def test_raise_exception + debug_code program do + type 'c' + assert_line_text(/foo/) + type 'c' + end + end + end end