Skip to content

Commit

Permalink
Merge pull request #37 from MeasureAuthoringTool/MAT-7998_updatErrMsg…
Browse files Browse the repository at this point in the history
…WhenDefineNameIsKeyword

MAT-7998 update error message when definition name is key word
  • Loading branch information
sb-cecilialiu authored Dec 26, 2024
2 parents e06a562 + fd9b407 commit d5e35d5
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.cqframework.cql.cql2elm.CqlCompilerException;
import org.hl7.elm.r1.VersionedIdentifier;

Expand Down Expand Up @@ -113,18 +114,20 @@ private List<CqlCompilerException> filterBySyntax(
}

/*
* MAT-7995: error: "No Viable Input at 'define :'"
* MAT-7995: error: "no viable alternative at input 'define :'"
* should be customized as: "Definition is missing a name."
* This is done in cql-antlr-parse, so on the frontend we don't want a duplicate error message
* therefore we are filtering it out here.
* MAT-7998: error: "no viable alternative at input 'define KEYWORD'"
* should be customized as: "Definition names must not be a reserved word."
* The errors are handled in cql-antlr-parser, so on the front-end we don't want
* duplicate error message therefore we are filtering it out here.
*/
private List<CqlCompilerException> filterOutCustomErrors(
List<CqlCompilerException> filteredCqlTranslatorExceptions) {
return filteredCqlTranslatorExceptions.stream()
.filter(
cqlCompilerException ->
!"no viable alternative at input 'define :'"
.equalsIgnoreCase(cqlCompilerException.getMessage()))
!StringUtils.containsIgnoreCase(
cqlCompilerException.getMessage(), "no viable alternative at input 'define"))
.toList();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,28 @@ public void testFilterSyntaxException() {
CqlCompilerException syntaxException = filteredExceptions.get(0);
assertEquals(syntaxException.getClass(), CqlCompilerException.class);
}

@Test
public void testFilterOutCustomErrors() {
CqlCompilerException definitionKeyWordException =
new CqlCompilerException("no viable alternative at input 'define :'");
cqlTranslatorExceptions.add(definitionKeyWordException);
CqlTranslatorExceptionFilter filter =
new CqlTranslatorExceptionFilter(cqlData, false, cqlTranslatorExceptions);

List<CqlCompilerException> filteredExceptions = filter.filter();
assertTrue(filteredExceptions.size() == 0);
}

@Test
public void testFilterOutDefinitionWithKeywords() {
CqlCompilerException definitionKeyWordException =
new CqlCompilerException("no viable alternative at input 'define year'");
cqlTranslatorExceptions.add(definitionKeyWordException);
CqlTranslatorExceptionFilter filter =
new CqlTranslatorExceptionFilter(cqlData, false, cqlTranslatorExceptions);

List<CqlCompilerException> filteredExceptions = filter.filter();
assertTrue(filteredExceptions.size() == 0);
}
}

0 comments on commit d5e35d5

Please sign in to comment.