Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rescue from exceptions raised by #name #899

Merged
merged 2 commits into from
Mar 14, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/irb/completion.rb
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ def retrieve_completion_data(input, bind:, doc_namespace:)

if doc_namespace
rec_class = rec.is_a?(Module) ? rec : rec.class
"#{rec_class.name}#{sep}#{candidates.find{ |i| i == message }}"
"#{rec_class.name}#{sep}#{candidates.find{ |i| i == message }}" rescue nil
Copy link
Member

@tompng tompng Mar 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍
I think there is one more class.name in Line 421 that needs rescue nil

irb(main):010> @foo = Foo.new
=> #<Foo:0x00000001236950b8>
irb(main):011> @f[press tab]
(irb):4:in `name': Abort! (StandardError)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops! Fixed in 00b5a97

Thanks for the review!

else
select_message(receiver, message, candidates, sep)
end
Expand Down Expand Up @@ -418,7 +418,7 @@ def retrieve_completion_data(input, bind:, doc_namespace:)
vars = (bind.local_variables | bind.eval_instance_variables).collect{|m| m.to_s}
perfect_match_var = vars.find{|m| m.to_s == input}
if perfect_match_var
eval("#{perfect_match_var}.class.name", bind)
eval("#{perfect_match_var}.class.name", bind) rescue nil
else
candidates = (bind.eval_methods | bind.eval_private_methods | bind.local_variables | bind.eval_instance_variables | bind.eval_class_constants).collect{|m| m.to_s}
candidates |= ReservedWords
Expand Down
Loading