awesome-print / awesome_print

Pretty print your Ruby objects with style -- in full color and with proper indentation
http://github.com/michaeldv/awesome_print
MIT License
4.07k stars 454 forks source link

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

Open Irostovsky opened 6 years ago

Irostovsky commented 6 years ago
[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 commented 6 years ago

+1

sunsations commented 6 years ago

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

Chadh13 commented 6 years ago

^ 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 commented 4 years ago

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 commented 4 years ago

+1

LucasKuhn commented 3 years ago

+1

stdedos commented 3 years ago

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 commented 3 years ago

This commit https://github.com/ruby/irb/commit/c5ea79d5cecea9cae6ad0c1f31703a98cd329431 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 commented 3 years ago

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 commented 3 years ago

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)?