Way to capture stack trace output from CGI::Carp?? 
Author Message
 Way to capture stack trace output from CGI::Carp??

Hi everyone,

I would like to capture a stack trace of any fatal errors and email them
to myself when a fatal error occurs in my scripts.  

Now I know how to set up a die handler through $SIG{__DIE__} and I know
how to email myself something.  

I also know how to output fatal error messages to the screen through the
use CGI::Carp qw(carpout fatalsToBrowser); line.

What I don't know how to do is to capture the output of a croak (that  
gives me a stack trace) so that I could email it to myself.  

If I can capture the croak or stack trace output as a string I can take
it from there but is there a way to do that?

Maybe through some other module?

Thanks.

---
Carlos
www.internetsuccess.ca (not operational yet)



Mon, 05 Apr 2004 02:27:14 GMT  
 Way to capture stack trace output from CGI::Carp??

I figured out a way to capture the stack trace by adding the following to
the top of my code...

use CGI::Carp qw(carpout fatalsToBrowser set_message);
BEGIN {
  sub handle_errors {
    my $msg = shift;
    print "<h1>Oh gosh</h1>";
    print "Got an error: $msg";
  }
  set_message(\&handle_errors);

Quote:
}

Then I set die handler through $SIG{__DIE__} to be a routine that ouputs
a generic message to a user and the full stack trace to me (I beleive it
was Randall who wrote some sample code in Linux world(?) - I lost the
link - it showed how to use $SIG{__DIE__} - anyway thanks.).  

Can anyone see any pitfalls to doing things this way?  I know that the
use CGI::Carp qw(carpout fatalsToBrowser set_message); line is normally a
big security hole in giving out too much info to visitors but since the
output of Carp is now redirected to me through email, a visitor never
sees it.

I have also heard that use CGI::Carp qw(carpout fatalsToBrowser) slows
down my code but it doesn't seem to have any noticeable effect in having
my code run slowly.

Thanks.

---
Carlos
www.internetsuccess.ca (not operational yet)



Mon, 05 Apr 2004 02:50:54 GMT  
 Way to capture stack trace output from CGI::Carp??

I figured out that I can simplify things and do the samne thing by ...

#!/usr/bin/perl -W
$SIG{__DIE__} = \&error_control;
use CGI::Carp;

step1();
sub step1 {step2();}
sub step2 {croak "\nScript died here...\n";}

sub error_control
{
  my $message = shift;
  print "Content-type: text/html\n\n";

  print "<br>$message<br>";

Quote:
}

The output is not exactly pretty in this code snippet but it does what I
want.

Any suggestions on the above code or pitfalls I may be missing?

---
Carlos
www.internetsuccess.ca (not operational yet)



Mon, 05 Apr 2004 03:17:04 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Whats the meaning of this stack trace

2. How to go up stack trace?

3. Any way to automatically stack trace on die?

4. Carp.pm and CGI::Carp.pm versioning questions

5. Carp.pm and CGI::Carp.pm versioning questions

6. Installation: Carp.pm vs. CGI::Carp

7. Carp always produces stack trace, even without 'verbose'

8. CGI to capture "multiple select" output

9. How to capture CGI program .exe output, modify it and then pass back to browser (client)

10. Capturing output of CGI::Carp confess to email to myself?

11. using CGI::Request w/o CGI::Carp

12. ANNOUNCE: Debug::Trace 0.04 -- tracing subroutine calls

 

 
Powered by phpBB® Forum Software