LP#1528596: Add another eval/warning check in marc_export.
authorJason Stephenson <jstephenson@mvlc.org>
Tue, 22 Dec 2015 14:11:55 +0000 (09:11 -0500)
committerBen Shum <ben@evergreener.net>
Mon, 1 Feb 2016 07:13:30 +0000 (02:13 -0500)
This one checks if the $marc->insert_grouped_field for adding items
throws an error or warning.  This happened on my records with a bad
field that somehow made it through the conversion from XML.

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

index f894e57..6e0face 100755 (executable)
@@ -470,7 +470,13 @@ sub next {
                         next unless ($acp);
                         my $location = $Marque::config->option_value('location');
                         my $price = ($acp->price() ? $Marque::config->option_value('money').$acp->price() : '');
-                        $marc->insert_grouped_field(
+                        eval {
+                            local $SIG{__WARN__} = sub {
+                                my $message = "Warning from bibliographic record " . $r->id() . ": "
+                                    . shift;
+                                warn($message);
+                            };
+                            $marc->insert_grouped_field(
                             MARC::Field->new(
                                 '852', '4', ' ',
                                 ($location ? ('a' => $location) : ()),
@@ -487,6 +493,12 @@ sub next {
                                 (!$U->is_true($acp->circulate()) ? (x => 'noncirculating') : ()),
                                 (!$U->is_true($acp->opac_visible()) ? (x => 'hidden') : ())
                             ));
+                        };
+                        if ($@) {
+                            warn("Error in bibliographic record " . $r->id() . ": $@");
+                            import MARC::File::XML; # Reset SAX Parser.
+                            return $self->next();
+                        }
                     }
                 }
                 if ($Marque::config->option_value('mfhd')) {