Skip to content

Commit

Permalink
Avoid duplicate failure handling on syntax errors (#443)
Browse files Browse the repository at this point in the history
  • Loading branch information
fsteeg committed Sep 22, 2022
1 parent 318e5e9 commit f182204
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,17 @@ public void setWriteInvalid(final String writeInvalid) {

@Override
public void process(final String json) {
JSONObject object = null;
final JSONObject object;
try {
object = new JSONObject(json); // throws JSONException on syntax error
validate(json, object);
}
catch (final JSONException e) {
handleInvalid(json, null, e.getMessage());
}
}

private void validate(final String json, final JSONObject object) {
try {
initSchema();
schema.validate(object); // throws ValidationException if invalid
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public void testShouldInvalidateSyntaxError() {

@Test(expected = MetafactureException.class)
public void testShouldCatchMissingSchemaFile() {
new JsonValidator("").process("");
new JsonValidator("").process("{}");
}

@Test(expected = MetafactureException.class)
Expand Down

0 comments on commit f182204

Please sign in to comment.