[ruby-core:97017] [Ruby master Bug#16599] did_you_mean is not activated for NameError and KeyError
From:
zverok.offline@...
Date:
2020-01-29 10:29:43 UTC
List:
ruby-core #97017
Issue #16599 has been updated by zverok (Victor Shepelev).
As far as I can understand, `did_you_mean` reacts only when it can find contextually appropriate thing with similar name. For me, it is this way:
```ruby
foo
# NameError (undefined local variable or method `foo' for main:Object) -- did_you_mean can't suggest anything
fox = 1
foo
# NameError (undefined local variable or method `foo' for main:Object)
# Did you mean? fox
# And similarly:
FOO = 1
Foo
# NameError (uninitialized constant Foo)
# Did you mean? FOO
# 2.7 only:
{baz: 1}.fetch(:bar)
# KeyError (key not found: :bar)
# Did you mean? :baz
```
----------------------------------------
Bug #16599: did_you_mean is not activated for NameError and KeyError
https://bugs.ruby-lang.org/issues/16599#change-84106
* Author: sawa (Tsuyoshi Sawada)
* Status: Open
* Priority: Normal
* Assignee: yuki24 (Yuki Nishijima)
* Target version:
* ruby -v: 2.6, 2.7, perhaps for earlier versions too
* Backport: 2.5: UNKNOWN, 2.6: UNKNOWN, 2.7: UNKNOWN
----------------------------------------
[This document](https://www.rubydoc.info/gems/did_you_mean/) claims that the did_you_mean gem responds to NameError, NoMethodError, and KeyError, but it actually seems to only respond to NoMethodError.
```ruby
foo()
# >> NoMethodError: undefined method `foo' for main:Object
# >> Did you mean? for
foo
# >> NameError: undefined local variable or method `foo' for main:Object
Foo
# >> NameError: uninitialized constant Foo
{foo: 1}.fetch(:bar)
# >> KeyError: key not found: :bar
```
--
https://bugs.ruby-lang.org/
Unsubscribe: <mailto:ruby-core-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>