Skip to content

Commit 35b87cf

Browse files
authored
Rescue from exceptions raised by #name (#899)
* Rescue from exceptions raised by #name Irb might terminate if the class overwrites `name` and raise errors. This commit rescue irb from termination. * fix for other unknown patterns
1 parent 29901e4 commit 35b87cf

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

lib/irb/completion.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ def retrieve_completion_data(input, bind:, doc_namespace:)
388388

389389
if doc_namespace
390390
rec_class = rec.is_a?(Module) ? rec : rec.class
391-
"#{rec_class.name}#{sep}#{candidates.find{ |i| i == message }}"
391+
"#{rec_class.name}#{sep}#{candidates.find{ |i| i == message }}" rescue nil
392392
else
393393
select_message(receiver, message, candidates, sep)
394394
end
@@ -418,7 +418,7 @@ def retrieve_completion_data(input, bind:, doc_namespace:)
418418
vars = (bind.local_variables | bind.eval_instance_variables).collect{|m| m.to_s}
419419
perfect_match_var = vars.find{|m| m.to_s == input}
420420
if perfect_match_var
421-
eval("#{perfect_match_var}.class.name", bind)
421+
eval("#{perfect_match_var}.class.name", bind) rescue nil
422422
else
423423
candidates = (bind.eval_methods | bind.eval_private_methods | bind.local_variables | bind.eval_instance_variables | bind.eval_class_constants).collect{|m| m.to_s}
424424
candidates |= ReservedWords

0 commit comments

Comments
 (0)