Commits

Shlomi Fish  committed a1d6568

Handling warnings better.

This way the error message is less obscure. There's some duplicate code
with XML-Grammar-Fiction-App-FromProto.

  • Participants
  • Parent commits c0e9a15

Comments (0)

Files changed (1)

File perl/modules/XML-Grammar-Fiction/lib/XML/Grammar/Screenplay/App/FromProto.pm

         parser_class => "XML::Grammar::Screenplay::FromProto::Parser::QnD",
     });
 
-    my $output_xml = $converter->convert({
-            source => { file => shift(@ARGV), },
+    eval
+    {
+        my $output_xml = $converter->convert({
+                source => { file => shift(@ARGV), },
+            }
+        );
+
+        open my $out, ">", $output_filename;
+        binmode $out, ":utf8";
+        print {$out} $output_xml;
+        close($out);
+    };
+
+    my $e;
+    if ($e = Exception::Class->caught("XML::Grammar::Fiction::Err::Parse::TagsMismatch"))
+    {
+        warn $e->error(), "\n";
+        warn "Open: ", $e->opening_tag->name(),
+            " at line ", $e->opening_tag->line(), "\n"
+            ;
+        warn "Close: ",
+            $e->closing_tag->name(), " at line ",
+            $e->closing_tag->line(), "\n";
+
+        exit(-1);
+    }
+    elsif ($e = Exception::Class->caught("XML::Grammar::Fiction::Err::Parse::LineError"))
+    {
+        warn $e->error(), "\n";
+        warn "At line ", $e->line(), "\n";
+        exit(-1);
+    }
+    elsif ($e = Exception::Class->caught())
+    {
+        if (ref($e))
+        {
+            $e->rethrow();
         }
-    );
-
-    open my $out, ">", $output_filename;
-    binmode $out, ":utf8";
-    print {$out} $output_xml;
-    close($out);
+        else
+        {
+            die $e;
+        }
+    }
 
     exit(0);
 }