die if cannot open output or exception files
[migration-tools.git] / fingerprinter
index 93df981..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 )