]> mj.ucw.cz Git - temple.git/commitdiff
Avoid reporting a single error multiple times
authorMartin Mares <mj@ucw.cz>
Fri, 12 Oct 2012 20:58:29 +0000 (22:58 +0200)
committerMartin Mares <mj@ucw.cz>
Fri, 12 Oct 2012 20:58:29 +0000 (22:58 +0200)
One day, we might want to get a proper backtrace, but in the meantime
it is easier to avoid wrapping a single error in several layers of
line number info, which are often wrong, as we do not clear the position
stack in error paths.

UCW/Temple.pm

index 98aea96d9077860e5333925e8c235afd9822df75..e1a21e305b3a032a2aed33b726f7f86a9e7d8de7 100644 (file)
@@ -32,10 +32,11 @@ sub add_depend($) {
 my $current_file_name;
 my $current_string;
 my $current_pos;
+my $reported_error;
 
 sub error($;$) {
        my ($msg, $offset) = @_;
-       if (defined $current_file_name) {
+       if (defined $current_file_name && !$reported_error) {
                #
                #  This is rather tricky. We want to report the exact place, where the error
                #  occurred, but the cost of keeping track of the current line number is too high.
@@ -45,6 +46,7 @@ sub error($;$) {
                my $input = substr(${$current_string}, 0, $current_pos);
                my @newlines = ($input =~ m{\n}g);
                my $line = @newlines + ($offset // 1);
+               $reported_error++;
                die "$current_file_name:$line: $msg\n";
        } else {
                die "$msg\n";
@@ -184,6 +186,7 @@ sub parse_file($) {
 sub start(;$) {
        $arguments = $_[0];
        @cond = (1);
+       $reported_error = 0;
 }
 
 sub finish() {