Improve validator error messages for bad json & turtle formats

This commit is contained in:
Grahame Grieve 2021-01-20 16:53:14 +11:00
parent 026a958e39
commit 00410604d7
4 changed files with 19 additions and 21 deletions

View File

@ -165,7 +165,6 @@ public class JsonParser extends ParserBase {
Set<String> processed = new HashSet<String>();
if (hasResourceType)
processed.add("resourceType");
processed.add("fhir_comments");
// note that we do not trouble ourselves to maintain the wire format order here - we don't even know what it was anyway
// first pass: process the properties
@ -218,7 +217,7 @@ public class JsonParser extends ParserBase {
}
} else {
if (property.isList()) {
logError(line(e), col(e), npath, IssueType.INVALID, context.formatMessage(I18nConstants.THIS_PROPERTY_MUST_BE_AN_ARRAY_NOT_, describeType(e)), IssueSeverity.ERROR);
logError(line(e), col(e), npath, IssueType.INVALID, context.formatMessage(I18nConstants.THIS_PROPERTY_MUST_BE_AN_ARRAY_NOT_, describeType(e), name, path), IssueSeverity.ERROR);
}
parseChildComplexInstance(npath, object, element, property, name, e);
}
@ -247,7 +246,7 @@ public class JsonParser extends ParserBase {
else
parseChildren(npath, child, n, false);
} else
logError(line(e), col(e), npath, IssueType.INVALID, context.formatMessage(I18nConstants.THIS_PROPERTY_MUST_BE__NOT_, (property.isList() ? "an Array" : "an Object"), describe(e)), IssueSeverity.ERROR);
logError(line(e), col(e), npath, IssueType.INVALID, context.formatMessage(I18nConstants.THIS_PROPERTY_MUST_BE__NOT_, (property.isList() ? "an Array" : "an Object"), describe(e), name, npath), IssueSeverity.ERROR);
}
private String describe(JsonElement e) {
@ -273,11 +272,11 @@ public class JsonParser extends ParserBase {
if (property.isList()) {
boolean ok = true;
if (!(main == null || main instanceof JsonArray)) {
logError(line(main), col(main), npath, IssueType.INVALID, context.formatMessage(I18nConstants.THIS_PROPERTY_MUST_BE_AN_ARRAY_NOT_A_, describe(main)), IssueSeverity.ERROR);
logError(line(main), col(main), npath, IssueType.INVALID, context.formatMessage(I18nConstants.THIS_PROPERTY_MUST_BE_AN_ARRAY_NOT_, describe(main), name, path), IssueSeverity.ERROR);
ok = false;
}
if (!(fork == null || fork instanceof JsonArray)) {
logError(line(fork), col(fork), npath, IssueType.INVALID, context.formatMessage(I18nConstants.THIS_BASE_PROPERTY_MUST_BE_AN_ARRAY_NOT_A_, describe(main)), IssueSeverity.ERROR);
logError(line(fork), col(fork), npath, IssueType.INVALID, context.formatMessage(I18nConstants.THIS_BASE_PROPERTY_MUST_BE_AN_ARRAY_NOT_, describe(main), name, path), IssueSeverity.ERROR);
ok = false;
}
if (ok) {
@ -307,9 +306,9 @@ public class JsonParser extends ParserBase {
JsonElement main, JsonElement fork) throws FHIRException {
if (main != null && !(main instanceof JsonPrimitive))
logError(line(main), col(main), npath, IssueType.INVALID, context.formatMessage(
I18nConstants.THIS_PROPERTY_MUST_BE_AN_SIMPLE_VALUE_NOT_, describe(main)), IssueSeverity.ERROR);
I18nConstants.THIS_PROPERTY_MUST_BE_AN_SIMPLE_VALUE_NOT_, describe(main), name, npath), IssueSeverity.ERROR);
else if (fork != null && !(fork instanceof JsonObject))
logError(line(fork), col(fork), npath, IssueType.INVALID, context.formatMessage(I18nConstants.THIS_PROPERTY_MUST_BE_AN_OBJECT_NOT_, describe(fork)), IssueSeverity.ERROR);
logError(line(fork), col(fork), npath, IssueType.INVALID, context.formatMessage(I18nConstants.THIS_PROPERTY_MUST_BE_AN_OBJECT_NOT_, describe(fork), name, npath), IssueSeverity.ERROR);
else {
Element n = new Element(name, property).markLocation(line(main != null ? main : fork), col(main != null ? main : fork));
element.getChildren().add(n);

View File

@ -209,13 +209,13 @@ public class TurtleParser extends ParserBase {
// todo: check type
n.setValue(value);
} else
logError(object.getLine(), object.getCol(), npath, IssueType.INVALID, context.formatMessage(I18nConstants.THIS_PROPERTY_MUST_BE_A_LITERAL_NOT_A_, e.getClass().getName()), IssueSeverity.ERROR);
logError(object.getLine(), object.getCol(), npath, IssueType.INVALID, context.formatMessage(I18nConstants.THIS_PROPERTY_MUST_BE_A_LITERAL_NOT_, "a "+e.getClass().getName()), IssueSeverity.ERROR);
}
} else
parseChildren(src, npath, child, n, false);
} else
logError(object.getLine(), object.getCol(), npath, IssueType.INVALID, context.formatMessage(I18nConstants.THIS_PROPERTY_MUST_BE_A_URI_OR_BNODE_NOT_A_, e.getClass().getName()), IssueSeverity.ERROR);
logError(object.getLine(), object.getCol(), npath, IssueType.INVALID, context.formatMessage(I18nConstants.THIS_PROPERTY_MUST_BE_A_URI_OR_BNODE_NOT_, "a "+e.getClass().getName()), IssueSeverity.ERROR);
}

