Skip to content

Commit 7cb4cfc

Browse files
committed
take care exceptions from const_get
`const_get` can raise an error so it should be handled.
1 parent 79bf499 commit 7cb4cfc

File tree

4 files changed

+25
-3
lines changed

4 files changed

+25
-3
lines changed

lib/debug/server_cdp.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1194,7 +1194,11 @@ def search_const b, expr
11941194
[Object, *b.eval('::Module.nesting')].reverse_each{|mod|
11951195
if cs.all?{|c|
11961196
if mod.const_defined?(c)
1197-
mod = mod.const_get(c)
1197+
begin
1198+
mod = mod.const_get(c)
1199+
rescue Exception
1200+
false
1201+
end
11981202
else
11991203
false
12001204
end

lib/debug/server_dap.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -960,7 +960,11 @@ def search_const b, expr
960960
[Object, *b.eval('::Module.nesting')].reverse_each{|mod|
961961
if cs.all?{|c|
962962
if mod.const_defined?(c)
963-
mod = mod.const_get(c)
963+
begin
964+
mod = mod.const_get(c)
965+
rescue Exception
966+
false
967+
end
964968
else
965969
false
966970
end

lib/debug/thread_client.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -608,7 +608,11 @@ def show_consts pat, only_self: false
608608
c.constants(false).sort.each{|name|
609609
next if names.has_key? name
610610
names[name] = nil
611-
value = c.const_get(name)
611+
begin
612+
value = c.const_get(name)
613+
rescue Exception => e
614+
value = e
615+
end
612616
puts_variable_info name, value, pat
613617
}
614618
}

test/console/info_test.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,16 @@ def test_info_constant
203203
type 'c'
204204
end
205205
end
206+
207+
def test_info_constant_twice
208+
debug_code program do
209+
type 'i c' # on Ruby 3.2, `Set` loads `set.rb`
210+
type 'i c' # on Ruby 3.2, accessing `SortedSet` raises an error
211+
# #<RuntimeError: The `SortedSet` class has been extracted from the `set` library.
212+
# You must use the `sorted_set` gem or other alternatives.
213+
type 'c'
214+
end
215+
end
206216
end
207217

208218
class InfoIvarsTest < ConsoleTestCase

0 commit comments

Comments
 (0)