From 09613feb458154665d2e1cff9c8d4d7285ff0c82 Mon Sep 17 00:00:00 2001 From: Martin Mares Date: Fri, 12 Oct 2012 22:58:29 +0200 Subject: [PATCH] Avoid reporting a single error multiple times 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 | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/UCW/Temple.pm b/UCW/Temple.pm index 98aea96..e1a21e3 100644 --- a/UCW/Temple.pm +++ b/UCW/Temple.pm @@ -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() { -- 2.39.5