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

Handle parsing errors in semantic rules better #33052

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ public SemanticRules build(ApplicationPackage applicationPackage) {
try {
toMap(config); // validates config
ensureZeroOrOneDefaultRule(config);
} catch (ParseException | IOException e) {
throw new RuntimeException(e);
} catch (ParseException e) {
throw new IllegalArgumentException(e);
}
return rules;
}
Expand Down Expand Up @@ -109,7 +109,7 @@ private void ensureZeroOrOneDefaultRule(SemanticRulesConfig config) {
}
}

static Map<String, com.yahoo.prelude.semantics.RuleBase> toMap(SemanticRulesConfig config) throws ParseException, IOException {
static Map<String, com.yahoo.prelude.semantics.RuleBase> toMap(SemanticRulesConfig config) throws ParseException {
RuleImporter ruleImporter = new RuleImporter(config, true, new SimpleLinguistics());
Map<String, com.yahoo.prelude.semantics.RuleBase> ruleBaseMap = new HashMap<>();
for (SemanticRulesConfig.Rulebase ruleBaseConfig : config.rulebase()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class SemanticRulesTest {
private static final String rootWithDuplicateDefault = basePath + "semanticrules_with_duplicate_default_rule";

@Test
void semanticRulesTest() throws ParseException, IOException {
void semanticRulesTest() throws ParseException {
SemanticRuleBuilder ruleBuilder = new SemanticRuleBuilder();
SemanticRules rules = ruleBuilder.build(FilesApplicationPackage.fromFile(new File(root)));
SemanticRulesConfig.Builder configBuilder = new SemanticRulesConfig.Builder();
Expand All @@ -49,8 +49,8 @@ void semanticRulesTest() throws ParseException, IOException {
void rulesWithErrors() {
try {
new SemanticRuleBuilder().build(FilesApplicationPackage.fromFile(new File(rootWithErrors)));
fail("should fail with exception");
} catch (Exception e) {
fail("should fail with IllegalArgumentException, so that it is reported to the user as an error in application package");
} catch (IllegalArgumentException e) {
assertEquals("com.yahoo.prelude.semantics.parser.ParseException: Could not parse rule 'invalid'", e.getMessage());
}
}
Expand All @@ -59,8 +59,8 @@ void rulesWithErrors() {
void rulesWithDuplicateDefault() {
try {
new SemanticRuleBuilder().build(FilesApplicationPackage.fromFile(new File(rootWithDuplicateDefault)));
fail("should fail with exception");
} catch (Exception e) {
fail("should fail with IllegalArgumentException, so that it is reported to the user as an error in application package");
} catch (IllegalArgumentException e) {
assertEquals("Rules [one, other] are both marked as the default rule, there can only be one", e.getMessage());
}
}
Expand Down
Loading