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

json_pure: Parser Constructor Error With Ruby 3.3.5 Using Version 2.7.4 #651

Closed
Hohlen opened this issue Oct 25, 2024 · 13 comments
Closed

Comments

@Hohlen
Copy link

Hohlen commented Oct 25, 2024

Started getting the following error after upgrading to version 2.7.4 using Ruby 3.3.5. This error does not occur with version 2.7.2 that I rolled back to:

/Users/john/.rbenv/versions/3.3.5/lib/ruby/gems/3.3.0/gems/json_pure-2.7.4/lib/json/common.rb:222:in `initialize': wrong number of arguments (given 2, expected 1) (ArgumentError)

  **Parser.new(source, opts).parse**
             ^^^^^^^^^^^^
from /Users/john/.rbenv/versions/3.3.5/lib/ruby/gems/3.3.0/gems/json_pure-2.7.4/lib/json/common.rb:222:in `new'
from /Users/john/.rbenv/versions/3.3.5/lib/ruby/gems/3.3.0/gems/json_pure-2.7.4/lib/json/common.rb:222:in `parse'
from /Users/john/.rbenv/versions/3.3.5/lib/ruby/gems/3.3.0/gems/simplecov-0.22.0/lib/simplecov/last_run.rb:18:in `read'
from /Users/john/.rbenv/versions/3.3.5/lib/ruby/gems/3.3.0/gems/simplecov-0.22.0/lib/simplecov/exit_codes/maximum_coverage_drop_check.rb:39:in `last_run'
from /Users/john/.rbenv/versions/3.3.5/lib/ruby/gems/3.3.0/gems/simplecov-0.22.0/lib/simplecov/exit_codes/maximum_coverage_drop_check.rb:12:in `failing?'
@Hohlen Hohlen changed the title Parser Error With Ruby 3.3.5 Version 2.7.4 Parser Error With Ruby 3.3.5 Using Version 2.7.4 Oct 25, 2024
@Hohlen Hohlen changed the title Parser Error With Ruby 3.3.5 Using Version 2.7.4 Parser Constructor Error With Ruby 3.3.5 Using Version 2.7.4 Oct 25, 2024
@Hohlen Hohlen changed the title Parser Constructor Error With Ruby 3.3.5 Using Version 2.7.4 json_pure: Parser Constructor Error With Ruby 3.3.5 Using Version 2.7.4 Oct 25, 2024
@casperisfine
Copy link

Hum, this is weird. simplecov is doing a very mundane JSON.parse call: https://github.com/simplecov-ruby/simplecov/blob/v0.22.0/lib/simplecov/last_run.rb#L18C9-L18C48

>> gem 'json_pure'
=> true
>> require 'json/pure'
=> true
>> JSON.parse('{}', symbolize_names: true)
=> {}
>> JSON::VERSION
=> "2.7.4"
>> JSON.parser
=> JSON::Ext::Parser
>> JSON.parser = JSON::Pure::Parser
=> JSON::Pure::Parser
>> JSON.parse('{}', symbolize_names: true)

Any chance you'd have a reproduction script of some sort?

Or at the very least put some debug statements in there to understand what JSON::Parser is, e.g. p JSON::Parser and p JSON::Parser.instance_method(:initialize).

Because I don't see how Parser#initialize can possibly not accept two arguments.

@Hohlen
Copy link
Author

Hohlen commented Oct 25, 2024

