wix-incubator / accord

Accord: A sane validation library for Scala
http://wix.github.io/accord/
Other
529 stars 55 forks source link

"has size" RuleViolation has wrong value #104

Closed stijn-starmind closed 7 years ago

stijn-starmind commented 7 years ago

With version 0.6.1:

import com.wix.accord.dsl._

val listValidator = validator[ List[Int] ] { p =>
  p has size < 2
  p is empty
}

listValidator(List(1,2,3))

results in

Failure(Set(
  RuleViolation(3,has size 3, expected less than 2,SelfReference),
  RuleViolation(List(1, 2, 3),must be empty,SelfReference))
)

I would expect List(1,2,3) as the value (first RuleViolation parameter) for both violations. Now the first violations reads "3 has size 3" which is very confusing.

holograph commented 7 years ago

That is actually a very good point; right now the value is the actual thing that's being validated (in this case the size), but I agree that it's misleading, and the actual culprit is reflected in the constraint text. I'll add it as a bug for the next milestone.

holograph commented 7 years ago

Fix should be presently available in 0.7-SNAPSHOT builds.