Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

Re^3: Trap the error msg from Mime::Lite

by Sidhekin (Priest)
on Jan 23, 2008 at 13:36 UTC ( #663783=note: print w/replies, xml ) Need Help??

in reply to Re^2: Trap the error msg from Mime::Lite
in thread Trap the error msg from Mime::Lite

What I need to do is capture those error(s), print a copy to stdout (which along with stderr is re-directed to my logfile) and save a copy in a variable that I can then use elsewhere.

Right. I think I'd choose grep for that one. Replace my last line above with these:

my @errors = grep { defined && length } $trap->die, $trap->stderr, $tr +ap->stdout; print "Error: $_\n" for @errors; # any and all error(s) are now left in @errors

Update: Oh, and "logfile"? Is this for production, not just testing? Then I'd definitely get Test::Trap version 0.1.0 — it fixes, among other things, a bug that in this case might slowly fill up your /tmp partition. Oops.

print "Just another Perl ${\(trickster and hacker)},"
The Sidhekin proves Sidhe did it!

Replies are listed 'Best First'.
Re^4: Trap the error msg from Mime::Lite
by chrism01 (Friar) on Jan 24, 2008 at 00:07 UTC
    Thx for the warning(!). Just checked and the 1st 2 lines are:
    package Test::Trap; use version; $VERSION = qv('0.1.0');
    so hopefully that's all good. :)

    Actually, I already came up with this:

    # Send trap { $msg->send or $error_msg = "Error: $! $@\n" }; $_ and $error_msg .= ": $_\n" for $trap->die, $trap->stdout, $trap +->stderr; exit_with_error("email_csv_file() failed: $error_msg") if( $error_ +msg );
    to try and get everything. Looks ok?

    My exit_with_error($msg) sub sends a regular email via Mail::Mailer and prints to the logfile, then cleans up other stuff and and exit(1) etc.
    Y, it's a prodn system. No cxn to internet though (and I don't have root), so I have to go through the sysadmin to get extra modules installed like Test::Trap, etc. Hence the delay in my replies.


Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://663783]
and all is calm...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (3)
As of 2017-05-28 09:11 GMT
Find Nodes?
    Voting Booth?