Hi. Sorry I don't have a way to easily reproduce since it's not my code (instead it's code coverage report being executed via rake).

@byroot
Copy link
Member

byroot commented Oct 25, 2024

Right, but this is happening on your machine, right? If you you can bundle open simplecov and put some debug statement or a debugger there.

@Hohlen
Copy link
Author

Hohlen commented Oct 25, 2024

Yea, I should/could. I just got home from hospital form major wrist surgery and can barely type. The issue does not occur with version 2.7.3 if that helps. It's definitely specific to 2.7.4.

@byroot
Copy link
Member

byroot commented Oct 25, 2024

No need to justified yourself, my requests do imply a "whenever you get the chance". Hope you feel better soon.

The issue does not occur with version 2.7.3 if that helps. It's definitely specific to 2.7.4.

That does help narrow it down, thank you.

@byroot
Copy link
Member

byroot commented Oct 25, 2024

Ok, I think I know what's up. I bet json_pure is at 2.7.4, but you also have the json gem at another version.

Ref: #650

@Hohlen
Copy link
Author

Hohlen commented Oct 25, 2024

Actually, tell me what to add to debug. I don't want to leave you hanging:
image

overage report generated for Functional Tests, Unit Tests to /Users/john/git/fantasy-golf/coverage.
Line Coverage: 65.96% (5208 / 7896)
debug JSON.parse(...)
{"result":{"line":65.95}}
/Users/john/.rbenv/versions/3.3.5/lib/ruby/gems/3.3.0/gems/json_pure-2.7.4/lib/json/common.rb:222:in `initialize': wrong number of arguments (given 2, expected 1) (ArgumentError)

  Parser.new(source, opts).parse
             ^^^^^^^^^^^^

@Hohlen
Copy link
Author

Hohlen commented Oct 25, 2024

I don't have the json gem specified, actually. Is that what I need to do?

    csv (3.3.0)
    date (3.3.4)
    docile (1.4.1)
    ed25519 (1.3.0)
    fiddle (1.1.4)
    i18n (1.14.6)
      concurrent-ruby (~> 1.0)
    jmespath (1.6.2)
    json_pure (2.7.4)
    logger (1.6.1)
    metaclass (0.0.4)

@byroot
Copy link
Member

byroot commented Oct 25, 2024

No need, I found a repro:

require 'bundler/inline'

gemfile do
  source 'https://rubygems.org'
  gem 'json_pure', "2.7.4"
  gem 'json', "~> 2.6.0"
end

require 'json/ext'
require 'json/pure'
JSON.parser = JSON::Ext::Parser
JSON.parse('{}', symbolize_names: true)
$ ruby foo.rb
JSON::Pure::Parser
/Users/byroot/.gem/rubies/3.3.4/gems/json_pure-2.7.4/lib/json/common.rb:222:in `initialize': wrong number of arguments (given 2, expected 1) (ArgumentError)

      Parser.new(source, opts).parse
                 ^^^^^^^^^^^^
	from /Users/byroot/.gem/rubies/3.3.4/gems/json_pure-2.7.4/lib/json/common.rb:222:in `new'
	from /Users/byroot/.gem/rubies/3.3.4/gems/json_pure-2.7.4/lib/json/common.rb:222:in `parse'
	from foo.rb:13:in `<main>'

You can rest your wrist :)

I don't have the json gem specified, actually.

It probably is the stdlib version, I'll try to adjust my repro.

@byroot
Copy link
Member

byroot commented Oct 25, 2024

Yep, even simpler:

require 'bundler/inline'

gemfile do
  source 'https://rubygems.org'
  gem 'json_pure', "2.7.4"
end

require 'json'
JSON.parse('{}', symbolize_names: true)

@Hohlen
Copy link
Author

Hohlen commented Oct 25, 2024

Nice. You nailed it!
Do I need to add a gem or does this require a code fix to the json_pure lib?

@byroot
Copy link
Member

byroot commented Oct 25, 2024

Yeah, I'll have to cut a json_pure 2.7.5, in the meantime you can lock it to 2.7.3.

Thank you very much for the bug report.

byroot added a commit to byroot/json that referenced this issue Oct 25, 2024
Prior to 2.7.3, `JSON::Ext::Parser` would only take kwargs.
So if json_pure 2.7.4 is loaded with `json <= 2.7.2` (or stdlib)
it blows up.

Ref: ruby#650
Fix: ruby#651
@byroot byroot closed this as completed in 4d9dc98 Oct 25, 2024
@Hohlen
Copy link
Author

Hohlen commented Oct 25, 2024

Yeah, I'll have to cut a json_pure 2.7.5, in the meantime you can lock it to 2.7.3.

Thank you very much for the bug report.

Thank you for the quick fix!

hsbt pushed a commit to hsbt/ruby that referenced this issue Oct 26, 2024
Prior to 2.7.3, `JSON::Ext::Parser` would only take kwargs.
So if json_pure 2.7.4 is loaded with `json <= 2.7.2` (or stdlib)
it blows up.

Ref: ruby/json#650
Fix: ruby/json#651

ruby/json@4d9dc98817
hsbt pushed a commit to hsbt/ruby that referenced this issue Oct 26, 2024
Prior to 2.7.3, `JSON::Ext::Parser` would only take kwargs.
So if json_pure 2.7.4 is loaded with `json <= 2.7.2` (or stdlib)
it blows up.

Ref: ruby/json#650
Fix: ruby/json#651

ruby/json@4d9dc98817
hsbt pushed a commit to ruby/ruby that referenced this issue Oct 26, 2024
Prior to 2.7.3, `JSON::Ext::Parser` would only take kwargs.
So if json_pure 2.7.4 is loaded with `json <= 2.7.2` (or stdlib)
it blows up.

Ref: ruby/json#650
Fix: ruby/json#651

ruby/json@4d9dc98817
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

No branches or pull requests

3 participants