You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Mithun Bhattacharya <mi...@egurucool.com> on 2002/01/19 06:59:18 UTC

How to handle die

Hello,

I am running ePerl on my Apache server and a little problem has been 
bugging me a lot. When I do a die "blah blah blah" inside a eval I get 
the following in my browser. It doesnt matter which browser I use or 
which version of apache I use or which version of Apache::ePerl I use.

--------------------
Apache::ePerl
Version 2.0214

ERROR:
Error on evaluating script from P-code

Contents of STDERR channel:

blah blah blah at /xxxx/tmp/test.html line 2.
--------------------

logs/error_log says

--------------------
[Sat Jan 19 11:23:01 2002] [error] access to /xxxx/tmp/test.html failed 
for xx.xx.xx.xx, reason: Apache::ePerl: Error on evaluating script from 
P-code
--------------------

I would like to know a couple of things in this context :
1. Is die supposed to be handled by ePerl/EmbPerl/Mason ... or did ePerl 
end up over ridding something. In that case I would rather have it 
restored to the default.
2. How do I implement a solution throughout the site without having to 
do goofy stuff in every HTML page or module.
3. Why would anyone do that in the first place ?

Before anyone suggests it - no I cant move to EmbPerl or Mason or 
anything else.

ePerl can be found as Apache::ePerl on cpan or 
http://www.engelschall.com/sw/eperl/ . I wouldnt know if Engelschall is 
on this list but if he is - feedback would be highly appreciated :). 
Also I wonder whether it has been abandoned or renamed since nothing has 
changed since 02-08-1998 (8th Feb ??). The latest version isnt on CPAN 
either.



Mithun


Re: handling eval in ePerl

Posted by Perrin Harkins <pe...@elem.com>.
> print STDERR "blah blah blah" is going to the browser but I am not
> really worried about it too much unless it is something I should worry
> about - anyone care to comment on that ?

Printing error messages to the public is a potential security risk, so
you have to decide how paranoid you want to be.  You could change this
behavior by modifying the tied STDERR in Parse::ePerl or maybe in
Apache::ePerl where it prints the message to the browser.

> Ofcourse I still dont understand why die was being trapped out there.

It is being trapped to allow for error reporting and to avoid leaving
the program in an unknown state when a problem occurs.  If you want it
to still work for this but not pick up your eval() calls, you can
replace the __DIE__ handler there with something fancier like this:

local $SIG{__DIE__} = sub {
     my $in_eval = 0;
     for( my $stack = 1;  my $sub = (CORE::caller($stack))[3];
 $stack++ ) {
         $in_eval = 1 if $sub =~ /^\(eval\)/;
     }
     $error .= $_[0] unless $in_eval;
};

This is a slight variation of some Michael Schwern code that Stas posted
a little while ago.

- Perrin



Re: handling eval in ePerl

Posted by Mithun Bhattacharya <mi...@egurucool.com>.
Perrin Harkins wrote:

> local $SIG{'__DIE__'}  = sub { $error .= $_[0]; };
> 
> That's going to kill your exception handling code.  You need to change
> that if you want to be able to use eval() in your code.  Matt has an
> explanation of this in the exceptions part of the mod_perl Guide.


Hmm,

I think just commenting it worked !!. I have tried the following which 
have worked the way it should.

