Bug #14176
closedUnclear error message when calling method with keyword arguments
Description
I (wrongly) created a method with the following signature:
def asd(first, options: {}); end
(notice that options is a keyword argument)
I called the method this way:
asd(arg, options)
And got the following misleading error:
ArgumentError: wrong number of arguments (given 2, expected 1)
It took me some time to realize that the options argument is a keyword argument:
method(:asd)
Object#asd(first, ?)
It would be much more helpful if the error would mention this:
ArgumentError: wrong number of arguments (given 2, expected 1 and 1 keyword argument: options)
Thanks!
        
           Updated by marcandre (Marc-Andre Lafortune) almost 8 years ago
          Updated by marcandre (Marc-Andre Lafortune) almost 8 years ago
          
          
        
        
      
      Note that Ruby 2.5 improves this since #13196 if options has only symbol keys:
asd(42, {a:1})  # => ArgumentError: unknown keyword: a
I agree the message could still be improved as you suggest.
        
           Updated by marcandre (Marc-Andre Lafortune) almost 8 years ago
          Updated by marcandre (Marc-Andre Lafortune) almost 8 years ago
          
          
        
        
      
      - Related to Bug #13196: Improve keyword argument errors when non-keyword arguments given added
        
           Updated by marcandre (Marc-Andre Lafortune) almost 8 years ago
          Updated by marcandre (Marc-Andre Lafortune) almost 8 years ago
          
          
        
        
      
      - Subject changed from Calling method with keyword arguments inconsistent behavior to Unclear error message when calling method with keyword arguments
        
           Updated by jeremyevans0 (Jeremy Evans) about 6 years ago
          Updated by jeremyevans0 (Jeremy Evans) about 6 years ago
          
          
        
        
      
      - Status changed from Open to Closed
With the separation of keyword arguments and positional arguments in #14183, I think this can be closed.