Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

How to locate an error in a CGI application

by rbi (Monk)
on Aug 16, 2007 at 11:23 UTC ( #633003=perlquestion: print w/ replies, xml ) Need Help??
rbi has asked for the wisdom of the Perl Monks concerning the following question:

Hello,
I'm getting this error message in the Apache error_log file:
Use of uninitialized value in array element at (eval 9) line 86., referer: http://my.server/cgi-bin/mainscript.cgi?feature=a
I don't understand what position is this. mainscript.cgi is less than 86 lines so I guess it is in the modules I'm using, but how can I get to the specific module and line of code ?
Thanks for an explaination.

Comment on How to locate an error in a CGI application
Download Code
Re: How to locate an error in a CGI application
by moritz (Cardinal) on Aug 16, 2007 at 11:46 UTC
      I have no eval at line 9 of the mainscript.cgi (empty line, and still line 9 is indicated if I put some warn messages above line 9 just to increment the lines at the top of the mainscript.cgi code).
      Could it be in one of the modules I'm using ? How can I locate it, in that case ?

      It's the 9th execution of an eval (not an eval on line 9). For example, the script below would give

      Use of uninitialized value in array element at (eval 9) line 4.
      #!/usr/bin/perl use warnings; my $code_err = q| my @arr; my $i; $arr[$i] = 0; # line 4 within this code snippet |; my $code_ok = q|my $var = ""|; eval $code_ok for (1..8); eval $code_err; # 9th eval, but line 14 in this script

      Unfortunately, I don't think there's an easy, straightforward way to locate the warning based on the info you've got...

        Thanks for the clarification. Unfortunately I tested it with one eval at line one - not a good idea, of course ;-)

        A possible way to find the error woud be to Carp::confess() on errors, I think that works via a SIG{__DIE__} handler, but I don't know that offhand.

        Update: I just tested it, it doesn't seem to work inside an eval.

        Thanks, at least now I know what to debug in my code.
Re: How to locate an error in a CGI application
by Anonymous Monk on Aug 16, 2007 at 12:19 UTC
      Thanks but my real problem is how to locate the line where the error takes place in my codes.
        how to locate the line
        Open the file mainscript.cgi with your favourite editor. Put the cursor on line 1, then move it down 85 times. With vi that's typing 85j (or :86) while in command mode. You should end up on line 86.

        What's on that line?

        update: reading your reply, I see that I missed some information (which you didn't post). You meant to ask

        how to locate the file and the line

        --shmem

        _($_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
                                      /\_¯/(q    /
        ----------------------------  \__(m.====·.(_("always off the crowd"))."·
        ");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}
Re: How to locate an error in a CGI application
by cdarke (Prior) on Aug 16, 2007 at 13:27 UTC
    With a CGI program you might find it easier to use:
    use CGI::Carp qw(fatalsToBrowser);


      Thanks :)
Re: How to locate an error in a CGI application
by shmem (Canon) on Aug 16, 2007 at 15:24 UTC
    how can I get to the specific module and line of code ?

    Insert at the top of your script

    use Carp; $SIG{__WARN__} = \&Carp::cluck;

    That will output a backtrace at each warning.

    update - lowercase'd cluck

    --shmem

    _($_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
                                  /\_¯/(q    /
    ----------------------------  \__(m.====·.(_("always off the crowd"))."·
    ");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (4)
As of 2014-12-29 04:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (184 votes), past polls