Skip to content

Commit

Permalink
nice error message on broken headers
Browse files Browse the repository at this point in the history
show less cryptic error message when record header is broken
  • Loading branch information
Marc Chantreux committed Jan 19, 2014
1 parent dad92ff commit df8909f
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions lib/MARC/MIR.pm
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use parent 'Exporter';
use autodie;
use Modern::Perl;
use Perlude;
use YAML;
# use Perlude::Sh qw< :all >;

# ABSTRACT: DSL to manipulate MIR records.
Expand Down Expand Up @@ -162,9 +163,12 @@ sub from_iso2709 (_) {
@fields or die "raw $raw";
$head =~ /(.{24})/cg or die;
my $leader = $1;
my @tags = $head =~ /\G(\d{3})\d{9}/cg;
unless ( $head =~ /\G$/cg ) {
die "head tailing ".( $head =~ /(.*)/cg );
my @tags = $head =~ /\G(\d{3})[\d ]{9}/cg;
if ( $head =~ /\G(.+)$/cg ) {
die YAML::Dump
{ "can't parse head" => $head
, "found garbage" => $1
, "at char " => pos($head) };
}
[ $leader
, [ map [ shift(@tags), _field ], @fields ]
Expand Down

0 comments on commit df8909f

Please sign in to comment.