Skip to content

Commit

Permalink
Addressed review comments
Browse files Browse the repository at this point in the history
Signed-off-by: Krishna Kondaka <krishkdk@amazon.com>
  • Loading branch information
kkondaka committed Dec 12, 2024
1 parent 63de35a commit 90a14c1
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ default Boolean evaluateConditional(final String statement, final Event context)
return (Boolean) result;
}
throw new ClassCastException("Unexpected expression return value of " + result);
} catch (ExpressionParsingException e) {
throw e;
} catch (ExpressionEvaluationException e) {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* @since 2.11
* Wrapper exception for any exception thrown while evaluating a statement
*/
public class ExpressionParsingException extends RuntimeException {
public class ExpressionParsingException extends ExpressionEvaluationException {
public ExpressionParsingException(final String message, final Throwable cause) {
super(message, cause);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,16 @@ public GenericExpressionEvaluator(final Parser<ParseTree> parser, final Evaluato
*/
@Override
public Object evaluate(final String statement, final Event context) {
boolean parsedSuccessfully = false;
ParseTree parseTree = null;
try {
final ParseTree parseTree = parser.parse(statement);
parsedSuccessfully = true;
return evaluator.evaluate(parseTree, context);
parseTree = parser.parse(statement);
} catch (final Exception exception) {
throw new ExpressionParsingException("Unable to parse statement \"" + statement + "\"", exception);
}
catch (final Exception exception) {
if (parsedSuccessfully) {
throw new ExpressionEvaluationException("Unable to evaluate statement \"" + statement + "\"", exception);
} else {
throw new ExpressionParsingException("Unable to parse statement \"" + statement + "\"", exception);
}
try {
return evaluator.evaluate(parseTree, context);
} catch (final Exception exception) {
throw new ExpressionEvaluationException("Unable to evaluate statement \"" + statement + "\"", exception);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,6 @@ private static Stream<Arguments> exceptionExpressionSyntaxArguments() {
Arguments.of("/status - ", event("{\"status\": 200, \"message\":\"msg\"}")),
Arguments.of("/status / ", event("{\"status\": 200, \"message\":\"msg\"}")),
Arguments.of(" * /status ", event("{\"status\": 200, \"message\":\"msg\"}"))
//Arguments.of("-/message ", event("{\"status\": 200, \"message\":\"msg\"}"))
);
}

Expand All @@ -252,9 +251,6 @@ private static Stream<Arguments> exceptionExpressionArguments() {
Arguments.of("/message * /status", event("{\"status\": 200, \"message\":\"msg\"}")),
Arguments.of("/message + /status", event("{\"status\": 200, \"message\":\"msg\"}")),
Arguments.of("/status - /message", event("{\"status\": 200, \"message\":\"msg\"}")),
//Arguments.of("/status - ", event("{\"status\": 200, \"message\":\"msg\"}")),
//Arguments.of("/status / ", event("{\"status\": 200, \"message\":\"msg\"}")),
//Arguments.of(" * /status ", event("{\"status\": 200, \"message\":\"msg\"}")),
Arguments.of("/message - /status", event("{\"status\": 200, \"message\":\"msg\"}")),
Arguments.of("-/message ", event("{\"status\": 200, \"message\":\"msg\"}"))
);
Expand Down

0 comments on commit 90a14c1

Please sign in to comment.