LP 1350345: marc_export blows up on bad records.
authorJason Stephenson <jstephenson@mvlc.org>
Wed, 30 Jul 2014 13:26:38 +0000 (09:26 -0400)
committerBen Shum <bshum@biblio.org>
Thu, 18 Sep 2014 20:21:58 +0000 (16:21 -0400)
Add some eval blocks around calls to MARC::Record->as_usmarc and
MARC::Record->as_xml_record to trap errors in bibliograpic and
authority records.

If MARC::Record reports an error, print the record id and the
error message and continue the export.

Signed-off-by: Jason Stephenson <jstephenson@mvlc.org>
Signed-off-by: Ben Shum <bshum@biblio.org>
Open-ILS/src/support-scripts/marc_export.in

index 7f24a3d..348c4b3 100755 (executable)
@@ -509,10 +509,24 @@ sub next {
             }
         }
         if ($Marque::config->option_value('format') eq 'XML') {
-            $output = $marc->as_xml_record;
-            $output =~ s/^<\?.+?\?>$//mo;
+            eval {
+                $output = $marc->as_xml_record;
+                $output =~ s/^<\?.+?\?>$//mo;
+            };
+            if ($@) {
+                print STDERR "Error in bibliograpic record " . $r->id() . "\n";
+                print STDERR "$@\n";
+                return $self->next();
+            }
         } else {
-            $output = $marc->as_usmarc;
+            eval {
+                $output = $marc->as_usmarc;
+            };
+            if ($@) {
+                print STDERR "Error in bibliograpic record " . $r->id() . "\n";
+                print STDERR "$@\n";
+                return $self->next();
+            }
         }
     }
     return $output;
@@ -755,10 +769,24 @@ sub next {
                 }
             }
             if ($Marque::config->option_value('format') eq 'XML') {
-                $output = $r->as_xml_record;
-                $output =~ s/^<\?.+?\?>$//mo;
+                eval {
+                    $output = $r->as_xml_record;
+                    $output =~ s/^<\?.+?\?>$//mo;
+                };
+                if ($@) {
+                    print STDERR "Error in authority record " . $r->id() . "\n";
+                    print STDERR "$@\n";
+                    return $self->next();
+                }
             } else {
-                $output = $r->as_usmarc;
+                eval {
+                    $output = $r->as_usmarc;
+                };
+                if ($@) {
+                    print STDERR "Error in authority record " . $r->id() . "\n";
+                    print STDERR "$@\n";
+                    return $self->next();
+                }
             }
         }
     }