Skip to content

Commit 5b14e0a

Browse files
st0012bitwise-aiden
authored andcommitted
Fix info c <exp> when <exp> doesn't return a constant
Currently, the command `info c <exp>` crashes the debugger when <exp>` is not a constant because it raises an exception. This patch fixes it by changing it to `puts`. This commit also adds 2 test cases for the `info c <exp>` usage. Co-authored-by: Aiden Storey <[email protected]>
1 parent 7b1ef07 commit 5b14e0a

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

lib/debug/thread_client.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -613,7 +613,7 @@ def get_consts expr = nil, only_self: false, &block
613613
iter_consts _self, &block
614614
return
615615
else
616-
raise "#{_self.inspect} (by #{expr}) is not a Module."
616+
puts "#{_self.inspect} (by #{expr}) is not a Module."
617617
end
618618
elsif _self = current_frame&.self
619619
cs = {}

test/console/info_test.rb

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,38 @@ def test_info_constant_with_expression
248248
type "c"
249249
end
250250
end
251+
252+
def test_info_constant_with_expression_errors
253+
debug_code(program) do
254+
type "b 31"
255+
type "c"
256+
assert_line_num 31
257+
258+
type "info constants foo"
259+
assert_line_text([
260+
/eval error: undefined local variable or method `foo' for main/,
261+
/.*/,
262+
/nil \(by foo\) is not a Module./
263+
])
264+
265+
type "c"
266+
end
267+
end
268+
269+
def test_info_constant_with_non_module_expression
270+
debug_code(program) do
271+
type "b 31"
272+
type "c"
273+
assert_line_num 31
274+
275+
type "info constants 3"
276+
assert_line_text([
277+
/3 \(by 3\) is not a Module./
278+
])
279+
280+
type "c"
281+
end
282+
end
251283
end
252284

253285
class InfoIvarsTest < ConsoleTestCase

0 commit comments

Comments
 (0)