Skip to content

Commit

Permalink
QuteProcessor - more concise format to report incorrect expressions
Browse files Browse the repository at this point in the history
- resolves #25724
  • Loading branch information
mkouba committed May 26, 2022
1 parent d7a1d28 commit 068bd67
Show file tree
Hide file tree
Showing 13 changed files with 32 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -177,39 +177,41 @@ void processTemplateErrors(TemplatesAnalysisBuildItem analysis, List<IncorrectEx
errors.add(TemplateException.builder()
.code(Code.INCORRECT_EXPRESSION)
.origin(incorrectExpression.origin)
.message("Incorrect expression found: \\{{}\\}\n\t- {}\n\t- at {}:{}")
.arguments(incorrectExpression.expression, incorrectExpression.reason,
findTemplatePath(analysis, incorrectExpression.origin.getTemplateGeneratedId()),
incorrectExpression.origin.getLine())
.message("{}:{} - \\{{}\\}: {}")
.arguments(findTemplatePath(analysis, incorrectExpression.origin.getTemplateGeneratedId()),
incorrectExpression.origin.getLine(), incorrectExpression.expression,
incorrectExpression.reason)
.build());
} else if (incorrectExpression.clazz != null) {
errors.add(TemplateException.builder()
.code(Code.INCORRECT_EXPRESSION)
.origin(incorrectExpression.origin)
.message(
"Incorrect expression found: \\{{}}\n\t- property/method [{}] not found on class [{}] nor handled by an extension method\n\t- at {}:{}")
.arguments(incorrectExpression.expression, incorrectExpression.property, incorrectExpression.clazz,
findTemplatePath(analysis, incorrectExpression.origin.getTemplateGeneratedId()),
incorrectExpression.origin.getLine())
"{}:{} - \\{{}}: Property/method [{}] not found on class [{}] nor handled by an extension method")
.arguments(findTemplatePath(analysis, incorrectExpression.origin.getTemplateGeneratedId()),
incorrectExpression.origin.getLine(), incorrectExpression.expression,
incorrectExpression.property, incorrectExpression.clazz)
.build());
} else {
errors.add(TemplateException.builder()
.code(Code.INCORRECT_EXPRESSION)
.origin(incorrectExpression.origin)
.message("Incorrect expression found: \\{{}}\n\t- @Named bean not found for [{}]\n\t- at {}:{}")
.arguments(incorrectExpression.expression, incorrectExpression.property,
findTemplatePath(analysis, incorrectExpression.origin.getTemplateGeneratedId()),
incorrectExpression.origin.getLine())
.message("{}:{} - \\{{}}: @Named bean not found for [{}]")
.arguments(findTemplatePath(analysis, incorrectExpression.origin.getTemplateGeneratedId()),
incorrectExpression.origin.getLine(), incorrectExpression.expression,
incorrectExpression.property)
.build());
}
}

