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

Handle MultiJson ParseErrors #20

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

ethanabrooks
Copy link

Previously, the first rspec test was failing because the matcher.rb was only rescuing JSON::ParseErrors but not MultiJson::ParseErrors. For whatever reason, the empty string raised the latter, not the former, error.

With this minor fix, all tests are green.

@@ -24,6 +24,8 @@ def matches?(response)
false
rescue JSON::ParserError
raise InvalidSchemaError
rescue MultiJson::ParseError
raise InvalidSchemaError
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the patch!

What do you think about combining the errors on a single line:

rescue JSON::ParserError, MultiJson::ParseError
  raise InvalidSchemaError
end

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sold! Let's do it.

@seanpdoyle
Copy link
Collaborator

On further inspection, what is the source of the MultiJson::ParseError?

What happens when the multi_json isn't included as a dependency?

@ethanabrooks
Copy link
Author

For some reason, it tries to parse the empty string JSON schema in the first rspec test with MultiJson, not the regular JSON validator.

I looked up the docs for MultiJson, and it seems to be kind of a catch-all JSON coder. Not sure how Ruby decides between multijson and the regular JSON validator.

On Oct 6, 2015, at 9:10 PM, Sean Doyle notifications@github.com wrote:

On further inspection, what is the source of the MultiJson::ParseError?

What happens when the multi_json https://github.com/intridea/multi_json isn't included?


Reply to this email directly or view it on GitHub #20 (comment).

@ethanabrooks
Copy link
Author

A small follow up:
I placed a break point just above the call to JSON::Validator and confirmed that, for some reason, when we call that method, ruby invokes the MultiJson library. The documentation on JSON is pretty sparse, but I will dig a little further to figure out why.

On Oct 6, 2015, at 9:13 PM, Ethan Brooks ethanabrooks@gmail.com wrote:

For some reason, it tries to parse the empty string JSON schema in the first rspec test with MultiJson, not the regular JSON validator.

I looked up the docs for MultiJson, and it seems to be kind of a catch-all JSON coder. Not sure how Ruby decides between multijson and the regular JSON validator.

On Oct 6, 2015, at 9:10 PM, Sean Doyle <notifications@github.com mailto:notifications@github.com> wrote:

On further inspection, what is the source of the MultiJson::ParseError?

What happens when the multi_json https://github.com/intridea/multi_json isn't included?


Reply to this email directly or view it on GitHub #20 (comment).

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 this pull request may close these issues.

2 participants