-
Notifications
You must be signed in to change notification settings - Fork 19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
suppress "...at line..." in _croak if end newline #32
base: main
Are you sure you want to change the base?
Conversation
I don't understand why this is a good thing. What's the use case? |
This shows a useful example: https://travis-ci.org/graphql-perl/graphql-perl/builds/278494197#L572-L590 The error messages show information that I would like to be able to choose to not show, as well as more generally that tests can be fragile if that information is in errors. More generally, the convention in Perl exceptions is to only add the information if there is no Separately, I'm not sure why it's differing on "item 1" and "item 2", but that's a different problem which I will address. |
The error message is for users of the function (who need to know which call is the problem). Why should the type of a single parameter get to decide to suppress the error location for the whole function? Besides, the
This is not a generic "throw exception" mechanism. The behavior is consistent with perl's own runtime errors, which don't let you suppress the location either. If you want to make tests more robust, there are a couple of ways. You can set the filename and line number in #line 1 "foobar"
do_stuff(); Then the Or you can make your message check more flexible (regex match) and allow Or cut off the |
Thanks for the observations.
Therefore it seems like Perl thinks that
Note the second line refers to
|
|
{
package WithFP;
use Function::Parameters;
use Return::Type;
use Types::Standard -all;
method s(Str $s) { }
method s_rt(Str $s) :ReturnType(Any) { }
}
eval { WithFP->s(undef); }; print "no RT: $@" if $@;
eval { WithFP->s_rt(undef); }; print "with RT: $@" if $@;
__END__
no RT: In method s: parameter 1 ($s): Undef did not pass type constraint "Str" at tf line 10.
with RT: In method s_rt: parameter 1 ($s): Undef did not pass type constraint "Str" at (eval 72) line 15.
|
@mauke I thought you might have some insight into this: while investigating making |
It can be very helpful to include line numbers etc for failure messages. Not having the choice when parameters are wrong is less helpful, though. This change makes
F::P::_croak
behave likedie
: the...at line...
is suppressed if last list element ends with"\n"
.