Skip Menu |

This queue is for tickets about the Devel-SimpleTrace CPAN distribution.

Report information
The Basics
Id: 13063
Status: resolved
Priority: 0/
Queue: Devel-SimpleTrace

People
Owner: Nobody in particular
Requestors: martin [...] hybyte.com
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: 0.04
Fixed in: 0.05



Subject: Failing tests for Error->throw (object or structure)
using Devel::SimpleTrace stops some tests from working. If your test expects an exception thrown, and test for the result it will likely fail with Devel::SimpleTrace. This is as $@ is replaced by a text including the callstack. The problem arises for test like eval { die "text" }; ok $@ eq 'text'; or for object or perl data structures beeing thrown. also watch the following command line scripts perl -MDevel::SimpleTrace -we ' eval { die { a=>1 }; }; print ref $@; ' perl -we ' eval { die { a=>1 }; }; print ref $@; ' HASH Not sure how to Fix, I dont know, why the code is doing anything if die occurs in_eval from sub _do_die : if($in_eval) { $@ = $stderr; $stderr = ''; $in_eval = 0; CORE::die $@ } Possible Solutions: - do nothing if in_eval - do nothing by default, and allow to enable this feature, by passing an arg to import: use Devel::SimpleTrace 'eval' allow several switches, for $@ is plain text, or structure/object - do it by default (maybe only for text), and allow to switch on/off the rest Also a nice Idea (or has someone a better solution) allow switching via $ENV. if you do "perl -MDevel::SimpleTrace " you cant pass arguments to import. So TRACE_EVAL=0 perl -MDevel::SimpleTrace could do the trick.
Date: Wed, 22 Jun 2005 02:11:49 +0200
Subject: Re: [cpan #13063] Failing tests for Error->throw (object or structure)
From: Sébastien Aperghis-Tramoni <saper [...] cpan.org>
To: bug-Devel-SimpleTrace [...] rt.cpan.org
RT-Send-Cc:
Hello, Apologies for answering only now, but I'll take the organisation of FPW2005 as an excuse :-) You wrote: Show quoted text
> using Devel::SimpleTrace stops some tests from working. > > If your test expects an exception thrown, and test for the result it > will likely fail with Devel::SimpleTrace. > > This is as $@ is replaced by a text including the callstack. > > The problem arises for test like > > eval { die "text" }; > ok $@ eq 'text';
Hmm.. That code looks like a red flag to me. I think you should not try to compare the error message with eq but with a m// to match the beginning of the string because the actual text may vary from what you can expect. And if you are doing this for tests, Test::Warn and Test::Exception are most certainly better suited for this task. Show quoted text
> or for object or perl data structures beeing thrown. > > also watch the following command line scripts > > perl -MDevel::SimpleTrace -we ' eval { die { a=>1 }; }; print ref $@; ' > > perl -we ' eval { die { a=>1 }; }; print ref $@; ' > HASH
I didn't know you could give die() a ref and expect it to actually work. perldoc confirms me this is a valid and documented usage so I take that as a bug or caveat of Devel::SimpleTrace. Show quoted text
> Not sure how to Fix, I dont know, why the code is doing anything if > die occurs in_eval > > from sub _do_die : > > if($in_eval) { > $@ = $stderr; > $stderr = ''; > $in_eval = 0; > CORE::die $@ > }
IIRC this code is here to avoid some forms of eval() that were causing Devel::SimpleTrace to produce incorrect traces (I can't remember the exact details). Show quoted text
> Possible Solutions: > - do nothing if in_eval
No. The aim of Devel::SimpleTrace is to allow for an easier mean to trace warnings and errors, even those that are inside eval(). Show quoted text
> - do nothing by default, and allow to enable this feature, by passing > an arg to import: > use Devel::SimpleTrace 'eval' > allow several switches, for $@ is plain text, or structure/object > - do it by default (maybe only for text), and allow to switch on/off > the rest
Hmm.. I can print the traces as usual when it's plain text and just return the thing unchanged when it's an object or reference. But I'd say that I primarily wrote Devel::SimpleTrace in order to ease interactive debugging sessions, by just adding it to perl switches: perl -WMDevel::SimpleTrace program_with_hairy_warnings.pl Of course you can use it permanently with a "use Devel::SimpleTrace", it's just that I didn't think it would be its typical usage :-) So I understand the need to preserve the references when seeing them, but I also see that a mode where Devel::SimpleTrace stringify them would be very useful. This is what should be the option: stringify references. Show quoted text
> Also a nice Idea (or has someone a better solution) allow switching > via $ENV. > > if you do "perl -MDevel::SimpleTrace " you cant pass arguments to > import. So > > TRACE_EVAL=0 perl -MDevel::SimpleTrace > could do the trick.
In fact, you can; for example: perl -MO=Deparse -le 'print "hello"' will load the O module, giving it the "Deparse" argument, which will instruct it to load the B::Deparse module. The generic form is: perl -MModule=arg1,arg2,arg3 Check perlrun(1) for the details. So no need for environment variable, although I could also recognize one. Sébastien Aperghis-Tramoni -- - --- -- - -- - --- -- - --- -- - --[ http://maddingue.org ] Close the world, txEn eht nepO
Another option, to handle a die with data structure in eval, is to print the trace directly to STDOUT or STDERR, and leave the sructure untouched. This will even increase the amount of output compared against what there is now, because you have no warranty that the modified $@ ever is printed (or warned). That is if you want that as default, as I would still say that an object in $@ clearly means, the code was ecpected to die, and handle that. More complexwould be, to keep quiet in the case above, but to remember, ther callstack in a variable. If you have a pragramm like eval { .....; die $exception_object; ...}; if ($@->isa('xxx') {} # catch expected stuff else {die $@} you could detect, that thi object was died earlier, and append the info. same for a: warn $@