refined
refined copied to clipboard
Better error message when a value doesn't satisfy the predicate
This tweet https://twitter.com/ppurang/status/674252856720031745 indicates that we could improve the error message when a value doesn't satisfy the predicate.
I tend to change the error message from Predicate failed: (4 > 6)
to something like Predicate failed: (x > 6) where x = 4
. That should help to keep apart the predicate and the value that didn't satisfy it.
One more example of a strange error message:
@ string.NonEmptyString.from("foo")
res2: Either[String, string.NonEmptyString] = Right(foo)
@ string.NonEmptyString.from("")
res3: Either[String, string.NonEmptyString] = Left("Predicate isEmpty() did not fail.")
Yes, I was misled today by this strange error message - it expresses the opposite of the actual problem.