Skip to content

Commit

Permalink
provide more descriptive error message
Browse files Browse the repository at this point in the history
  • Loading branch information
Piotr Rudnicki committed Dec 17, 2024
1 parent 7feab59 commit 440726d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ object SpelExpressionParseError {

case object MapWithExpressionKeysError extends UnsupportedOperationError {
override def message: String =
"Currently inline maps with not literal keys (e.g. expressions as keys) are not supported"
"Currently inline maps with not literal stringy keys (e.g. expressions as keys, numerals) are not supported"
}

case object ArrayConstructorError extends UnsupportedOperationError {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package pl.touk.nussknacker.engine.spel

import cats.data.Validated.Valid
import cats.data.ValidatedNel
import cats.data.Validated.{Invalid, Valid}
import cats.data.{NonEmptyList, ValidatedNel}
import org.scalatest.funsuite.AnyFunSuite
import org.scalatest.matchers.should.Matchers
import org.springframework.expression.common.TemplateParserContext
Expand All @@ -15,6 +15,7 @@ import pl.touk.nussknacker.engine.dict.{KeysDictTyper, SimpleDictRegistry}
import pl.touk.nussknacker.engine.expression.PositionRange
import pl.touk.nussknacker.engine.spel.SpelExpressionParseError.IllegalOperationError.DynamicPropertyAccessError
import pl.touk.nussknacker.engine.spel.SpelExpressionParseError.MissingObjectError.NoPropertyError
import pl.touk.nussknacker.engine.spel.SpelExpressionParseError.UnsupportedOperationError.MapWithExpressionKeysError
import pl.touk.nussknacker.engine.spel.Typer.TypingResultWithContext
import pl.touk.nussknacker.engine.spel.TyperSpecTestData.TestRecord._
import pl.touk.nussknacker.engine.util.Implicits.RichScalaMap
Expand All @@ -29,6 +30,12 @@ class TyperSpec extends AnyFunSuite with Matchers with ValidatedValuesDetailedMe
private val parser: standard.SpelExpressionParser =
new org.springframework.expression.spel.standard.SpelExpressionParser()

test("not allow maps with keys other than strings") {
typeExpression("{1L: 'foo'}") shouldBe Invalid(
NonEmptyList(MapWithExpressionKeysError, List())
)
}

test("simple expression") {
typeExpression("#x + 2", "x" -> 2) shouldBe Valid(
CollectedTypingResult(
Expand Down

0 comments on commit 440726d

Please sign in to comment.