Merge pull request #401 from hapifhir/gg-fix-slicing-errors

improve error message for FHIRPath errors when slicing
This commit is contained in:
Grahame Grieve 2020-12-15 14:27:08 +11:00 committed by GitHub
commit b43431a65c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 16 additions and 8 deletions

View File

@ -149,7 +149,7 @@ public class FHIRLexer {
}
public FHIRLexerException error(String msg, String location) {
return new FHIRLexerException("Error in "+name+" at "+location+": "+msg);
return new FHIRLexerException("Error @"+location+": "+msg);
}
public void next() throws FHIRLexerException {

View File

@ -67,6 +67,7 @@ public class I18nConstants {
public static final String DISCRIMINATOR__IS_BASED_ON_ELEMENT_EXISTENCE_BUT_SLICE__NEITHER_SETS_MIN1_OR_MAX0 = "Discriminator__is_based_on_element_existence_but_slice__neither_sets_min1_or_max0";
public static final String DISCRIMINATOR__IS_BASED_ON_TYPE_BUT_SLICE__IN__HAS_MULTIPLE_TYPES_ = "Discriminator__is_based_on_type_but_slice__in__has_multiple_types_";
public static final String DISCRIMINATOR__IS_BASED_ON_TYPE_BUT_SLICE__IN__HAS_NO_TYPES = "Discriminator__is_based_on_type_but_slice__in__has_no_types";
public static final String DISCRIMINATOR_BAD_PATH = "DISCRIMINATOR_BAD_PATH";
public static final String DISPLAY_NAME_FOR__SHOULD_BE_ONE_OF__INSTEAD_OF_ = "Display_Name_for__should_be_one_of__instead_of_";
public static final String DOCUMENT = "documentmsg";
public static final String DOCUMENT_DATE_REQUIRED = "Bundle_Document_Date_Missing";
@ -77,6 +78,7 @@ public class I18nConstants {
public static final String ELEMENT_ID__NULL__ON_ = "element_id__null__on_";
public static final String ELEMENT_MUST_HAVE_SOME_CONTENT = "Element_must_have_some_content";
public static final String ELEMENT__NULL_ = "element__null_";
public static final String SLICING_CANNOT_BE_EVALUATED = "SLICING_CANNOT_BE_EVALUATED";
public static final String ERROR_AT_PATH__IN__TYPE_SLICING_WITH_SLICINGDISCRIMINATORCOUNT__1 = "Error_at_path__in__Type_slicing_with_slicingdiscriminatorcount__1";
public static final String ERROR_AT_PATH__IN__TYPE_SLICING_WITH_SLICINGDISCRIMINATORPATH__THIS = "Error_at_path__in__Type_slicing_with_slicingdiscriminatorpath__this";
public static final String ERROR_AT_PATH__IN__TYPE_SLICING_WITH_SLICINGDISCRIMINATORTYPE__TYPE = "Error_at_path__in__Type_slicing_with_slicingdiscriminatortype__type";
@ -180,7 +182,6 @@ public class I18nConstants {
public static final String ILLEGAL_PATH__IN_DIFFERENTIAL_IN__NAME_PORTION_EXCEEDS_64_CHARS_IN_LENGTH = "Illegal_path__in_differential_in__name_portion_exceeds_64_chars_in_length";
public static final String ILLEGAL_PATH__IN_DIFFERENTIAL_IN__NAME_PORTION_MISING_ = "Illegal_path__in_differential_in__name_portion_mising_";
public static final String ILLEGAL_PATH__IN_DIFFERENTIAL_IN__NO_UNICODE_WHITESPACE = "Illegal_path__in_differential_in__no_unicode_whitespace";
public static final String INTERNAL_ERROR = "Internal_error";
public static final String INTERNAL_ERROR___TYPE_NOT_KNOWN_ = "Internal_error___type_not_known_";
public static final String INTERNAL_INT_BAD_TYPE = "Internal_INT_Bad_Type";
public static final String INTERNAL_RECURSION_DETECTION_FIND_LOOP_PATH_RECURSION____CHECK_PATHS_ARE_VALID_FOR_PATH_ = "Internal_recursion_detection_find_loop_path_recursion____check_paths_are_valid_for_path_";

View File

@ -522,7 +522,6 @@ TYPE_CHECKS_PATTERN_CC = The pattern [system {0}, code {1}, and display ''{2}'']
TYPE_CHECKS_PATTERN_CC_US = The pattern [system {0}, code {1}, display ''{2}'' and userSelected {5}] defined in the profile {3} not found. Issues: {4}
TYPE_CHECKS_FIXED_CC = The pattern [system {0}, code {1}, and display ''{2}''] defined in the profile {3} not found. Issues: {4}
TYPE_CHECKS_FIXED_CC_US = The pattern [system {0}, code {1}, display ''{2}'' and userSelected {5}] defined in the profile {3} not found. Issues: {4}
Internal_error = Internal error: {0}
VALIDATION_VAL_GLOBAL_PROFILE_UNKNOWN = Global Profile reference ''{0}'' from IG {1} could not be resolved, so has not been checked
VALIDATION_VAL_PROFILE_SIGNPOST = Validate resource against profile {0}
VALIDATION_VAL_PROFILE_SIGNPOST_META = Validate resource against profile {0} - listed in meta
@ -632,4 +631,6 @@ SD_ED_SHOULD_BIND = The element {0} has a type that should have a binding ({1}),
SD_ED_SHOULD_BIND_WITH_VS = The element {0} has a type that should have a binding ({1}), but the binding has no value set
SD_ED_BIND_UNKNOWN_VS = The valueSet reference {1} on element {0} could not be resolved
SD_ED_BIND_NOT_VS = The valueSet reference {1} on element {0} points to something that is not a value set ({2})
SD_ED_BIND_NO_BINDABLE = The element {0} has a binding, but no bindable types are present {1}
SD_ED_BIND_NO_BINDABLE = The element {0} has a binding, but no bindable types are present {1}
DISCRIMINATOR_BAD_PATH = Error processing path expression for disciminator: {0} (src = ''{1}'')
SLICING_CANNOT_BE_EVALUATED = Slicing cannot be evaluated: {0}

View File

@ -772,7 +772,7 @@ public class InstanceValidator extends BaseValidator implements IResourceValidat
return true;
if (s.isOk()) {
if (s.getMessage() != null)
txWarning(errors, s.getTxLink(), IssueType.CODEINVALID, element.line(), element.col(), path, s == null, I18nConstants.INTERNAL_ERROR, s.getMessage());
throw new Error("Internal error: ok, but has error message '"+s.getMessage()+"'");
return true;
}
if (s.getErrorClass() != null && s.getErrorClass().isInfrastructure())
@ -2861,7 +2861,13 @@ public class InstanceValidator extends BaseValidator implements IResourceValidat
}
ElementDefinition ed = null;
ExpressionNode expr = fpe.parse(fixExpr(discriminator, null));
String fp = fixExpr(discriminator, null);
ExpressionNode expr = null;
try {
expr = fpe.parse(fp);
} catch (Exception e) {
throw new FHIRException(context.formatMessage(I18nConstants.DISCRIMINATOR_BAD_PATH, e.getMessage(), fp), e);
}
long t2 = System.nanoTime();
ed = fpe.evaluateDefinition(expr, profile, element);
timeTracker.sd(t2);
@ -2886,7 +2892,7 @@ public class InstanceValidator extends BaseValidator implements IResourceValidat
if (element == null)
throw new DefinitionException(context.formatMessage(I18nConstants.UNABLE_TO_RESOLVE_ELEMENT__IN_PROFILE_, id, p));
}
expr = fpe.parse(fixExpr(discriminator, null));
expr = fpe.parse(fp);
t2 = System.nanoTime();
ed = fpe.evaluateDefinition(expr, profile, element);
timeTracker.sd(t2);
@ -4694,7 +4700,7 @@ public class InstanceValidator extends BaseValidator implements IResourceValidat
ei.additionalSlice = true;
}
} catch (FHIRException e) {
rule(errors, IssueType.PROCESSING, ei.line(), ei.col(), ei.getPath(), false, I18nConstants.INTERNAL_ERROR, e.getMessage());
rule(errors, IssueType.PROCESSING, ei.line(), ei.col(), ei.getPath(), false, I18nConstants.SLICING_CANNOT_BE_EVALUATED, e.getMessage());
unsupportedSlicing = true;
childUnsupportedSlicing = true;
}