Skip Menu |

This queue is for tickets about the Error CPAN distribution.

Report information
The Basics
Id: 20724
Status: resolved
Priority: 0/
Queue: Error

People
Owner: Nobody in particular
Requestors: dbasch [...] yahoo.com
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: 0.15
Fixed in: (no value)



D:\UseNet\clpmisc> cat err.pl #!/usr/bin/perl use strict; use warnings; use Error; throw Error::Simple -text => "Oops!" if 1; __END__ D:\UseNet\clpmisc> err -text at D:\UseNet\clpmisc\err.pl line 8. Now, of course, the error message should have been "Oops!". On the other hand: D:\UseNet\clpmisc> cat err.pl #!/usr/bin/perl use strict; use warnings; use Error; throw Error -text => "Oops!" if 1; __END__ D:\UseNet\clpmisc> err Oops! Hmmmmm ... Now, Error::Simple overrides Error->new but not Error->throw. Show quoted text
>> 265 sub new { >> 266 my $self = shift; >> 267 my $text = "" . shift;
This causes the overloaded stringification operator to be invoked which adds the "at D:\UseNet\clpmisc\err.pl line 8." at the end of the error message above. Show quoted text
>> 268 my $value = shift; >> 269 my(@args) = ();
The problem is, Error::Simple->new ends with: $self->SUPER::new(-text => $text, @args); whereas it should be $self->SUPER::new(-text => $value, @args); After making that change in Error.pm: D:\UseNet\clpmisc> cat err.pl #!/usr/bin/perl use strict; use warnings; use Error; throw Error::Simple -text => "Oops!" if 1; __END__ D:\UseNet\clpmisc> err Oops! at D:\UseNet\clpmisc\err.pl line 8.
On Thu Jul 27 13:35:01 2006, dbasch wrote: Show quoted text
> throw Error::Simple -text => "Oops!" if 1;
This is not the way it's supposed to be used. perldoc Error reports: ----- SYNOPSIS use Error qw(:try); throw Error::Simple( "A simple error"); ----- Error::Simple only wants the string as the text, not a full hash-like array of keys. Take a look at the attached demo, showing the wrong and correct uses of this subclass. I get the following output from it: ----- The following two are wrong: Argument "Oops!" isn't numeric in addition (+) at /usr/local/share/perl/5.8.8/Error.pm line 275. Argument "Oops!" isn't numeric in addition (+) at /usr/local/share/perl/5.8.8/Error.pm line 275. -text at ./bug-rt_20724-test.pl line 24. -text at ./bug-rt_20724-test.pl line 25. The following four are correct: Oops! Oops! Oops! at ./bug-rt_20724-test.pl line 33. Oops! at ./bug-rt_20724-test.pl line 34. ----- -- Paul Evans
#!/usr/bin/perl -w use strict; use Error qw(:try); sub map_catch(@) { my @exceptions; map { try { $_->(); push @exceptions, undef; } catch Error with { push @exceptions, shift; }; } @_; return @exceptions; } print "The following two are wrong:\n"; print join "\n", map_catch sub { die new Error::Simple -text => "Oops!" }, sub { throw Error::Simple -text => "Oops!" }, ; print "The following four are correct:\n"; print join "\n", map_catch sub { die new Error -text => "Oops!" }, sub { throw Error -text => "Oops!" }, sub { die new Error::Simple "Oops!" }, sub { throw Error::Simple "Oops!" }, ;
Subject: Synopsis is wrong
From: dbasch [...] yahoo.com
On Tue Aug 08 14:28:52 2006, PEVANS wrote: Show quoted text
> On Thu Jul 27 13:35:01 2006, dbasch wrote:
> > throw Error::Simple -text => "Oops!" if 1;
> > This is not the way it's supposed to be used. > > perldoc Error > > reports: > > ----- > SYNOPSIS > use Error qw(:try); > > throw Error::Simple( "A simple error"); > ----- > > Error::Simple only wants the string as the text, not a full hash-like > array of keys. > > Take a look at the attached demo, showing the wrong and correct uses of > this subclass. I get the following output from it: > > ----- > The following two are wrong: > Argument "Oops!" isn't numeric in addition (+) at > /usr/local/share/perl/5.8.8/Error.pm line 275. > Argument "Oops!" isn't numeric in addition (+) at > /usr/local/share/perl/5.8.8/Error.pm line 275. > -text at ./bug-rt_20724-test.pl line 24. > > -text at ./bug-rt_20724-test.pl line 25. > The following four are correct: > Oops! > Oops! > Oops! at ./bug-rt_20724-test.pl line 33. > > Oops! at ./bug-rt_20724-test.pl line 34. > -----
The hash passing example needs to be corrected in the synopsis then: try { do_some_stuff(); die "error!" if $condition; throw Error::Simple -text => "Oops!" if $other_condition; } That is what led me to file this bug in the first place. Thanks.
On Tue Aug 08 14:40:01 2006, dbasch wrote: Show quoted text
> The hash passing example needs to be corrected in the synopsis then: > > try { > do_some_stuff(); > die "error!" if $condition; > throw Error::Simple -text => "Oops!" if $other_condition; > } > > That is what led me to file this bug in the first place. Thanks.
I've now corrected the POD to say throw Error::Simple "Oops!" if $other_condition; That's in the latest svn source, which will form the next release to CPAN. -- Paul Evans
[oops. pressed wrong button. closing again] -- Paul Evans