Subject: | Ambiguous exceptions where used with Params::ValidationCompiler |
Hello. I like Params::ValidationCompiler very much for its Perlish API and its performance. Up until now, I had been using it with Specio. However, after being bowled over by the performance of Type::Tiny::XS, I experimented with the conversion of one of my projects, only to find that debugging becomes extremely difficult.
Consider the attached program, which prints the following:-
*** Params::ValidationCompiler/Specio ***
Validation failed for type named ArrayRef[Int] declared in package main (type-tiny-issue.pl) at line 11 in sub named main::a with value [ "str" ]
*** Params::ValidationCompiler/Type::Tiny ***
Reference ["str"] did not pass type constraint "ArrayRef[Int]" at (eval 153) line 26
*** Function::Parameters/Type::Tiny ***
In fun c: parameter 2 ($aref): Reference ["str"] did not pass type constraint "ArrayRef[Int]" at type-tiny-issue.pl line 32.
The exception produced by the combination of Params::ValidationCompiler and Type::Tiny makes it impossible to know exactly where in the program it was thrown. What's interesting is that Specio manages it, somehow. Would there be any feasible way for Type::Tiny to behave similarly?
Subject: | type-tiny-demo.txt |
#!/usr/bin/perl
use 5.10.1;
use Function::Parameters 2;
use Params::ValidationCompiler qw(validation_for);
use Specio::Library::Builtins;
use Try::Tiny;
use Types::Standard qw(Str Int ArrayRef HashRef Map Maybe);
sub a {
state $validator = validation_for(params => [
{ type => t('Str') },
{ type => t('ArrayRef' => of => t('Int')) },
{ type => t('HashRef') }
]);
my ($str, $aref, $map) = $validator->(@_);
}
sub b {
state $validator = validation_for(params => [
{ type => Str },
{ type => ArrayRef[Int] },
{ type => HashRef }
]);
my ($str, $aref, $map) = $validator->(@_);
}
fun c (Str $str, ArrayRef[Int] $aref, HashRef $map) {}
try { a(1, ['str'], {}); } catch { say for '*** Params::ValidationCompiler/Specio ***', (split /\n/)[0]; };
try { b(1, ['str'], {}); } catch { say for '*** Params::ValidationCompiler/Type::Tiny ***', (split /\n/)[0]; };
try { c(1, ['str'], {}); } catch { say for '*** Function::Parameters/Type::Tiny ***', (split /\n/)[0]; };