diff --git a/lib/debug/server_cdp.rb b/lib/debug/server_cdp.rb index db4ca9124..99abffcfa 100644 --- a/lib/debug/server_cdp.rb +++ b/lib/debug/server_cdp.rb @@ -1194,7 +1194,11 @@ def search_const b, expr [Object, *b.eval('::Module.nesting')].reverse_each{|mod| if cs.all?{|c| if mod.const_defined?(c) - mod = mod.const_get(c) + begin + mod = mod.const_get(c) + rescue Exception + false + end else false end diff --git a/lib/debug/server_dap.rb b/lib/debug/server_dap.rb index cf50395e1..288db814d 100644 --- a/lib/debug/server_dap.rb +++ b/lib/debug/server_dap.rb @@ -960,7 +960,11 @@ def search_const b, expr [Object, *b.eval('::Module.nesting')].reverse_each{|mod| if cs.all?{|c| if mod.const_defined?(c) - mod = mod.const_get(c) + begin + mod = mod.const_get(c) + rescue Exception + false + end else false end diff --git a/lib/debug/thread_client.rb b/lib/debug/thread_client.rb index 1f90df081..2d184a76a 100644 --- a/lib/debug/thread_client.rb +++ b/lib/debug/thread_client.rb @@ -608,7 +608,11 @@ def show_consts pat, only_self: false c.constants(false).sort.each{|name| next if names.has_key? name names[name] = nil - value = c.const_get(name) + begin + value = c.const_get(name) + rescue Exception => e + value = e + end puts_variable_info name, value, pat } } diff --git a/test/console/info_test.rb b/test/console/info_test.rb index 7c696d1e0..ae72f42af 100644 --- a/test/console/info_test.rb +++ b/test/console/info_test.rb @@ -203,6 +203,16 @@ def test_info_constant type 'c' end end + + def test_info_constant_twice + debug_code program do + type 'i c' # on Ruby 3.2, `Set` loads `set.rb` + type 'i c' # on Ruby 3.2, accessing `SortedSet` raises an error + # #