-------------------
# Exception handling
eval {die "blah blah blah";};
print "got : $@";
-------------------
die "blah blah blah";
-------------------
# Write to error log
use Apache::Log;
Apache->request->log->error("got : $@");
-------------------
# Syntax error
eval {die "blah blah blah";
print "got : $@";
-------------------


print STDERR "blah blah blah" is going to the browser but I am not 
really worried about it too much unless it is something I should worry 
about - anyone care to comment on that ?

Ofcourse I still dont understand why die was being trapped out there.

Thanks to Perrin and Matt for their suggestions anyway.



Mithun


Re: handling eval in ePerl

Posted by Perrin Harkins <pe...@elem.com>.
> Umm I didnt mean to offend anyone in my previous posting - I did say I
> probably hadnt presented my situation properly.

No problem, I just meant "don't give up so quickly."

> Ofcourse you noticed I wrote ePerl/EmbPerl/Mason ?? I clubbed them
> together since I assume among other things you can embed perl code in
> HTML using either of them.

You can, but they don't share any code with ePerl.

> My problem is that die works fine as such but it conks out if done
> inside a eval.

Okay, I missed the part about eval() before.  Take a look at this code
from Parse::ePerl::Evaluate() :
local $SIG{'__DIE__'}  = sub { $error .= $_[0]; };

That's going to kill your exception handling code.  You need to change
that if you want to be able to use eval() in your code.  Matt has an
explanation of this in the exceptions part of the mod_perl Guide.

> It feels like being told to
> change gcc's code if my C code is not working :) - yah both of them
are
> written in C .

Apache::ePerl is written in perl.  It calls Parse::ePerl to do the dirty
work, and some of that is written in C, but not the part that's causing
you problems.

- Perrin


Re: handling eval in ePerl

Posted by Matt Sergeant <ma...@sergeant.org>.
On Mon, 21 Jan 2002, Mithun Bhattacharya wrote:

> Perrin Harkins wrote:
>
>
> Umm I didnt mean to offend anyone in my previous posting - I did say I
> probably hadnt presented my situation properly.

I don't think anyone was offended. Perrin was just trying to help you see
why people might not have replied. That's what I got from the tone anyway.

> > The Apache::ePerl code is very simple, and I suggest you read it at some
> > point.  It attempts to eval() your code, and does the behavior you saw
> > if it fails (which is what happens when your script does a die()).  I
> > don't think you can change that without changing the code, but that's
> > pretty easy to do.
>
> My problem is that die works fine as such but it conks out if done
> inside a eval.
>
> ----------------------
> <%
> die "blah blah blah";
> %>
> ----------------------
>
> redirects me to the default error page.
>
> ----------------------
> <%
> eval {die "blah blah blah";};
> %>
> ----------------------
>
> on the other hand says the following.
>
> ----------------------
> Apache::ePerl
> Version 2.0214
>
> ERROR:
> Error on evaluating script from P-code
>
> Contents of STDERR channel:
>
> blah blah blah at /xxxx/test.html line 2.
> ----------------------

It looks to me like the generated code that ePerl is trying to eval is
bad. That seems like it's most likely this is an actual ePerl problem, and
so the only thing I can suggest is you hack the ePerl code to actually
display $@ when the evaluation of the "script from P-code" occurs (why on
earth aren't they doing that already??). Also I suggest while you're in
there, have it print the script to STDERR before doing the eval, so you
can check the error log and see what ePerl thinks your parsed script looks
like.

> I am not sure why that might be considered acceptable response but it
> really makes my code a lot more messier trying to circumvent that.
>
> If I could have fixed Apache::ePerl I wouldnt be asking the question
> here - I usually dont go around asking questions to show people how much
> I know about anything. I am not asking to be spoonfed or something but
> if there is something which can be done without changing the
> Apache::ePerl code I would opt for that. It feels like being told to
> change gcc's code if my C code is not working :) - yah both of them are
> written in C .

The difference being that gcc is maintained, so you might stand a cat in
hell's chance of some help from the authors or getting a bug fix.
Unfortunately ePerl isn't maintained, so you have to open the bonnet (hood
to USians) and fix things yourself.

-- 
<!-- Matt -->
<:->Get a smart net</:->


handling eval in ePerl

Posted by Mithun Bhattacharya <mi...@egurucool.com>.
Perrin Harkins wrote:


Umm I didnt mean to offend anyone in my previous posting - I did say I 
probably hadnt presented my situation properly.

> First, ePerl has nothing to do with Embperl or Mason.  It is a totally



Ofcourse you noticed I wrote ePerl/EmbPerl/Mason ?? I clubbed them 
together since I assume among other things you can embed perl code in 
HTML using either of them.



> The Apache::ePerl code is very simple, and I suggest you read it at some
> point.  It attempts to eval() your code, and does the behavior you saw
> if it fails (which is what happens when your script does a die()).  I
> don't think you can change that without changing the code, but that's
> pretty easy to do.


My problem is that die works fine as such but it conks out if done 
inside a eval.

----------------------
<%
die "blah blah blah";
%>
----------------------

redirects me to the default error page.

----------------------
<%
eval {die "blah blah blah";};
%>
----------------------

on the other hand says the following.

----------------------
Apache::ePerl
Version 2.0214

ERROR:
Error on evaluating script from P-code

Contents of STDERR channel:

blah blah blah at /xxxx/test.html line 2.
----------------------

I am not sure why that might be considered acceptable response but it 
really makes my code a lot more messier trying to circumvent that.

If I could have fixed Apache::ePerl I wouldnt be asking the question 
here - I usually dont go around asking questions to show people how much 
I know about anything. I am not asking to be spoonfed or something but 
if there is something which can be done without changing the 
Apache::ePerl code I would opt for that. It feels like being told to 
change gcc's code if my C code is not working :) - yah both of them are 
written in C .



Mithun


Re: How to handle die

Posted by Perrin Harkins <pe...@elem.com>.
> Umm it didnt really answer my original query but I guess since no one
> has answered it - either I didnt present it correctly or no one has a
> answer to it.

Or you posted it late on Saturday night on a weekend when most US
workers have Monday off and may be travelling.  Not everyone is on the
same schedule as you, so give it a little time.

> I probably wont jump into the "I want a newbie mailing list" fray for
> this though ;).

