Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Catching errors.

by Steve_BZ (Hermit)
on Apr 02, 2013 at 13:21 UTC ( #1026682=perlquestion: print w/ replies, xml ) Need Help??
Steve_BZ has asked for the wisdom of the Perl Monks concerning the following question:

Dear Monks,

I'm trying to automate the catching and reporting of remote user errors as far as possible. Mainly because users don't always want to pick up the phone, (or it's not convenient if you are in the middle of a medical procedure, for example) and don't collect the info I need to fix problems. I'd like to find out if it is possible to automate the "deeper" errors. So here is a table of some of my code's responses, as you see, there are some lines where I don't have a response except "pick up the phone".

Can anyone suggest ways of trapping these errors and sending a message of some kind to the developer?
Error Type Response
Missing help email message to developer and display help menu.
Missing translation email message to translator, display message in English
Sql error Customised die routine, send email to developer and then die.
File error Customised die routine, send email to developer and then die.
Missing perl function (eg missing 'GetChar' at line 88 in Foo.pm, perhaps you forgot to use xxx). (I remain hopeful that I can somehow trap these, but I don't know how)
Seg fault. I suspect these will always be crashes. Maybe I could run the application from a script file and the script does something with STDERR to trap the error.
Compile time crash. As above.

Any and all suggestions welcome.

Regards

Steve

Comment on Catching errors.
Re: Catching errors.
by RichardK (Priest) on Apr 02, 2013 at 13:39 UTC

    Where are you trying to catch these errors? In your application or in the OS?

    If your application is throwing 'missing perl function errors' then that suggests that you are not testing your code sufficiently. I think you should investigate test driven development, unit tests and other automated tools to help you improve your code quality.

    Are you really compiling code on user machines? This is always going to be difficult, managing the dependencies is non trivial -- but more testing will help.

      I am trying to catch the errors within the perl application using a number of standard routines like this one:

      $sth=$dbh->prepare($sql_string) or die_db(...) sub die_db{ # # Send emails. # my $message=shift; my $line_number=shift; print STDOUT $line_number, "\n", $message; my $from = hostname().'@i-mageonline.com'; my $msg = "There has been an error at line $line_number. \nThe err +or message is '$message'. "; my $sender = send_email("DB Error at line $line_number", $msg, $fr +om); my $result = $sender->MailMsg({ msg => $sender->{msg}, }) or die "$Mail::Sender::Error\n"; die "DB Error" . DBI->errstr; }

      Update

      If your application is throwing 'missing perl function errors' then that suggests that you are not testing your code sufficiently.

      This is mostly caused by uninitialised objects, like this:

      $self->{"calendar_".$n} = Wx::Calendar->new(.....); . . . $self->{calendar_9}->GetValue();
      Because $self->{calendar_9} is not created (undefined), GetValue does not exist.

      Are you really compiling code on user machines?

      By 'compile time', I mean starting the perl interpreter, and the interpreter checks (compiles) all the dependencies and says that such-and-such a module has a syntax error and the code does not even execute.

Re: Catching errors.
by MidLifeXis (Prior) on Apr 02, 2013 at 14:47 UTC

    What about feeding them to your ticket triaging system?

    --MidLifeXis

      Hi MLX,

      That would be nice.

      Do you have one you could recommend?

      My current one is yellow and is manufactured by 3M,

      Regards

      Steve

        I am very fond of Bugzilla. I does everything i have needed it to, it is fairly well maintained, and it's written in Perl.

        ----
        I Go Back to Sleep, Now.

        OGB

Re: Catching errors.
by saberworks (Curate) on Apr 02, 2013 at 19:38 UTC
    Well, you need to hook into where your app is attempting to do the work in the first place. So figuring out whether help is missing, how do you load the help? If you are loading from a file, you'd have to test if the file exists before you attempt to load it.
    if(! -f $expected_help_file) { # send your message }
    Same with translation.

    For your SQL errors, file errors, sounds like you already have something in mind (custom die function). To trap those as well as any way the program as a whole can die, you can set a SIG die handler, as described in Perl's Warn and Die Signals. This will be run every time something dies (be careful, it also gets run when a die happens in an eval, and there are examples of how to detect and ignore that case). Also you need to be careful not to rely on too much extra stuff in your die handler, the less the better. If your app died because your database connection went away and then your die handler tries to use the db connection to grab a developer email address, it obviously won't work properly.

    We also have processes that log any warnings that are emitted and those are looked at on a regular basis as they often alert us to problematic code before it gets out into production.

      Hi Saberworks,

      To trap those as well as any way the program as a whole can die, you can set a SIG die handler

      This is exacly what I want. Then I can write a handler that runs on autostart, runs my program, and then when it finishes I can check the exit code for errors.

      I'll try that.

      Regards

      Steve

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (6)
As of 2014-09-16 06:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite cookbook is:










    Results (157 votes), past polls