Make robust against $rs->record() failure.
[irspy-moved-to-github.git] / lib / ZOOM / IRSpy / Test / ResultSet / Named.pm
index 3a5a950..8bc7625 100644 (file)
@@ -1,4 +1,4 @@
-# $Id: Named.pm,v 1.1 2006-11-02 11:46:40 sondberg Exp $
+# $Id: Named.pm,v 1.3 2007-03-05 12:53:57 mike Exp $
 
 # See the "Main" test package for documentation
 
@@ -20,7 +20,7 @@ sub start {
 
     $conn->irspy_search_pqf("\@attr 1=4 mineral", {},
                             {'setname' => 'a', 'start' => 0, 'count' => 0},    
-                           ZOOM::Event::RECV_SEARCH, \&completed_search_a,
+                           ZOOM::Event::ZEND, \&completed_search_a,
                            exception => \&error);
 }
 
@@ -31,16 +31,24 @@ sub completed_search_a {
     my $record = '';
     my $hits = $rs->size();
 
-    ## How should be handle the situation when there is 0 hits?
+    ## How should we handle the situation when there is 0 hits?
     if ($hits > 0) {
-        $record = $rs->record(0)->raw(); 
+       my $rsrec = $rs->record(0);
+       if (!defined $rsrec) {
+           # I thought this was a "can't happen", but it sometimes
+           # does, as for example documented for
+           # kat.vkol.cz:9909/svk02 at ../../../../../tmp/bad-run-1
+           eval { $conn->check() };
+           return error($conn, $task, $test_args, $@);
+       }
+        $record = $rsrec->raw(); 
     } 
 
     $conn->irspy_search_pqf("\@attr 1=4 4ds9da94",
                             {'record_a' => $record, 'hits_a' => $hits,
                              'rs_a' => $rs},
                             {'setname' => 'b'},        
-                           ZOOM::Event::RECV_SEARCH, \&completed_search_b,
+                           ZOOM::Event::ZEND, \&completed_search_b,
                            exception => \&error);
 
     return ZOOM::IRSpy::Status::TASK_DONE;