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::Validator.fully_validate(filename, data) fails when trying to parse filename as JSON #366

Closed
faucct opened this issue Nov 24, 2016 · 2 comments

Comments

@faucct
Copy link

faucct commented Nov 24, 2016

Hello, I have noticed that this code fails with JSON::ParserError though it should have fallen back to reading from file:

require 'json'
require 'json-schema'
require 'oj_mimic_json'

JSON::Validator.fully_validate('test.json', {})

I have dug deeper and found that the explanation of that.
When I require your gem, it requires multi_json and makes it use its default adapter. This makes it cache JSON::ParserError here. After that I require oj_mimic_json which overrides JSON::ParserError here. Now when JSON.parse throws an error, MultiJSON.load fails to wrap it inside MultiJSON::ParseError and as a result you fail to rescue it here and don't even try to read the file.
I am not sure which gem is most guilty here, so I will mention this issue there too. The problem can be reproduced without your gem:

require 'json'
require 'multi_json'
MultiJson.use nil
require 'oj_mimic_json'

# Throws JSON::ParserError instead of MultiJSON::ParseError
MultiJson.load('test.json')
@RST-J
Copy link
Contributor

RST-J commented Nov 24, 2016

We know that there is a problem with mulit-json. There is a PR ( #339 ) which will remove multi-json.
Can you uninstall multi-json? If multi-json is not installed, it should work. If you cannot uninstall multi-json because another project needs it, then use a custom gemset. This of course won't help if you need multi-json in the very same project.

@faucct
Copy link
Author

faucct commented Nov 25, 2016

Actually my PR ohler55/oj#320 in oj was accepted, so it makes the issue fixed. Closing.

@faucct faucct closed this as completed Nov 25, 2016
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

2 participants