View File

@ -429,17 +429,16 @@ public class I18nConstants {
public static final String TERMINOLOGY_TX_NOSVC_BOUND_EXT = "TERMINOLOGY_TX_NOSVC_BOUND_EXT";
public static final String TEXT_SHOULD_NOT_BE_PRESENT = "Text_should_not_be_present";
public static final String THE_BASE_SNAPSHOT_MARKS_A_SLICING_AS_CLOSED_BUT_THE_DIFFERENTIAL_TRIES_TO_EXTEND_IT_IN__AT__ = "The_base_snapshot_marks_a_slicing_as_closed_but_the_differential_tries_to_extend_it_in__at__";
public static final String THIS_BASE_PROPERTY_MUST_BE_AN_ARRAY_NOT_A_ = "This_base_property_must_be_an_Array_not_a_";
public static final String THIS_BASE_PROPERTY_MUST_BE_AN_ARRAY_NOT_ = "This_base_property_must_be_an_Array_not_";
public static final String THIS_CANNOT_BE_PARSED_AS_A_FHIR_OBJECT_NO_NAME = "This_cannot_be_parsed_as_a_FHIR_object_no_name";
public static final String THIS_DOES_NOT_APPEAR_TO_BE_A_FHIR_RESOURCE_UNKNOWN_NAMESPACENAME_ = "This_does_not_appear_to_be_a_FHIR_resource_unknown_namespacename_";
public static final String THIS_DOES_NOT_APPEAR_TO_BE_A_FHIR_RESOURCE_UNKNOWN_NAME_ = "This_does_not_appear_to_be_a_FHIR_resource_unknown_name_";
public static final String THIS_ELEMENT_DOES_NOT_MATCH_ANY_KNOWN_SLICE_ = "This_element_does_not_match_any_known_slice_";
public static final String THIS_PROPERTY_MUST_BE_AN_ARRAY_NOT_ = "This_property_must_be_an_Array_not_";
public static final String THIS_PROPERTY_MUST_BE_AN_ARRAY_NOT_A_ = "This_property_must_be_an_Array_not_a_";
public static final String THIS_PROPERTY_MUST_BE_AN_OBJECT_NOT_ = "This_property_must_be_an_object_not_";
public static final String THIS_PROPERTY_MUST_BE_AN_SIMPLE_VALUE_NOT_ = "This_property_must_be_an_simple_value_not_";
public static final String THIS_PROPERTY_MUST_BE_A_LITERAL_NOT_A_ = "This_property_must_be_a_Literal_not_a_";
public static final String THIS_PROPERTY_MUST_BE_A_URI_OR_BNODE_NOT_A_ = "This_property_must_be_a_URI_or_bnode_not_a_";
public static final String THIS_PROPERTY_MUST_BE_A_LITERAL_NOT_ = "This_property_must_be_a_Literal_not_";
public static final String THIS_PROPERTY_MUST_BE_A_URI_OR_BNODE_NOT_ = "This_property_must_be_a_URI_or_bnode_not_";
public static final String THIS_PROPERTY_MUST_BE__NOT_ = "This_property_must_be__not_";
public static final String THIS__CANNOT_BE_PARSED_AS_A_FHIR_OBJECT_NO_NAMESPACE = "This__cannot_be_parsed_as_a_FHIR_object_no_namespace";
public static final String TYPE_CHECKS_FIXED_CC = "TYPE_CHECKS_FIXED_CC";

View File

@ -367,10 +367,10 @@ Error_parsing_JSON_the_primitive_value_must_be_a_string = Error parsing JSON: th
Error_parsing_JSON_the_primitive_value_must_be_a_number = Error parsing JSON: the primitive value must be a number
Error_parsing_JSON_the_primitive_value_must_be_a_boolean = Error parsing JSON: the primitive value must be a boolean
Error_parsing_XHTML_ = Error parsing XHTML: {0}
This_property_must_be_an_object_not_ = This property must be an object, not {0}
This_property_must_be_an_simple_value_not_ = This property must be an simple value, not {0}
This_property_must_be__not_ = This property must be {0}, not {1}
This_property_must_be_an_Array_not_ = This property must be an Array, not {0}
This_property_must_be_an_object_not_ = This property must be an object, not {0} ({1} at {2})
This_property_must_be_an_simple_value_not_ = This property must be an simple value, not {0} ({1} at {2})
This_property_must_be__not_ = The property {2} must be {0}, not {1} (at {3})
This_property_must_be_an_Array_not_ = The property {1} must be a JSON Array, not {0} (at {2})
Unrecognised_property_ = Unrecognised property ''@{0}''
Object_must_have_some_content = Object must have some content
Error_parsing_JSON_ = Error parsing JSON: {0}
@ -384,8 +384,8 @@ Element_must_have_some_content = Element must have some content
No_processing_instructions_allowed_in_resources = No processing instructions allowed in resources
Unknown_resource_type_missing_rdfstype = Unknown resource type (missing rdfs:type)
reference_to__cannot_be_resolved = reference to {0} cannot be resolved
This_property_must_be_a_URI_or_bnode_not_a_ = This property must be a URI or bnode, not a {0}
This_property_must_be_a_Literal_not_a_ = This property must be a Literal, not a {0}
This_property_must_be_a_URI_or_bnode_not_ = This property must be a URI or bnode, not {0}
This_property_must_be_a_Literal_not_ = This property must be a Literal, not {0}
Unrecognised_predicate_ = Unrecognised predicate ''{0}''
Error_parsing_Turtle_ = Error parsing Turtle: {0}
Unexpected_datatype_for_rdfstype = Unexpected datatype for rdfs:type
@ -437,8 +437,8 @@ Unable_to_resolve_system__value_set_expansion_has_multiple_systems = Unable to r
Unable_to_resolve_system__value_set_has_no_includes_or_expansion = Unable to resolve system - value set has no includes or expansion
Unable_to_resolve_system__value_set_has_excludes = Unable to resolve system - value set has excludes
Unable_to_resolve_system__no_value_set = Unable to resolve system - no value set
This_base_property_must_be_an_Array_not_a_ = This base property must be an Array, not a {0}
This_property_must_be_an_Array_not_a_ = This property must be an Array, not a {0}
This_base_property_must_be_an_Array_not_ = This base property must be an Array, not {0}
This_property_must_be_an_Array_not_ = This property must be an Array, not {0}
documentmsg = (document)
xml_attr_value_invalid = The XML Attribute {0} has an illegal character
xml_encoding_invalid = The XML encoding is invalid (must be UTF-8)