From 66e72f83ea1cf1af8cf217934d324a656d9a9226 Mon Sep 17 00:00:00 2001 From: Philipp Ossler Date: Tue, 5 Sep 2023 06:45:36 +0200 Subject: [PATCH] refactor: Improve message for available keys/properties Wrap available keys and properties inside single quotes to improve the readability of the message. --- .../feel/impl/interpreter/FeelInterpreter.scala | 4 ++-- .../camunda/feel/impl/SuppressedFailuresTest.scala | 4 ++-- .../interpreter/InterpreterBeanExpressionTest.scala | 2 +- .../InterpreterContextExpressionTest.scala | 12 ++++++------ 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/main/scala/org/camunda/feel/impl/interpreter/FeelInterpreter.scala b/src/main/scala/org/camunda/feel/impl/interpreter/FeelInterpreter.scala index 2cdfd89f3..e5339621b 100644 --- a/src/main/scala/org/camunda/feel/impl/interpreter/FeelInterpreter.scala +++ b/src/main/scala/org/camunda/feel/impl/interpreter/FeelInterpreter.scala @@ -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, @@ -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" diff --git a/src/test/scala/org/camunda/feel/impl/SuppressedFailuresTest.scala b/src/test/scala/org/camunda/feel/impl/SuppressedFailuresTest.scala index c626a6739..38352d430 100644 --- a/src/test/scala/org/camunda/feel/impl/SuppressedFailuresTest.scala +++ b/src/test/scala/org/camunda/feel/impl/SuppressedFailuresTest.scala @@ -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'" ) } diff --git a/src/test/scala/org/camunda/feel/impl/interpreter/InterpreterBeanExpressionTest.scala b/src/test/scala/org/camunda/feel/impl/interpreter/InterpreterBeanExpressionTest.scala index ab18cd2cc..6e7e65d11 100644 --- a/src/test/scala/org/camunda/feel/impl/interpreter/InterpreterBeanExpressionTest.scala +++ b/src/test/scala/org/camunda/feel/impl/interpreter/InterpreterBeanExpressionTest.scala @@ -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'" )) } diff --git a/src/test/scala/org/camunda/feel/impl/interpreter/InterpreterContextExpressionTest.scala b/src/test/scala/org/camunda/feel/impl/interpreter/InterpreterContextExpressionTest.scala index b25be2eef..a3b9e6fbd 100644 --- a/src/test/scala/org/camunda/feel/impl/interpreter/InterpreterContextExpressionTest.scala +++ b/src/test/scala/org/camunda/feel/impl/interpreter/InterpreterContextExpressionTest.scala @@ -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'" ) ) } @@ -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") @@ -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'") ) }