Skip Menu |

This queue is for tickets about the Type-Tiny CPAN distribution.

Report information
The Basics
Id: 85054
Status: resolved
Priority: 0/
Queue: Type-Tiny

People
Owner: perl [...] toby.ink
Requestors: djerius [...] cpan.org
Cc:
AdminCc:

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



Subject: Confusing error message if required slurpy Dict not present in parameter list
If a non-optional slurpy Dict is requested but not provided, the error message is confusing. To wit: use Types::Standard -all; use Type::Params qw[ validate ]; validate( [ 'a' ], Str, slurpy Dict [ var => Int ]); results in: Value "HASH(0x10a8f310)" in $_[1] does not meet type constraint "Dict[var=>Int]" at /opt/perl5/perls/perl-5.16.2/lib/5.16.3/Carp.pm line 97. Carp::shortmess('Value "HASH(0x10a8f310)" in $_[1] does not meet type constrai...') called at /opt/perl5/perls/perl-5.16.2/lib/5.16.3/Carp.pm line 100 Carp::croak('Value "HASH(0x10a8f310)" in $_[1] does not meet type constrai...') called at /home/dj/.perlbrew/libs/perl-5.16.2@dev/lib/perl5/Type/Params.pm line 92 Type::Params::__ANON__('Value "HASH(0x10a8f310)" in $_[1] does not meet type constrai...') called at parameter validation for 'Type::Params::validate' line 7 Eval::TypeTiny::Sandbox69::__ANON__('a') called at try.pl line 4 instead of a "Wrong number of parameters" error. A missing non-slurpy Dict results in a message along the lines of: Wrong number of parameters (1); expected 2 at /opt/perl5/perls/perl-5.16.2/lib/5.16.3/Carp.pm line 97. which is more along the lines of what I expected. Thanks, Diab
In the version I've just uploaded (0.003_16) the error message will be: {} in $_[1] does not meet type constraint "Dict[var=>Int]" ... which is somewhat better. The error messages for slurpy parameters could do with some improvements though, so I'll keep this ticket open.
Current error message in repo: use Type::Params qw(validate); use Types::Standard qw(-all); sub foo { validate(\@_, Str, slurpy Dict[var => Int]) } foo("a"); # this is line 8 __END__ {} did not pass type constraint "Dict[var=>Int]" (in $SLURPY) at /home/tai/tmp/param-validate-errors.pl line 8. The error message is not really a string; it's an exception. If you catch it (with eval, or Try::Tiny for example) then you can call methods like ->type, ->value and ->varname on it. You can also call a method ->explain, which currently outputs: $VAR1 = [ '{} (in $SLURPY) fails type constraint Dict[var=>Int]', 'Dict[var=>Int] is defined as: (do { ref($_) eq \'HASH\' and not(grep !/^(var)$/, keys %{$_}) and (do { defined $_->{"var"} and $_->{"var"} =~ /\\A-?[0-9]+\\z/ }) })' ]; This will improve in the future. Dict doesn't have very good explanations yet.
Hopefully the exceptions thrown by the current development versions are more to your liking. I'm marking this as patched for now.
Subject: Re: [rt.cpan.org #85054] Confusing error message if required slurpy Dict not present in parameter list
Date: Fri, 17 May 2013 10:15:20 -0400
To: bug-Type-Tiny [...] rt.cpan.org
From: Diab Jerius <dj [...] head.cfa.harvard.edu>
On Fri, 2013-05-17 at 05:50 -0400, Toby Inkster via RT wrote: Show quoted text
> <URL: https://rt.cpan.org/Ticket/Display.html?id=85054 > > > Hopefully the exceptions thrown by the current development versions are more to your liking. I'm marking this as patched for now.
Sorry, I've been pulled away from the project I was using Type::Tiny on and haven't been able to evaluate the changes. I hope to be back to it shortly, but please don't wait on me. Thanks for your effort on this!
0.006 is now out, with exceptions. Feel free to re-open this issue if you still think the error messages could be improved.