add error handling for reading morphology update
[scpubgit/stemmatology.git] / lib / Text / Tradition / Collation / Reading / WordForm.pm
index 4335857..9d27181 100644 (file)
@@ -3,6 +3,8 @@ package Text::Tradition::Collation::Reading::WordForm;
 use Lingua::Features::Structure;
 use JSON ();
 use Moose;
+use Text::Tradition::Error;
+use TryCatch;
 
 =head1 NAME
 
@@ -68,10 +70,14 @@ around BUILDARGS => sub {
        my $class = shift;
        my $args = @_ == 1 ? $_[0] : { @_ };
        if( exists $args->{'JSON'} ) {
-               $DB::single = 1;
                my @data = split( / \/\/ /, $args->{'JSON'} );
-               print STDERR "Attempting to parse " . $data[2] . " into structure";
-               my $morph = Lingua::Features::Structure->from_string( $data[2] );
+               # print STDERR "Attempting to parse " . $data[2] . " into structure";
+               my $morph;
+               try {
+                       $morph = Lingua::Features::Structure->from_string( $data[2] );
+               } catch {
+                       throw("Could not parse string " . $data[2] . " into morphological structure");
+               }
                $args = { 'language' => $data[0], 'lemma' => $data[1],
                        'morphology' => $morph };
        }
@@ -98,6 +104,13 @@ sub TO_JSON {
                $self->morphology->to_string() );
 }
        
+sub throw {
+       Text::Tradition::Error->throw( 
+               'ident' => 'Wordform error',
+               'message' => $_[0],
+               );
+}
+
 no Moose;
 __PACKAGE__->meta->make_immutable;