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

Validate() throws exception on non-JSON string #776

Closed
RodneyRichardson opened this issue Sep 14, 2018 · 4 comments
Closed

Validate() throws exception on non-JSON string #776

RodneyRichardson opened this issue Sep 14, 2018 · 4 comments

Comments

@RodneyRichardson
Copy link

When validating an invalid JSON document (truncated), I would expect Validate() to return an appropriate ValidationError. Instead it throws a JsonReaderException (thrown by JsonTextReader):

Newtonsoft.Json.JsonReaderException: Unterminated string. Expected delimiter: ". Path 'blah', line 3, position 64.
   at Newtonsoft.Json.JsonTextReader.ReadStringIntoBuffer(Char quote)
   at Newtonsoft.Json.JsonTextReader.ParseValue()
   at Newtonsoft.Json.Linq.JContainer.ReadContentFrom(JsonReader r, JsonLoadSettings settings)
   at Newtonsoft.Json.Linq.JContainer.ReadTokenFrom(JsonReader reader, JsonLoadSettings options)
   at Newtonsoft.Json.Linq.JObject.Load(JsonReader reader, JsonLoadSettings settings)
   at Newtonsoft.Json.Linq.JToken.ReadFrom(JsonReader reader, JsonLoadSettings settings)
   at Newtonsoft.Json.Linq.JToken.Parse(String json, JsonLoadSettings settings)
   at NJsonSchema.JsonSchema4.Validate(String jsonData)

Suggest catching this exception, and adding a new ValidationErrorKind.

@RicoSuter
Copy link
Owner

RicoSuter commented Sep 14, 2018

Yes, why not... it may be a breaking change for some - but fine with me. Can you create a PR?

@RodneyRichardson
Copy link
Author

I am happy to do that

@RodneyRichardson
Copy link
Author

RodneyRichardson commented Sep 17, 2018

Looking at this in more detail, this doesn't really fit in with what the ValidationError encapsulates (i.e. an error with a specific property). JsonReaderException doesn't map cleanly to this, so I think it's nicer to leave it as it is.

I'm happy for this to be resolved as "Won't fix", and perhaps just update documentation?

@RicoSuter
Copy link
Owner

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

No branches or pull requests

2 participants