Skip Menu |

Preferred bug tracker

Please visit the preferred bug tracker to report your issue.

This queue is for tickets about the Specio CPAN distribution.

Report information
The Basics
Id: 84351
Status: resolved
Priority: 0/
Queue: Specio

People
Owner: Nobody in particular
Requestors: DROLSKY [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Subject: The message thrown for a failure should match the constraint that failed
When a type inherits from a series of parents, the failure message it throws should come from the failing parent if that parent's constraint fails. This will require some changes to how inlining works. Maybe the inlined constraint needs to return _false_ on success and return a failure message on failure?
FYI, I *initially* had it working this way in Type::Tiny, but it made inlining stupidly complex so I switched to just throwing from the child type constraint. But with the build up to 0.006 I'm working on an $exception->explain method which re-examines why the value failed the type constraint, step-by-step. For example, checking [1,2,[3]] against ArrayRef[Int] gives an explanation like this: [ '[1,2,[3]] did not pass type constraint "ArrayRef[Int]"', '"Int" is a subtype of "Num"', '"Num" is a subtype of "Str"', '"Str" is a subtype of "Value"', '[3] did not pass type constraint "Value" (in $_->[2])', '"Value" is defined as: (defined($_) and not ref($_))', ], This means that the extensive examination is avoided on "hot" code paths (i.e. where the value passes the type constraint), but can be explicitly called in, say, a catch block. Anyway, that's just an idea of a different way this can be done.
Ticket migrated to GitHub as