[#79440] [Ruby trunk Bug#13188] Reinitialize Ruby VM. — shyouhei@...
Issue #13188 has been updated by Shyouhei Urabe.
6 messages
2017/02/06
[#79441] Re: [Ruby trunk Bug#13188] Reinitialize Ruby VM.
— SASADA Koichi <ko1@...>
2017/02/06
On 2017/02/06 10:10, shyouhei@ruby-lang.org wrote:
[#79532] Immutable Strings vs Symbols — Daniel Ferreira <subtileos@...>
Hi,
15 messages
2017/02/15
[#79541] Re: Immutable Strings vs Symbols
— Rodrigo Rosenfeld Rosas <rr.rosas@...>
2017/02/15
Em 15-02-2017 05:05, Daniel Ferreira escreveu:
[#79543] Re: Immutable Strings vs Symbols
— Daniel Ferreira <subtileos@...>
2017/02/16
Hi Rodrigo,
[#79560] Re: Immutable Strings vs Symbols
— Rodrigo Rosenfeld Rosas <rr.rosas@...>
2017/02/16
Em 15-02-2017 22:39, Daniel Ferreira escreveu:
[ruby-core:79791] [Ruby trunk Bug#13196] Improve keyword argument errors when non-keyword arguments given
From:
sto.mar@...
Date:
2017-02-26 21:07:38 UTC
List:
ruby-core #79791
Issue #13196 has been updated by Marcus Stollsteimer.
Olivier Lacan wrote:
> ```diff
> + if (req_key_num > 0) {
> + VALUE mesg = rb_attr_get(exc, idMesg);
> + rb_str_resize(mesg, RSTRING_LEN(mesg)-1);
> + rb_str_cat_cstr(mesg, "; required keyword");
> + if (req_key_num > 1) rb_str_cat_cstr(mesg, "s");
> + do {
> + rb_str_cat_cstr(mesg, ": ");
> + rb_str_append(mesg, rb_id2str(*keywords++));
> + rb_str_cat_cstr(mesg, ",");
> + } while (--req_key_num);
> ```
* I think `rb_str_cat_cstr(mesg, ": ");` in the while-loop doesn't work; ":" must be added before the loop, in the loop only " " to separate different entries
* suggestion: s/keyword/keyword argument/, since "keyword" might be confused with language keywords like `def`, `end`, ...
Regarding `code` vs. `:code`, IMHO for beginners it's much easier to understand without leading ":", similar to the usage in the call sequence, it's _not_ `explode(:code: 123)` but `explode(code: 123)`, and in the method body.
----------------------------------------
Bug #13196: Improve keyword argument errors when non-keyword arguments given
https://bugs.ruby-lang.org/issues/13196#change-63217
* Author: Olivier Lacan
* Status: Open
* Priority: Normal
* Assignee:
* Target version:
* ruby -v:
* Backport: 2.2: UNKNOWN, 2.3: UNKNOWN, 2.4: UNKNOWN
----------------------------------------
Given the following method definition:
```ruby
def explode(code:)
puts "Boom!"
end
```
If a Ruby user doesn't provide any arguments when calling the `explode` method, the following helpful feedback is given:
```ruby
explode
ArgumentError: missing keyword: code
```
But when a Ruby user mistakenly provides a regular argument, the exception message is obtuse and unhelpful:
```ruby
explode "1234"
ArgumentError: wrong number of arguments (given 1, expected 0)
```
This does not provide information to properly recover from the error. Worse, it's incorrect. It is not true that the method expected 0 arguments. The method expected 1 keyword argument.
Instead, Ruby should respond something like:
```ruby
explode "1234"
ArgumentError: missing keyword: code, given "1234" which is not a keyword argument.
```
One could argue that this situation would call for a different error class, perhaps a `KeywordArgumentError` that would inherit from `ArgumentError`, but that would extend the scope of this feature request a bit too far in my mind.
---Files--------------------------------
missing_kwargs.diff (1.2 KB)
--
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>