Skip to content

Commit

Permalink
Fix info c <exp> when <exp> doesn't return a constant
Browse files Browse the repository at this point in the history
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 <git@storey.dev>
  • Loading branch information
st0012 and bitwise-aiden committed Mar 30, 2023
1 parent 24fc36c commit f168b75
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/debug/thread_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -612,7 +612,7 @@ def get_consts expr = nil, only_self: false, &block
iter_consts _self, &block
return
else
raise "#{_self.inspect} (by #{expr}) is not a Module."
puts "#{_self.inspect} (by #{expr}) is not a Module."
end
elsif _self = current_frame&.self
cs = {}
Expand Down
32 changes: 32 additions & 0 deletions test/console/info_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,38 @@ def test_info_constant_with_expression
type "c"
end
end

def test_info_constant_with_expression_errors
debug_code(program) do
type "b 31"
type "c"
assert_line_num 31

type "info constants foo"
assert_line_text([
/eval error: undefined local variable or method `foo' for main/,
/.*/,
/nil \(by foo\) is not a Module./
])

type "c"
end
end

def test_info_constant_with_non_module_expression
debug_code(program) do
type "b 31"
type "c"
assert_line_num 31

type "info constants 3"
assert_line_text([
/3 \(by 3\) is not a Module./
])

type "c"
end
end
end

class InfoIvarsTest < ConsoleTestCase
Expand Down

0 comments on commit f168b75

Please sign in to comment.