do something useful (log) when the eval block horks
[migration-tools.git] / fingerprinter
index 3b7e0ef..9c99ef1 100755 (executable)
@@ -6,6 +6,7 @@ use open ':utf8';
 use Getopt::Long;
 use MARC::Batch;
 use Unicode::Normalize;
+use MARC::File::XML ( BinaryEncoding => 'utf-8' );
 
 my $conf  = {}; # configuration hashref
 my $count = 0;
@@ -29,6 +30,8 @@ for my $file (@ARGV) {
     $batch->warnings_off();
 
     while ( eval { $record = $batch->next } ) {
+        if ($@)
+          { print XF "MARC::Batch error $@"; next }
         my $marc = undef;
         $count++; progress_ticker();
         unless ( defined $record )
@@ -285,19 +288,6 @@ sub initialize {
     # set mode on existing filehandles
     binmode(STDIN, ':utf8');
 
-    # set defaults if told to do so
-    if ($c->{incoming}) {
-        $c->{tag} = 903;
-        $c->{subfield} = 'a';
-        $c->{output} = 'incoming.fp';
-        $c->{exception} = 'incoming.ex';
-    } elsif ($c->{incumbent}) {
-        $c->{tag} = 901;
-        $c->{subfield} = 'c';
-        $c->{output} = 'incumbent.fp';
-        $c->{exception} = 'incumbent.ex';
-    }
-
     my $rc = GetOptions( $c,
                          'incoming',
                          'incumbent',
@@ -312,6 +302,19 @@ sub initialize {
     show_help() unless $rc;
     show_help() if ($c->{help});
 
+    # set defaults if told to do so
+    if ($c->{incoming}) {
+        $c->{tag} = 903 unless defined $c->{tag};
+        $c->{subfield} = 'a' unless defined $c->{subfield};
+        $c->{output} = 'incoming.fp' unless defined $c->{output};
+        $c->{exception} = 'incoming.ex' unless defined $c->{exception};
+    } elsif ($c->{incumbent}) {
+        $c->{tag} = 901 unless defined $c->{tag};
+        $c->{subfield} = 'c' unless defined $c->{subfield};
+        $c->{output} = 'incumbent.fp' unless defined $c->{output};
+        $c->{exception} = 'incumbent.ex' unless defined $c->{exception};
+    }
+
     my @keys = keys %{$c};
     show_help() unless (@ARGV and @keys);
     for my $key ('runtype', 'tag', 'subfield', 'output', 'exception')