Skip Menu |

This queue is for tickets about the Params-Validate CPAN distribution.

Report information
The Basics
Id: 4903
Status: rejected
Priority: 0/
Queue: Params-Validate

People
Owner: DROLSKY [...] cpan.org
Requestors: sabol [...] alderaan.gsfc.nasa.gov
Cc:
AdminCc:

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



Subject: ValidateXS errors when on_fail doesn't die; ValidatePP works great
I've tested this using Perl 5.6.1 and 5.8.0. For user interface purposes, I wanted Params::Validate to check all of the arguments and report all of the errors so I could properly report back to the user which fields were filled out erroneously. The documentation implied that, if I supplied an 'on_fail' code reference that didn't die, Params::Validate would validate all of the arguments. Wonderfull. So I created a exceptions container class and a validate_all wrapper which calls validate_with with an 'on_fail' code reference that adds each error to my exceptions container class. After the call to validate_with, the exception is thrown if the container is not empty. Everything works great with ValidatePP, but it just doesn't work at all with ValidateXS. With ValidateXS, you get the following error: Can't use an undefined value as a HASH reference at (eval 1) line 78. And I believe that is line 78 in ValidateXS.pm. I thought I'd try it with ValidatePP by setting the appropriate environment variable, and it worked! ValidateXS and ValidatePP should give identical results, I think. I could come up with some code which shows this, but it should be easy enough to test. Addin the following argument to any validate_with call should do it: 'on_fail' => sub { print "$_[0]\n"; }
Subject: 'on_fail' methods should be passed more info than just the error message
It would be *really* nice if 'on_fail' methods were passed the parameter name (or a reference to an array of parameter names for those cases where there are multiple names) and the parameter value (where appropriate) in addition to the error message. Carp::confess (the default on_fail) will ignore the extra parameters, I believe, so this change should be fully backwards compatible. As the code is currently written, my 'on_fail' method has to parse the error text message using regex in order to find the invalid parameter(s), and this is obviously very fragile if Params::Validate's error messages should change in some future version. I would be willing to put some effort into coming up with a patch for this if you think it's a good idea.
Date: Sat, 10 Jan 2004 18:13:34 -0600 (CST)
From: Dave Rolsky <autarch [...] urth.org>
To: Guest via RT <bug-Params-Validate [...] rt.cpan.org>
Subject: Re: [cpan #4902] ValidateXS errors when on_fail doesn't die; ValidatePP works great
RT-Send-Cc:
On Sat, 10 Jan 2004, Guest via RT wrote: Show quoted text
> For user interface purposes, I wanted Params::Validate to check all of > the arguments and report all of the errors so I could properly report > back to the user which fields were filled out erroneously. The > documentation implied that, if I supplied an 'on_fail' code reference > that didn't die, Params::Validate would validate all of the arguments.
The docs imply no such thing. They say: This callback is expected to C<die()> internally. If it does not, the validation will proceed onwards, with unpredictable results. Note the "unpredictable results" part. So in fact it's doing exactly what it's documented to do ;) However, I do like the idea of getting all the validation failures, rather than dying on the first one. I'm not sure that using on_fail is the right API for this, though. Also, I'd think that if you want to collect information on all validation failures, then getting a hash describing the failure (which parameter, how it failed, etc.) would be more useful than just getting an error message string. Anyway, I'll look into this for future versions. -dave /*======================= House Absolute Consulting www.houseabsolute.com =======================*/
Hello Dave, On Sat Jan 10 19:13:40 2004, autarch@urth.org wrote: Show quoted text
> However, I do like the idea of getting all the validation failures, rather > than dying on the first one. I'm not sure that using on_fail is the right > API for this, though. > > Also, I'd think that if you want to collect information on all validation > failures, then getting a hash describing the failure (which parameter, how > it failed, etc.) would be more useful than just getting an error message > string. > > Anyway, I'll look into this for future versions.
Just in case you were wondering if it would be worth investing the work because you don't know if anybody would care: I would extremely appreciate such functionality. Ideal would be as you describe getting back a hash with the parameters that failed together with indications of the failures. That would allow users to create their own error messages or maybe just warn about the failure or even silently discard failing parameters. I don't know how much work it is to let the validate methods go on after a failure. If it is a lot of work it would be already very helpful to introduce the possibility that the validate methods just return the first failing parameter and its classification instead of dying. With that, one could even (possibly expensive, but at least possible) emulate the full behaviour by replacing the failing parameter with a valid value and reexecuting the validation. Thanks for your work on Params::Validate, Lutz
RT-Send-CC: autarch [...] urth.org
On Fri May 28 19:06:30 2010, LGEHLEN wrote: Show quoted text
> Ideal would be as you describe getting back a hash with the > parameters that failed together with indications of the > failures. That would allow users to create their own error messages > or maybe just warn about the failure or even silently discard > failing parameters.
Please allow me to express my support for such an idea (i.e. return a hash ref with all violations, if any) and strong interest in it making it's way into Params-Validate. Thanks Dave for all your most valuable contributions to the perl community. Best regards, Andreas
I'm no longer going to make any non-bugfix changes to P::V so I'm closing old wishlist tickets. See https://metacpan.org/pod/Params::ValidationCompiler for a better parameter validation tool.