I don't think it would make a difference.  It would be pretty much the
same people on either list.

There are a couple of people on this list who use ePerl.  You might want
to repost with "ePerl" in your subject.  However, most of us no longer
use it.  ePerl is getting old at this point and has a pretty small
feature set compared to the more actively maintained alternatives.

Here's an attempt to answer your questions:

> 1. Is die supposed to be handled by ePerl/EmbPerl/Mason
> ... or did ePerl end up over ridding something. In that
> case I would rather have it restored to the default.

First, ePerl has nothing to do with Embperl or Mason.  It is a totally
separate program.

The Apache::ePerl code is very simple, and I suggest you read it at some
point.  It attempts to eval() your code, and does the behavior you saw
if it fails (which is what happens when your script does a die()).  I
don't think you can change that without changing the code, but that's
pretty easy to do.

> 2. How do I implement a solution throughout the site without
> having to do goofy stuff in every HTML page or module.

Solution to what?  To having die() trapped?  Changing the Apache::ePerl
code will be a site-wide change, so I'd suggest you do it there.

> 3. Why would anyone do that in the first place ?

Why catch exceptions?  Usually to allow the program to try something
else, clean up resources, or print a useful error message.

- Perrin


Re: How to handle die

Posted by Mithun Bhattacharya <mi...@egurucool.com>.
___cliff rayman___ wrote:


> sw-wml@engelschall.com
> 
> To subscribe to this Majordomo-controlled mailing list, just send an E-mail



Umm it didnt really answer my original query but I guess since no one 
has answered it - either I didnt present it correctly or no one has a 
answer to it.

I probably wont jump into the "I want a newbie mailing list" fray for 
this though ;).



Mithun


Re: How to handle die

Posted by ___cliff rayman___ <cl...@genwax.com>.
Mithun Bhattacharya wrote:

> Before anyone suggests it - no I cant move to EmbPerl or Mason or
> anything else.

ok

>
>
> ePerl can be found as Apache::ePerl on cpan or
> http://www.engelschall.com/sw/eperl/ . I wouldnt know if Engelschall is
> on this list but if he is - feedback would be highly appreciated :).
> Also I wonder whether it has been abandoned or renamed since nothing has
> changed since 02-08-1998 (8th Feb ??). The latest version isnt on CPAN

his new project is wml:

http://www.engelschall.com/sw/wml/docs/
it has an eperl component.  not sure if it will run old ePerl code
however.  there is a mailing list at:

sw-wml@engelschall.com

To subscribe to this Majordomo-controlled mailing list, just send an E-mail to
                         majordomo@engelschall.com with only

                           subscribe sw-wml you@domain.dom.

--
___cliff rayman___cliff@genwax.com___http://www.genwax.com/