Skip to content

Commit

Permalink
refactor: Improve message for available keys/properties
Browse files Browse the repository at this point in the history
Wrap available keys and properties inside single quotes to improve the readability of the message.
  • Loading branch information
saig0 committed Sep 5, 2023
1 parent 56b55ad commit 66e72f8
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -873,7 +873,7 @@ class FeelInterpreter {
case _: ValError =>
val detailedMessage = ctx.context.variableProvider.keys match {
case Nil => "The context is empty"
case keys => s"Available keys: ${keys.mkString(", ")}"
case keys => s"Available keys: ${keys.map("'" + _ + "'").mkString(", ")}"
}
error(
failureType = EvaluationFailureType.NO_CONTEXT_ENTRY_FOUND,
Expand All @@ -891,7 +891,7 @@ class FeelInterpreter {
ValNull
case value =>
value.property(key).getOrElse {
val propertyNames: String = value.propertyNames().mkString(",")
val propertyNames: String = value.propertyNames().map("'" + _ + "'").mkString(", ")
error(
failureType = EvaluationFailureType.NO_PROPERTY_FOUND,
failureMessage = s"No property found with name '$key' of value '$value'. Available properties: $propertyNames"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@ class SuppressedFailuresTest extends AnyFlatSpec
it should "report a suppressed failure for a non-existing context entry" in {
evaluateExpression("{x: 1}.y") should reportFailure(
failureType = EvaluationFailureType.NO_CONTEXT_ENTRY_FOUND,
failureMessage = "No context entry found with key 'y'. Available keys: x"
failureMessage = "No context entry found with key 'y'. Available keys: 'x'"
)
}

it should "report a suppressed failure for a non-existing property" in {
evaluateExpression(""" @"P1Y".days """) should reportFailure(
failureType = EvaluationFailureType.NO_PROPERTY_FOUND,
failureMessage = "No property found with name 'days' of value 'P1Y'. Available properties: years,months"
failureMessage = "No property found with name 'days' of value 'P1Y'. Available properties: 'years', 'months'"
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ class InterpreterBeanExpressionTest
) should (returnNull() and
reportFailure(
failureType = EvaluationFailureType.NO_CONTEXT_ENTRY_FOUND,
failureMessage = "No context entry found with key 'result'. Available keys: x"
failureMessage = "No context entry found with key 'result'. Available keys: 'x'"
))
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ class InterpreterContextExpressionTest
returnNull() and
reportFailure(
failureType = EvaluationFailureType.NO_CONTEXT_ENTRY_FOUND,
failureMessage = "No context entry found with key 'z'. Available keys: x, y"
failureMessage = "No context entry found with key 'z'. Available keys: 'x', 'y'"
)
)
}
Expand All @@ -156,7 +156,7 @@ class InterpreterContextExpressionTest
returnNull() and
reportFailure(
failureType = EvaluationFailureType.NO_CONTEXT_ENTRY_FOUND,
failureMessage = "No context entry found with key 'b'. Available keys: a") and
failureMessage = "No context entry found with key 'b'. Available keys: 'a'") and
reportFailure(
failureType = EvaluationFailureType.NO_CONTEXT_ENTRY_FOUND,
failureMessage = "No context entry found with key 'c'. The context is null")
Expand Down Expand Up @@ -217,24 +217,24 @@ class InterpreterContextExpressionTest
returnResult(List(1, null)) and
reportFailure(
failureType = EvaluationFailureType.NO_CONTEXT_ENTRY_FOUND,
failureMessage = "No context entry found with key 'a'. Available keys: b")
failureMessage = "No context entry found with key 'a'. Available keys: 'b'")
)

evaluateExpression("[ {a:1}, {b:2} ].b") should (
returnResult(List(null, 2)) and
reportFailure(
failureType = EvaluationFailureType.NO_CONTEXT_ENTRY_FOUND,
failureMessage = "No context entry found with key 'b'. Available keys: a")
failureMessage = "No context entry found with key 'b'. Available keys: 'a'")
)

evaluateExpression("[ {a:1}, {b:2} ].c") should (
returnResult(List(null, null)) and
reportFailure(
failureType = EvaluationFailureType.NO_CONTEXT_ENTRY_FOUND,
failureMessage = "No context entry found with key 'c'. Available keys: a") and
failureMessage = "No context entry found with key 'c'. Available keys: 'a'") and
reportFailure(
failureType = EvaluationFailureType.NO_CONTEXT_ENTRY_FOUND,
failureMessage = "No context entry found with key 'c'. Available keys: b")
failureMessage = "No context entry found with key 'c'. Available keys: 'b'")
)
}

Expand Down

0 comments on commit 66e72f8

Please sign in to comment.