Add a pretty print function
buildreactive opened this issue · 4 comments
It would be awesome to have a format
or pretty
function that would spit out violations in a nicely formatted, probably multi-line, indented style, making them easier to read.
I think #80 is a step in the right direction. We are a bit lost on how to easily figure out what is going wrong in our validation tests. For instance:
"Given a valid accomodation validator should validate correctly" in {
validate(validAccomodation).isSuccess must beTrue
}
Well, if this fails, all we end up seeing is a simple "should be true" and the test condition fails. What we really want is an easy (and simple, non-repetitive!) way to see exactly what went wrong.
Some of our validations are really nasty and deeply nested. So problem number one, how do we get the validation to output in the first place (in a specs2 test like above)? Problem number two, when we do get it, we don't want to have to read this:
GroupViolation(Booking(939957,G,BookingDetails(Some(coieYUtc),Some(HhrW),Some(izC),Some(2016-12-01),Some(i1ojjeMeh),Some(AccommodationInfo(Some(kfqezy),Some(913))),VoyageInfo(cxufExUdXgykkfqcgilfvoglaqdcejkwevjsfgsodnwRuckUrallhqyklN619610932572565588585749338129584536089025580481055889105473713503779748822008426983M1iA5b,cxufExUdXgykkfqcgilfvoglaqdcejkwevjsfgsodnwRuckUrallhqyklN,2016-12-01,2016-12-01,propertyCode,2017-01-14,voyageType,Port(ULF,ULF),Port(MJZ,MJZ)),TravelInfo(List()),GratuityDetails(Some(false),Some(false)),Some(Price(Some(215.61),Some(1320.01),Some(5354.27),Some(281.73),Some(85.74))),Waitlist(Some(B),Some(8),Some(qdZwq),Some(4),A),Some(Cancellation(Some(2016-12-01),Some(I))),Some(Group(Some(trhx),Some(A))))),is invalid,Set(GroupViolation(BookingDetails(Some(coieYUtc),Some(HhrW),Some(izC),Some(2016-12-01),Some(i1ojjeMeh),Some(AccommodationInfo(Some(kfqezy),Some(913))),VoyageInfo(cxufExUdXgykkfqcgilfvoglaqdcejkwevjsfgsodnwRuckUrallhqyklN619610932572565588585749338129584536089025580481055889105473713503779748822008426983M1iA5b,cxufExUdXgykkfqcgilfvoglaqdcejkwevjsfgsodnwRuckUrallhqyklN,2016-12-01,2016-12-01,propertyCode,2017-01-14,voyageType,Port(ULF,ULF),Port(MJZ,MJZ)),TravelInfo(List()),GratuityDetails(Some(false),Some(false)),Some(Price(Some(215.61),Some(1320.01),Some(5354.27),Some(281.73),Some(85.74))),Waitlist(Some(B),Some(8),Some(qdZwq),Some(4),A),Some(Cancellation(Some(2016-12-01),Some(I))),Some(Group(Some(trhx),Some(A)))),is invalid,Set(GroupViolation(Group(Some(trhx),Some(A)),is invalid,Set(RuleViolation(4,got 4, expected between 1 and 3,Generic(p.group.map(_.length).each)), GroupViolation(Group(Some(trhx),Some(A)),doesn't meet any of the requirements,Set(RuleViolation(true,must be false,AccessChain(WrappedArray(group, isDefined))), RuleViolation(true,must be false,Explicit(group identity must be between 1 and 3 characters))),Empty)),AccessChain(WrappedArray(group))), RuleViolation(false,must be true,Generic(p.earmark.map(_.length == 6).each))),AccessChain(WrappedArray(bookingDetails)))),AccessChain(WrappedArray(booking)))GroupViolation(GuestDetail(None,PC9399571,Some(Promo),None,Ms,abavuscmmue5u,v,abaviazg1ogt3h4rv,Some(Male),Some(100),Some(Hon),Some(Address(6 W 39th St,Some(NA),Some(NA),Westerly,NA,NA,Hon)),Some(WrappedArray(PhoneNumber(mobile,12345678094r8f))),Some(2010-02-02),Some(WkdSPExg6A9gkhDRWUfj@JOyyXZ.accenture.com)),is invalid,Set(RuleViolation(13,got 13, expected between 1 and 12,Explicit(forename is between 1 and 12 characters)), RuleViolation(17,got 17, expected between 1 and 16,Explicit(surname is between 1 and 16 characters))),Indexed(0,AccessChain(WrappedArray(guestDetails))))
Additional thought: It's not really just for debugging, it's for problem diagnosis. So if we have data coming in, and it fails to validate... we emit a log that someone will investigate. It would be very nice if that log was easy to read.