Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Carpout makes script run, but outputs no errors?

by punch_card_don (Curate)
on Sep 22, 2008 at 22:02 UTC ( [id://713113]=perlquestion: print w/replies, xml ) Need Help??

punch_card_don has asked for the wisdom of the Perl Monks concerning the following question:

Megawatt Monks,

I have a long script that retrieves data from a Mysql DB of user data then outputs it to browser using Template Toolkit. Everything works fine most of the time, but I came across one user record for which the script hangs, then times out to a 'misconfiguration' error. I telnet the db and see this record has some info few others have - maybe it's a data format problem or something like that.

So to the top of my script I add:

BEGIN { use CGI::Carp qw(carpout); carpout(STDOUT); }
Suddenly the script runs perfectly for the user record in question, and no errors are output. Nada.

Any general ideas on what kind of effect having this snippet in there has that it would have this effect?

Thanks.




Time flies like an arrow. Fruit flies like a banana.

Replies are listed 'Best First'.
Re: Carpout makes script run, but outputs no errors?
by moritz (Cardinal) on Sep 22, 2008 at 22:08 UTC
    The "obvious" answer is that STDERR of the script somehow doesn't work (for example it might not be opened, or opened to a pipe with something hanging at the other end), and something tries to write to STDERR.

    You might not notice the output when it goes to STDOUT (maybe it's after the end of the closing body or html tag or somewhere else where your browser doesn't display it?). Or maybe something even tries warn() with an empty string or just a space or something similar.

    To test this idea, simply print something to STDERR and see if it also hangs.

Re: Carpout makes script run, but outputs no errors?
by punch_card_don (Curate) on Sep 23, 2008 at 14:27 UTC
    Hmmm - Moritz & Anonymous Monk got me thinking, and I changed it to:
    BEGIN { use CGI::Carp qw(carpout); open(ERROR_LOG, ">>my_error_log") or die("my_error_log: $!\n"); carpout(\*ERROR_LOG); }
    And low & behold, there's my error output - mostly uninitialized values used in comparisons and concatenations. I've been pasting together old subroutines and some variables used in the subroutines but not in my application are not getting initialized for a few records.

    I'll fix all that and see if it then runs without this.

    Thanks.

    Update: yep, that did it.




    Time flies like an arrow. Fruit flies like a banana.
      This demonstrates yet again that copy&paste is the programmer's devil - so tempting, so easy, and yet evil and fraught with peril.
Re: Carpout makes script run, but outputs no errors?
by Anonymous Monk on Sep 23, 2008 at 09:29 UTC
    Suddenly the script runs perfectly for the user record in question, and no errors are output. Nada.
    Your browser is probably tricking you
    C:\>echo >1 C:\>perl -MCGI::Carp=carpout -MCGI=:standard -e"carpout(STDOUT);print +start_html;warn 1;print end_html;" >>1 C:\>perl -MCGI::Carp=carpout -e"carpout(STDOUT);warn 2; die 3" >>1 C:\>more 1 ECHO is on. [Tue Sep 23 02:32:33 2008] -e: 1 at -e line 1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" lang="en-US" xml:lang="en-U +S"> <head> <title>Untitled Document</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1 +" /> </head> <body> </body> </html>[Tue Sep 23 02:32:36 2008] -e: 2 at -e line 1. [Tue Sep 23 02:32:36 2008] -e: 3 at -e line 1. C:\>
    You are supposed to carpout to a log file... Maybe you want fatalsToBrowser/warningsToBrowser

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://713113]
Approved by moritz
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (6)
As of 2024-04-16 19:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found