Perl eval improvements in eg_staged_bib_overlay.
authorJason Stephenson <jason@sigio.com>
Sun, 7 Aug 2016 14:23:42 +0000 (10:23 -0400)
committerGalen Charlton <gmc@esilibrary.com>
Mon, 8 Aug 2016 18:24:06 +0000 (14:24 -0400)
Two changes to improve the eval conditions added in the previous
commit:

1. Both error handlers now warn with the same message:

   Record $i is bad: $@; skipping.

Thereby reporting the original message in case the user wants to try
and recover the records later.

2. If a bib record's 901$c is either missing or not numeric, die() is
called with a message to that effect.  This eliminates the Perl
warnings about exiting an eval block with next.

Signed-off-by: Jason Stephenson <jason@sigio.com>
Signed-off-by: Galen Charlton <gmc@esilibrary.com>

eg_staged_bib_overlay

index a517a6a..836795b 100755 (executable)
@@ -285,14 +285,13 @@ sub handle_stage_bibs {
             my $marc = MARC::Record->new_from_usmarc($_);
             my $bibid = $marc->subfield('901', 'c');
             if ($bibid !~ /^\d+$/) {
-                print STDERR "Record $i is suspect; skipping\n";
-                next;
+                 die('Subfield 901$c is not numeric or missing.');
             }
             my $xml = OpenILS::Application::AppUtils->entityize($marc->as_xml_record());
             $ins->execute($xml, $bibid);
         };
         if ($@) {
-            print STDERR "Record $i is bad; skipping\n";
+            warn("Record $i is bad: $@; skipping.");
             next;
         }
     }
@@ -473,7 +472,7 @@ sub handle_stage_auths {
             $ins->execute($xml, $authid, $lccn, $cancelled_lccn, $xml);
         };
         if ($@) {
-            print STDERR "Record $i is bad; skipping\n";
+            warn("Record $i is bad: $@; skipping.");
             next;
         }
     }