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

ArgumentError: wrong number of arguments (given 1, expected 0) #330

Open
Irostovsky opened this issue Jan 12, 2018 · 10 comments
Open

ArgumentError: wrong number of arguments (given 1, expected 0) #330

Irostovsky opened this issue Jan 12, 2018 · 10 comments

Comments

@Irostovsky
Copy link

[1] pry(main)> uri = URI('http://www.example.com/todo.cgi')
#<URI::HTTP http://www.example.com/todo.cgi>
[2] pry(main)> req = Net::HTTP::Post.new(uri, {q: 'asd'})
(pry) output error: #<ArgumentError: wrong number of arguments (given 1, expected 0)>
/Users/ir/.rvm/gems/ruby-2.3.1@guestready/gems/awesome_print-1.8.0/lib/awesome_print/formatter.rb:114:in `convert_to_hash'
/Users/ir/.rvm/gems/ruby-2.3.1@guestready/gems/awesome_print-1.8.0/lib/awesome_print/formatter.rb:47:in `awesome_self'
/Users/ir/.rvm/gems/ruby-2.3.1@guestready/gems/awesome_print-1.8.0/lib/awesome_print/formatter.rb:28:in `format'
/Users/ir/.rvm/gems/ruby-2.3.1@guestready/gems/awesome_print-1.8.0/lib/awesome_print/inspector.rb:115:in `unnested'
/Users/ir/.rvm/gems/ruby-2.3.1@guestready/gems/awesome_print-1.8.0/lib/awesome_print/inspector.rb:74:in `awesome'
/Users/ir/.rvm/gems/ruby-2.3.1@guestready/gems/awesome_print-1.8.0/lib/awesome_print/core_ext/kernel.rb:10:in `ai'
/Users/ir/.rvm/gems/ruby-2.3.1@guestready/gems/awesome_print-1.8.0/lib/awesome_print/custom_defaults.rb:45:in `block in pry!'
/Users/ir/.rvm/gems/ruby-2.3.1@guestready/gems/pry-0.11.3/lib/pry/pry_instance.rb:367:in `show_result'
/Users/ir/.rvm/gems/ruby-2.3.1@guestready/gems/pry-0.11.3/lib/pry/pry_instance.rb:336:in `block in handle_line'
/Users/ir/.rvm/gems/ruby-2.3.1@guestready/gems/pry-0.11.3/lib/pry/pry_class.rb:395:in `critical_section'
/Users/ir/.rvm/gems/ruby-2.3.1@guestready/gems/pry-0.11.3/lib/pry/pry_instance.rb:335:in `handle_line'
/Users/ir/.rvm/gems/ruby-2.3.1@guestready/gems/pry-0.11.3/lib/pry/pry_instance.rb:243:in `block (2 levels) in eval'
/Users/ir/.rvm/gems/ruby-2.3.1@guestready/gems/pry-0.11.3/lib/pry/pry_instance.rb:242:in `catch'
/Users/ir/.rvm/gems/ruby-2.3.1@guestready/gems/pry-0.11.3/lib/pry/pry_instance.rb:242:in `block in eval'
/Users/ir/.rvm/gems/ruby-2.3.1@guestready/gems/pry-0.11.3/lib/pry/pry_instance.rb:241:in `catch'

The reason that instance of the Net::HTTP::Post POST has the method method. And into https://github.com/awesome-print/awesome_print/blob/master/lib/awesome_print/formatter.rb#L114 tries to call method with param.

[1] pry(main)> uri = URI('http://www.example.com/todo.cgi')
=> #<URI::HTTP http://www.example.com/todo.cgi>
[2] pry(main)> req = Net::HTTP::Post.new(uri, {q: 'asd'})
=> #<Net::HTTP::Post POST>
[3] pry(main)> req.method
=> "POST"
@sunsations
Copy link

+1

@sunsations
Copy link

Works for me, if I disable the IRB Integration (https://github.com/awesome-print/awesome_print#irb-integration)

Chadh13 added a commit to Chadh13/awesome_print that referenced this issue Feb 4, 2018
The array_formatter was always returning  an empty array when associated
objects were called via a `has_many through:` relationship because they
are loaded as a collection, and the collection is always considered
empty.

resolves: awesome-print#330
@Chadh13
Copy link
Contributor

Chadh13 commented Feb 4, 2018

^ is an accidental ref. I was experiencing a similar error however it is specifically with the array_formatter, not the hash_formatter... not entirely sure how to remove the ref. Sorry!

@bceppi
Copy link

bceppi commented Feb 25, 2020

Hi! I'm having the same problem. Is there any workaround for this for an app with awesome_print installed through the Gemfile?

@araslanov-e
Copy link

+1

1 similar comment
@LucasKuhn
Copy link

+1

@stdedos
Copy link

stdedos commented Sep 4, 2020

You are aware that commenting "+1" doesn't help, makes no difference, and it's spamming us with a useless message, right?

There is this
image
neat little button, which you can press to add your "participation" to the issue

@febeling
Copy link
Contributor

febeling commented Dec 4, 2020

This commit ruby/irb@c5ea79d in IRB changes the signature of IRB::Irb#output_value to add one default argument.

When overriding same method in awesome_print without this default parameter, the error is raised.

@febeling
Copy link
Contributor

febeling commented Dec 6, 2020

I just realize this issue is not about the ArgumentError that I was experiencing. The one I encountered (and fixed in the PR) is avoided by disabling awesome_print support for IRB. This is probably the one @sunsations saw too, but that seems to be a separate issue. (It isn't, as his comment from a time before the IRB change.)

That issue would be fixed by my fix/PR (closed now).

Also, this issue is from 2018, and the change in irb which I thought was the cause dates from August 2020.

@febeling
Copy link
Contributor

febeling commented Dec 6, 2020

I think I'm at the bottom of this. net/http's Net::HTTPGenericRequest has an attribute with a reader method; that conflicts with Ruby's core Object#method(sym) .

Now awesome_print in the fallback_formatter converts objects to hashes for output. It relies on Object#method to check for that here: https://github.com/awesome-print/awesome_print/blob/awesomeprint2/lib/awesome_print/formatters/fallback_formatter.rb#L41 (for the version 2 branch, which is pre-released).

How to fix this? The real problem is the net/http class shadowing Object#method. I don't see an easy general fix. Possibly add another special formatter to awesome_print, as there are some already for other classes (24 files for various ruby core classes, I don't see any stdlib formatters for now)?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants