Skip Menu |

This queue is for tickets about the Clamd CPAN distribution.

Report information
The Basics
Id: 6614
Status: new
Priority: 0/
Queue: Clamd

People
Owner: Nobody in particular
Requestors: cfaber [...] fpsn.net
Cc:
AdminCc:

Bug Information
Severity: Important
Broken in: 1.00
Fixed in: (no value)



Subject: Clamd fails to return errors in a meaningful way
Hi, I noticed while using the Clamd application in one of my scripts that it either warns or dies on error, and there is no meaningful way of returning error messages from the Clamd module it self. The solution is to provide an error handler routine which can collect and return the error message it self. Commonly this error handler routine is known as: errstr() - which is the name I've chosen to use. I've attached a patch which adds this functionality to the Clamd.pm library, Nothing else has been modified.
--- Clamd-1.04/lib/Clamd.pm Thu Nov 21 07:51:45 2002 +++ Clamd-1.05/lib/Clamd.pm Sun Jun 13 14:07:34 2004 @@ -6,7 +6,7 @@ use File::Find qw(find); use IO::Socket; -$VERSION = '1.04'; +$VERSION = '1.05'; =head1 NAME @@ -219,14 +219,21 @@ while (my $result = $conn->getline) { chomp($result); - if ($result !~ /^(.*): (.*)(ERROR|FOUND|OK)$/ and $options->{ShowWarnings}) { - warn("Unrecognised line from clamd: $result\n"); + if ($result !~ /^(.*): (.*)(ERROR|FOUND|OK)$/){ + if($options->{ShowWarnings}){ + warn("Unrecognised line from clamd: $result\n"); + } else { + $self->errstr("Unrecognised line from clamd: $result"); + return; + } } my ($filename, $desc, $type) = ($1, $2, $3); if ($type eq 'ERROR' and $options->{RaiseError}) { die("Error processing $filename: $desc"); - } - elsif ($type eq 'FOUND') { + } elsif($type eq 'ERROR'){ + $self->errstr("Error professing $filename: $desc"); + return; + } elsif ($type eq 'FOUND') { push @results, $filename, $desc; } } @@ -273,6 +280,18 @@ 1 while (<$conn>); $conn->close; return 1; +} + +=head2 errstr() + +Return the last error message. + +=cut + +sub errstr { + my ($self, $err) = @_; + $self->{'.errstr'} = $err if $err; + return $self->{'.errstr'}; } sub _get_connection {
From: Matt Sergeant <matt [...] sergeant.org>
Subject: Re: [cpan #6614] Clamd fails to return errors in a meaningful way
Date: Mon, 21 Jun 2004 08:05:02 +0100
To: bug-Clamd [...] rt.cpan.org
RT-Send-Cc:
On 13 Jun 2004, at 21:08, Guest via RT wrote: Show quoted text
> This message about Clamd was sent to you by guest <> via rt.cpan.org > > Full context and any attached attachments can be found at: > <URL: https://rt.cpan.org/Ticket/Display.html?id=6614 > > > Hi, > > I noticed while using the Clamd application in one of my scripts that > it either warns or dies on error, and there is no meaningful way of > returning error messages from the Clamd module it self. The solution > is to provide an error handler routine which can collect and return > the error message it self. > > Commonly this error handler routine is known as: errstr() - which is > the name I've chosen to use. > > > I've attached a patch which adds this functionality to the Clamd.pm > library, Nothing else has been modified.
Errors should be trapped by wrapping the call to clamd in eval {} (see perldoc -f eval for details on the block form of eval). Warnings can usually be dealt with before you send things to clamd (i.e. if the file is of zero size you get a warning back - but you can just skip scanning those). Sorry, patch rejected.