die if cannot open output or exception files
[migration-tools.git] / fingerprinter
index 8c2b6dc..4318340 100755 (executable)
@@ -16,8 +16,8 @@ $| = 1;
 
 initialize($conf);
 
-open OF, '>', $conf->{output};
-open XF, '>', $conf->{exception};
+open OF, '>', $conf->{output} or die "$0: cannot open output file $conf->{output}: $!\n";
+open XF, '>', $conf->{exception} or die "$0: cannot open exception file $conf->{output}: $!\n";
 
 for my $file (@ARGV) {
     print XF "Processing $file\n";
@@ -27,7 +27,15 @@ for my $file (@ARGV) {
     $batch->strict_off();
     $batch->warnings_off();
 
-    while ( $record = $batch->next ) {
+    my $record;
+    while ( 1 ) {
+        eval { $record = $batch->next; };
+        if ($@) {
+            import MARC::File::XML;
+            print "skipping bad record: $@\n";
+            next;
+        }
+        last unless $record;
         $count++; progress_ticker();
         my $marc = undef;
         unless ( defined $record )
@@ -325,7 +333,7 @@ sub dump_fingerprints {
         }
     }
 
-    if ($conf->{fingerprints}{koha_bib_id}) {
+    if ($conf->{fingerprints}{koha_bib_id} and exists $marc->{koha_bib_id}) {
         print OF join("\t", $marc->{score}, $marc->{id}, "z_koha_bib_id",
                       $marc->{item_form}, $marc->{date1},
                       $marc->{record_type},