LP 1528596: Add another eval/warning check in marc_export. user/dyrcona/lp1528596_another_marc_export_warning
authorJason Stephenson <jstephenson@mvlc.org>
Tue, 22 Dec 2015 14:11:55 +0000 (09:11 -0500)
committerJason Stephenson <jstephenson@mvlc.org>
Tue, 22 Dec 2015 14:48:46 +0000 (09:48 -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>
Open-ILS/src/support-scripts/marc_export.in

index 5b5ff9c..9f24aa7 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')) {