-
Notifications
You must be signed in to change notification settings - Fork 572
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
Error and warning IDs #14093
Comments
From @cpansproutAs has been oft repeated, we need error codes or IDs to identify diagnostic messages without having to use regular expressions on the message, whose wording might change between versions. The usual proposed solution is to use error objects. I am opposed to that, because it will break backward compatibility with code that does this: if (ref $@) { (And I’ve seen plenty of code that does that.) Last year (I think) I proposed implementing them similarly to vstrings. Have just ‘plain’ strings passed around, but with magic attached to them, so that error::code( That idea was shot down immediately as making strings ‘more complex’, and since we have objects for this purpose we might as well use them. (See above, how the latter will break things.) However, I think the magic implementation could just be an implementation detail. I have long wanted diagnostics.pm to have a ‘splain’ function that will be able to describe a message for me, instead of requiring me to use warn hooks or pipe error messages to the ‘splain’ program. The thing is, we already have such functionality available; we just need to expose it better. Put two ideas together and we come up with this: The functions we provide for identifying a message (error::code or error::id, whichever you prefer) could work like diagnostics.pm (i.e., matching the text), but the messages generated by perl could have magic attached to them storing the ID for efficiency. To the Perl programmer, the difference between "Bad hash at foo line 1.\n" from a string literal or input and the same string from $@ can be transparent. error::code is just more efficient on the latter. All error codes should ideally be alphanumeric, to keep them memorable. I would hate having to write ‘no warnings "97"’ to disable a specific warning. Since we already have warning categories, let’s do "category::shortid". I’m not sure whether we should categorize errors. Perhaps we should also provide a constructor to allow users to create error objects via error->new(message => xxxx, id => xxx, line => xxx, file, => xxx). error::code() would take objects and strings. -- Father Chrysostomos |
From perl5-porters@perl.orgI wrote:
And it stops there. Somehow the message sent to the list has been truncated. The full version can be seen in the RT ticket. |
The RT System itself - Status changed from 'new' to 'open' |
From @karenetheridgeOn Tue, Sep 16, 2014 at 11:05:14PM -0000, Father Chrysostomos wrote:
I posted my thoughts on the wrong thread. I've had a mental image of error Therefore, code like this will behave the same as before: eval { foo() } or warn "got error: $@"; but code like this can be smarter: use Try::Tiny; This would make a *lot* of code simpler (with the exception of having to |
From @demerphqOn 17 September 2014 01:00, Father Chrysostomos <perlbug-followup@perl.org>
I was thinking of a simpler approach. Why not just have an environment So where we now have something like: $ perl -wle'my $x; print 0+$x' We would instead have something like $ perl -wle'my $x; print 0+$x' The [PERL-W001] would be constant irregardless of localization. A simple Yves -- |
From @cpansproutOn Tue Sep 16 17:18:46 2014, demerphq wrote:
Action at a distance: Module::Runtime (exempli gratia) does $@ !~ /\ACan't locate.../, which will break if someone has set the environment variable. Let’s not add -- Father Chrysostomos |
From @demerphqOn 17 September 2014 03:11, Father Chrysostomos via RT <
Ok, so then make is a lexically scoped pragma. The point is, it doesnt -- |
From @cpansproutOn Tue Sep 16 18:19:42 2014, demerphq wrote:
What about code like LWP that catches errors and turns them into response objects? You can add your own protocols to LWP by providing your own LWP::Protocol classes. If your classes throw errors and some of them have the pragma turned on, then your response objects are no longer formatted consistently. (Oh no, there’s the C word again.) While that could be construed as LWP’s problem, I think this example demonstrates how errors naturally transcend lexical scopes. And I *do* like solutions involving regular expressions. That is exactly what I was suggesting when I mentioned giving error::id/code diagnostic.pm’s capabilities. What do you think diagnostic.pm uses? :-) -- Father Chrysostomos |
From @demerphqOn 17 September 2014 05:35, Father Chrysostomos via RT <
Unless LWP enabled the pragma it wouldn't matter would it?
That sounds like a "so dont do that" problem.
Im not sure I see the problem in the same way you do.
I dunno if I can say why cogently, but that doesnt sound like the right We want it so that when someone runs a perl script and they get an error or If the only way you get such a thing is by using special function it seems I guess this one of those things that if we really want to do it right we BTW, I am pretty sure at least one or two custom ports of Perl already do So either we do something like you describe, which IMO is only marginally Yves |
From @cpansproutOn Tue Sep 16 20:54:41 2014, demerphq wrote:
Hmmm, do you mean adding the error code based on the eval{} site, rather than the die site? I hadn’t thought of that till now.
But LWP::Protocol classes may be written by different authors. You’re saying I should stick to old-style error messages just because my module is used by LWP when available? (This question only applies if we base the pragma on where the error is thrown.)
Apparently not. :-) I have several times had to right code that recognizes Perl error messages and re-throws some of them, and this among 30 modules or so calling each other. If some code expects error codes and some does not, that complicates things.
I only meant that as a fallback, if the magic attached to the error is gone.
I had not considered that use case. The gradual change in wording that happens with each release was the only thing I had in mind.
In that case what you suggest makes sense. But I think we need to put the error code at the end of the message, rather than at the beginning, if we do it universally. Just look at <http://grep.cpan.me/?q=\%24%40+%3D~+%2F\^>: $@ =~ /^Can't locate/ If we do it based on the eval site, then I suppose the error code could go at the beginning, but the thing I mention above about re-throwing errors (does my caller want the error code?) still applies then. Since warnings should have these as well, and we already have lowercase alphabetic identifiers for some warnings (though with :: as well: experimental::postderef), I suggest we use lowercase names, rather than PERL-W001. That way they will be recognizable without having to look up the number: -e வரி 1 பக்கம் வழிதல். [format::overflow] Forgive the clunky machine translation. -- Father Chrysostomos |
From @cpansproutOn Tue Sep 16 22:33:32 2014, I wrote:
Gah! How did I manage that? I’m not that illiterate! It should be ‘write’, of course. -- Father Chrysostomos |
From @demerphqOn 17 September 2014 07:42, Father Chrysostomos via RT <
I got you write the first place. :-) Yves -- |
From PeterCMartini@GMail.comAre error/warning objects out of the discussion because of backcompat I much prefer objects, because we can get a sane tree of them - which What if we create a new (C-level) variable, PL_errsv, with PL_errgv |
From @cpansproutOn Tue Sep 16 22:49:16 2014, pcm wrote:
Probably a bit of both, but mostly the former.
Assuming you mean GvSV(PL_errgv), you are not taking local *@ into account. I’ve had to do that in some of my code to work around perl bugs.
The tied variable itself could choose whether to return a reference
Nice idea, but it needs simplification. :-) How about a new variable? -- Father Chrysostomos |
From @b2gillsOn Wed, Sep 17, 2014 at 12:59 AM, Father Chrysostomos via RT
I think it should be a single perl data structure so that it gets So just have it be a tied object that acts like a string. I don't think it would be too annoying that you have to Perhaps we could add a CATCH block similar to Perl6 If you rethrow a Perl error object it should get tied like it was Just a quick <10min thought. |
From @AbigailI'm not to fond of the "let's change the behaviour, and have it controlled Why not something like: * We leave $@ as is. That way, any existing code remains working. And there's no action at a Abigail |
From @rjbs* Abigail <abigail@abigail.be> [2014-09-17T11:51:05]
...and I think that in this case, it's going to be confusing. Errors happily
Once we are doing this, why not ${^ERROR_OBJ}? It need only provide, for now, At any rate, I think it's a promising idea. -- |
From @ap* Father Chrysostomos via RT <perlbug-followup@perl.org> [2014-09-17 07:35]:
I like this. I particularly like the idea of this being the same identifier you would The »PERL-W« part also serves a usability role in the other proposal, Regards, |
From @jhi
If we have more 'structure' in the errors (class, severity, message, |
From @cpansproutOn Wed Sep 17 08:57:18 2014, perl.p5p@rjbs.manxome.org wrote:
It still poses the problem of re-throwing errors. So perhaps die( Yves’ suggestion of adding the ID to the stringification helps significantly here. Also, what if someone writes die( -- Father Chrysostomos |
From @rgarciaOn 17 September 2014 17:51, Abigail <abigail@abigail.be> wrote:
I was thinking about this thread and I wonder what codes should be assigned Also, if someone turns on fatalisation of a warning, should the code be reported |
From @lizmatOn 23 Sep 2014, at 10:01, Rafael Garcia-Suarez <rgs@consttype.org> wrote:
Far being it for me to suggest an approach from Perl 6. But maybe you just need to define a class per exception, and define its API there and then, instead of using numbers? Such classes typically start with X:: in Perl 6. Then translation would just mean overriding these classes with another language’s version, as long as they have the same API, that shouldn’t be a problem? Liz |
From @AbigailOn Tue, Sep 23, 2014 at 10:01:34AM +0200, Rafael Garcia-Suarez wrote:
But all bets are off with user generated warnings anyway, whether they Perhaps we can recommend that each package keeps its own list of numbers, if (${^WARNING_OBJ} -> warning_code eq "Some::Long::Package::Name::Several::Levels::Deep::127") {
I'm included to say "error code", but if we go for numbers, I strongly Abigail |
From @cpansproutOn Tue Sep 23 01:02:16 2014, rgs@consttype.org wrote:
I have been opposed to numbers from the beginning, because we already have warning categories, and those should be part of the warning ID. Modules that register warnings can just do MyPackage::toolumpy or whatever for the warning ID.
There would be no distinction between the two.
What do you have against fatal warnings? Is it the same thing I have against them, that you are shooting yourself in the foot? -- Father Chrysostomos |
From @demerphqOn 23 September 2014 17:33, Father Chrysostomos via RT <
The reason I favour numeric ids is that they are truly transligual. Yves |
From @cpansproutOn Tue Sep 23 09:29:51 2014, demerphq wrote:
But they are not particularly memorable. Put them in Sepedi or Japanese if you have to. I won’t complain, as long as they are more memorable than numbers. -- Father Chrysostomos |
From @karenetheridgeOn Wed, Sep 24, 2014 at 10:07:39PM -0700, Father Chrysostomos via RT wrote:
Why not numbers *and* names, where they are considered equivalent to each |
From @demerphqOn 25 September 2014 07:46, Karen Etheridge <perl@froods.org> wrote:
Yes I agree. An error should have a number, a symbolic code, and a Yves -- |
Migrated from rt.perl.org#122794 (status was 'open')
Searchable as RT122794$
The text was updated successfully, but these errors were encountered: