in reply to Archive::Tar and error handling

The warning "Something's wrong" is coming from the line

warn $tar->error unless $tar->read($device);

And indicates that whilst $tar->read( $device ) is returning false, the return value from $tar->error is undefined or null.

Whilst it may be considered "bad form" for a module to return and error, but fail to set it's error message, the module is free and if that means that the author hasn't crossed all the I's and dotted all the T's, it is still pretty good value for money:)

In this case, it probably means that the module was unable to open or read from the device. It is possible that you might get a little more information as to the cause if you were to check $! to see what, if any, system error was logged. It would be prudent to set $! = 0 before the failing call so that you aren't confused by a previous, unrelated error.

Exactly which is difficult to tell from a simple visual examination of the code. However, you have the code and the device. Maybe it time to learn to perl -d and step through the code until you can see where the error is being returned without an error message having been set. When you work out where the failure to set an error message is occuring, you can a) fix that ommission in your copy, b) send a suggestion to the author that he amends the module in a similar way.

The authors recommendation that you leave warnings enabled is only that, a recommendation. If you wish to handle the errors yourself internally, then set $Archive::Tar::WARN = 0;, the author won't hold it against you:)


Examine what is said, not who speaks.
"Efficiency is intelligent laziness." -David Dunham
"Think for yourself!" - Abigail
Hooray!

Replies are listed 'Best First'.
Re: Re: Archive::Tar and error handling
by Anonymous Monk on Oct 25, 2003 at 20:53 UTC

    I pretty much knew where the problem was and what causes it initially. The program works as expected as long as there is a tar archive as file #1 on the tape. The problem is that I have to make sure that the tape in the drive is the correct one. So I need error handling graceful enough so that the program doesn't generate cron mailings every time it runs.

    As you suggest, I can turn off the Archive::Tar warnings and don't need to use $tar->error since $! returns 'I/O error' and will probably serve for most of the other errors I might encounter. Rewritten as follows should meet my needs for now:

    use strict; use warnings; use Archive::Tar; $Archive::Tar::WARN = 0; my $device = '/dev/rmt/1'; my $tar = Archive::Tar->new(); $! = 0; $tar->read($device); die "### ERROR on \$tar->read($device): $!\n\n" if $!;

    I'll test this further and post my findings if I have to modify the approach further. Thanks for the suggestions, they were very helpful. I'm still very disppointed with the error handling capabilities of this module.