From: mike Date: Mon, 26 Feb 2007 14:36:55 +0000 (+0000) Subject: When a connection is in asynchronous mode, failing operations (search, X-Git-Tag: cpan_1_22~70 X-Git-Url: http://jsfdemo.indexdata.com/cgi-bin?a=commitdiff_plain;h=9bace4246ae732a8ad7f6262c53da116a31b60b0;p=ZOOM-Perl-moved-to-github.git When a connection is in asynchronous mode, failing operations (search, scan, etc.) no longer throw exceptions. This is because the event-loop in asychronous applications needs to check for errors anyway, in case the server has returned high-level diagnostics such as "unsupported use attribute". So this check within the event-loop is now the only place where error-checking need be done. Add new public ZOOM::Connection() function, check(), which throws an exception if an error is pending (even if the connection is asynchronous). New YAZ logging level, "zoom_check", notes when errors are detected and either left unreported (asynchronous connections) or thrown as exception (synchronous). --- diff --git a/lib/ZOOM.pm b/lib/ZOOM.pm index e99ddc7..a571872 100644 --- a/lib/ZOOM.pm +++ b/lib/ZOOM.pm @@ -1,4 +1,4 @@ -# $Id: ZOOM.pm,v 1.45 2007-02-13 15:31:26 mike Exp $ +# $Id: ZOOM.pm,v 1.46 2007-02-26 14:36:55 mike Exp $ use strict; use warnings; @@ -337,20 +337,34 @@ sub _conn { sub _check { my $this = shift(); + my($always_die_on_error) = @_; my($errcode, $errmsg, $addinfo, $diagset) = (undef, "x", "x", "x"); $errcode = Net::Z3950::ZOOM::connection_error_x($this->_conn(), $errmsg, $addinfo, $diagset); if ($errcode) { - if ($this->option("_check_debug")) { - print STDERR "ZOOM WARNING! $this->check() failed with error $diagset:$errcode ($errmsg) $addinfo\n"; - print STDERR "SIG{SEGV} ", (defined $SIG{SEGV} ? ("= '" . $SIG{SEGV} . "'") : "undefined"), "'\n"; - print STDERR "SIG{__DIE__} ", (defined $SIG{__DIE__} ? ("= '" . $SIG{__DIE__} , "'") : "undefined"), "'\n"; + my $exception = new ZOOM::Exception($errcode, $errmsg, $addinfo, + $diagset); + if (!$this->option("async") || $always_die_on_error) { + ZOOM::Log::log("zoom_check", "throwing error $exception"); + die $exception; + } else { + ZOOM::Log::log("zoom_check", "not reporting error $exception"); } - die new ZOOM::Exception($errcode, $errmsg, $addinfo, $diagset); } } +# This wrapper for _check() is called only from outside the ZOOM +# module, and therefore only in situations where an asynchronous +# application is actively asking for an exception to be thrown if an +# error has been detected. So it passed always_die_on_error=1 to the +# underlying _check() method. +# +sub check { + my $this = shift(); + return $this->_check(1); +} + sub create { my $class = shift(); my(@options) = @_;