if (!errors.isEmpty()) {
StringBuilder message = new StringBuilder("Found template problems (").append(errors.size()).append("):");
StringBuilder message = new StringBuilder("Found incorrect expressions (").append(errors.size())
.append("):");
int idx = 1;
for (TemplateException error : errors) {
message.append("\n").append("[").append(idx++).append("] ").append(error.getMessage());
message.append("\n\t").append("[").append(idx++).append("] ").append(error.getMessage());
}
message.append("\n");
TemplateException exception = new TemplateException(message.toString());
for (TemplateException error : errors) {
exception.addSuppressed(error);
Expand Down Expand Up @@ -808,7 +810,7 @@ static Match validateNestedExpressions(QuteConfig config, TemplateAnalysis templ
} else {
// No namespace extension method found - incorrect expression
incorrectExpressions.produce(new IncorrectExpressionBuildItem(expression.toOriginalString(),
String.format("no matching namespace [%s] extension method found", namespace), expression.getOrigin()));
String.format("No matching namespace [%s] extension method found", namespace), expression.getOrigin()));
match.clearValues();
return putResult(match, results, expression);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class TemplateDataValidationTest {
e = e.getCause();
}
assertNotNull(te);
assertTrue(te.getMessage().contains("Found template problems (1)"), te.getMessage());
assertTrue(te.getMessage().contains("Found incorrect expressions (1)"), te.getMessage());
assertTrue(te.getMessage().contains("foo_My:BAZ"), te.getMessage());
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class TemplateEnumValidationFailureTest {
e = e.getCause();
}
assertNotNull(te);
assertTrue(te.getMessage().contains("Found template problems (1)"), te.getMessage());
assertTrue(te.getMessage().contains("Found incorrect expressions (1)"), te.getMessage());
assertTrue(te.getMessage().contains("TransactionType:BAR.scores"), te.getMessage());
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ public class NamespaceTemplateExtensionValidationFailureTest {
e = e.getCause();
}
assertNotNull(te);
assertTrue(te.getMessage().contains("Found template problems (2)"), te.getMessage());
assertTrue(te.getMessage().contains("no matching namespace [bro] extension method found"), te.getMessage());
assertTrue(te.getMessage().contains("property/method [bubu] not found on class [java.lang.String]"),
assertTrue(te.getMessage().contains("Found incorrect expressions (2)"), te.getMessage());
assertTrue(te.getMessage().contains("No matching namespace [bro] extension method found"), te.getMessage());
assertTrue(te.getMessage().contains("Property/method [bubu] not found on class [java.lang.String]"),
te.getMessage());
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,10 @@ public class TemplateGlobalValidationFailureTest {
}
assertNotNull(te);
assertTrue(
te.getMessage().contains("Incorrect expression found: {user.name}"),
te.getMessage());
te.getMessage().contains("Found incorrect expressions (1)"), te.getMessage());
assertTrue(
te.getMessage().contains(
"property/method [name] not found on class [java.lang.String] nor handled by an extension method"),
"Property/method [name] not found on class [java.lang.String] nor handled by an extension method"),
te.getMessage());
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public class MessageBundleExpressionValidationTest {
if (te == null) {
fail("No template exception thrown: " + t);
}
assertTrue(te.getMessage().contains("Found template problems (5)"), te.getMessage());
assertTrue(te.getMessage().contains("Found incorrect expressions (5)"), te.getMessage());
assertTrue(te.getMessage().contains("item.foo"), te.getMessage());
assertTrue(te.getMessage().contains("bar"), te.getMessage());
assertTrue(te.getMessage().contains("foo"), te.getMessage());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class MessageBundleTemplateExpressionValidationTest {
if (te == null) {
fail("No template exception thrown: " + t);
}
assertTrue(te.getMessage().contains("Found template problems (4)"), te.getMessage());
assertTrue(te.getMessage().contains("Found incorrect expressions (4)"), te.getMessage());
assertTrue(te.getMessage().contains("msg:hello('foo')"), te.getMessage());
assertTrue(te.getMessage().contains("msg:hello_and_bye"), te.getMessage());
assertTrue(te.getMessage().contains("msg:hello(1,2)"), te.getMessage());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public class NamedBeanValidationFailureTest {
e = e.getCause();
}
assertNotNull(te);
assertTrue(te.getMessage().contains("Found template problems (2)"), te.getMessage());
assertTrue(te.getMessage().contains("Found incorrect expressions (2)"), te.getMessage());
assertTrue(te.getMessage().contains("it.ping"), te.getMessage());
assertTrue(te.getMessage().contains("cdi:foo.bar"), te.getMessage());
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public class CheckedTemplateRequireTypeSafeTest {
e = e.getCause();
}
assertNotNull(te);
assertTrue(te.getMessage().contains("Found template problems (3)"), te.getMessage());
assertTrue(te.getMessage().contains("Found incorrect expressions (3)"), te.getMessage());
assertTrue(te.getMessage().contains("any"), te.getMessage());
assertTrue(te.getMessage().contains("identifier"), te.getMessage());
assertTrue(te.getMessage().contains("index"), te.getMessage());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class InterfaceValidationFailureTest {
e = e.getCause();
}
assertNotNull(te);
assertTrue(te.getMessage().contains("Found template problems (1)"), te.getMessage());
assertTrue(te.getMessage().contains("Found incorrect expressions (1)"), te.getMessage());
assertTrue(te.getMessage().contains("{metrics.responses.values}"), te.getMessage());
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class TypeSafeLoopFailureTest {
e = e.getCause();
}
assertNotNull(te);
assertTrue(te.getMessage().contains("Found template problems (1)"), te.getMessage());
assertTrue(te.getMessage().contains("Found incorrect expressions (1)"), te.getMessage());
assertTrue(te.getMessage().contains("foo.ages"), te.getMessage());
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public class ValidationFailuresTest {
e = e.getCause();
}
assertNotNull(te);
assertTrue(te.getMessage().contains("Found template problems (10)"), te.getMessage());
assertTrue(te.getMessage().contains("Found incorrect expressions (10)"), te.getMessage());
assertTrue(te.getMessage().contains("movie.foo"), te.getMessage());
assertTrue(te.getMessage().contains("movie.getName('foo')"), te.getMessage());
assertTrue(te.getMessage().contains("movie.findService(age)"), te.getMessage());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class WhenValidationFailureTest {
e = e.getCause();
}
assertNotNull(te);
assertTrue(te.getMessage().contains("Found template problems (1)"), te.getMessage());
assertTrue(te.getMessage().contains("Found incorrect expressions (1)"), te.getMessage());
assertTrue(te.getMessage().contains("{WRONG}"), te.getMessage());
});

Expand Down

0 comments on commit 068bd67

Please sign in to comment.