From 3e6159b6f15f2d96fba5e56488eeb1179af8ba76 Mon Sep 17 00:00:00 2001 From: Frank Lichtenheld Date: Thu, 6 Dec 2007 03:24:08 +0100 Subject: [PATCH] Dpkg::Changelog: Fix error handling Especially format string handling was very inconsistent before. --- scripts/Dpkg/Changelog.pm | 24 +++++++++--------- scripts/Dpkg/Changelog/Debian.pm | 43 ++++++++++++++++---------------- 2 files changed, 33 insertions(+), 34 deletions(-) diff --git a/scripts/Dpkg/Changelog.pm b/scripts/Dpkg/Changelog.pm index a1cb87a2..1f1e0f63 100644 --- a/scripts/Dpkg/Changelog.pm +++ b/scripts/Dpkg/Changelog.pm @@ -39,7 +39,7 @@ use English; use Dpkg; use Dpkg::Gettext; -use Dpkg::ErrorHandling; +use Dpkg::ErrorHandling qw(warning report); use base qw(Exporter); @@ -160,9 +160,9 @@ sub get_parse_errors { my $res = ""; foreach my $e (@{$self->{errors}{parser}}) { if ($e->[3]) { - $res .= warning(_g("%s(l%s): %s\nLINE: %s"), @$e ); + $res .= report(_g('warning'),_g("%s(l%s): %s\nLINE: %s"), @$e ); } else { - $res .= warning(_g("%s(l%s): %s"), @$e ); + $res .= report(_g('warning'),_g("%s(l%s): %s"), @$e ); } } return $res; @@ -170,10 +170,10 @@ sub get_parse_errors { } sub _do_fatal_error { - my ($self, @msg) = @_; + my ($self, $msg, @msg) = @_; - $self->{errors}{fatal} = "@msg"; - warning(_g("FATAL: %s"), "@msg")."\n" unless $self->{config}{quiet}; + $self->{errors}{fatal} = report(_g('fatal error'), $msg, @msg); + warning($msg, @msg) unless $self->{config}{quiet}; } =pod @@ -592,12 +592,12 @@ sub data2rfc822 { my $v= $data->{$f} or next; $v =~ m/\S/o || next; # delete whitespace-only fields $v =~ m/\n\S/o - && warning(_g("field %s has newline then non whitespace >%s<", - $f, $v )); - $v =~ m/\n[ \t]*\n/o && warning(_g("field %s has blank lines >%s<", - $f, $v )); - $v =~ m/\n$/o && warning(_g("field %s has trailing newline >%s<", - $f, $v )); + && warning(_g("field %s has newline then non whitespace >%s<"), + $f, $v); + $v =~ m/\n[ \t]*\n/o && warning(_g("field %s has blank lines >%s<"), + $f, $v); + $v =~ m/\n$/o && warning(_g("field %s has trailing newline >%s<"), + $f, $v); $v =~ s/\$\{\}/\$/go; $rfc822_str .= "$f: $v\n"; } diff --git a/scripts/Dpkg/Changelog/Debian.pm b/scripts/Dpkg/Changelog/Debian.pm index 7cfd0ace..752214b4 100644 --- a/scripts/Dpkg/Changelog/Debian.pm +++ b/scripts/Dpkg/Changelog/Debian.pm @@ -67,7 +67,6 @@ use Date::Parse; use Dpkg; use Dpkg::Gettext; -use Dpkg::ErrorHandling; use Dpkg::Changelog qw( :util ); use base qw(Dpkg::Changelog); @@ -136,8 +135,8 @@ sub parse { unless ($expect eq 'first heading' || $expect eq 'next heading or eof') { $entry->{ERROR} = [ $file, $NR, - _g( "found start of entry where expected %s", - $expect ), "$_" ]; + sprintf(_g("found start of entry where expected %s"), + $expect), "$_" ]; $self->_do_parse_error(@{$entry->{ERROR}}); } unless ($entry->is_empty) { @@ -160,15 +159,15 @@ sub parse { for my $kv (split(/\s*,\s*/,$rhs)) { $kv =~ m/^([-0-9a-z]+)\=\s*(.*\S)$/i || $self->_do_parse_error($file, $NR, - _g( "bad key-value after \`;': \`%s'", $kv )); + sprintf(_g("bad key-value after \`;': \`%s'"), $kv)); my $k = ucfirst $1; my $v = $2; $kvdone{$k}++ && $self->_do_parse_error($file, $NR, - _g( "repeated key-value %s", $k )); + sprintf(_g("repeated key-value %s"), $k)); if ($k eq 'Urgency') { $v =~ m/^([-0-9a-z]+)((\s+.*)?)$/i || $self->_do_parse_error($file, $NR, - _g( "badly formatted urgency value" ), + _g("badly formatted urgency value"), $v); $entry->{'Urgency'} = "$1"; $entry->{'Urgency_LC'} = lc("$1"); @@ -179,7 +178,7 @@ sub parse { $entry->{$k}= $v; } else { $self->_do_parse_error($file, $NR, - _g( "unknown key-value key %s - copying to XS-%s", $k, $k )); + sprintf(_g("unknown key-value key %s - copying to XS-%s"), $k, $k)); $entry->{ExtraFields}{"XS-$k"} = $v; } } @@ -210,12 +209,12 @@ sub parse { $self->{oldformat} .= join "", <$fh>; } elsif (m/^\S/) { $self->_do_parse_error($file, $NR, - _g( "badly formatted heading line" ), "$_"); + _g("badly formatted heading line"), "$_"); } elsif (m/^ \-\- (.*) <(.*)>( ?)((\w+\,\s*)?\d{1,2}\s+\w+\s+\d{4}\s+\d{1,2}:\d\d:\d\d\s+[-+]\d{4}(\s+\([^\\\(\)]\))?)$/o) { $expect eq 'more change data or trailer' || $self->_do_parse_error($file, $NR, - _g( "found trailer where expected %s", - $expect ), "$_"); + sprintf(_g("found trailer where expected %s"), + $expect), "$_"); if ($3 ne ' ') { $self->_do_parse_error($file, $NR, _g( "badly formatted trailer line" ), @@ -228,8 +227,8 @@ sub parse { $entry->{'Timestamp'} = str2time($4); unless (defined $entry->{'Timestamp'}) { $self->_do_parse_error( $file, $NR, - _g( "couldn't parse date %s", - "$4" ) ); + sprintf(_g("couldn't parse date %s"), + "$4")); } } $expect = 'next heading or eof'; @@ -244,8 +243,8 @@ sub parse { || $expect eq 'more change data or trailer' || do { $self->_do_parse_error($file, $NR, - _g( "found change data where expected %s", - $expect ), "$_"); + sprintf(_g("found change data where expected %s"), + $expect), "$_"); if (($expect eq 'next heading or eof') && !$entry->is_empty) { # lets assume we have missed the actual header line @@ -259,8 +258,8 @@ sub parse { $entry->{Version} = 'unknown'.($unknowncounter++); $entry->{Urgency_Comment} = ''; $entry->{ERROR} = [ $file, $NR, - _g( "found change data where expected %s", - $expect ), "$_" ]; + sprintf(_g("found change data where expected %s"), + $expect), "$_" ]; } }; $entry->{'Changes'} .= (" \n" x $blanklines)." $_\n"; @@ -277,8 +276,8 @@ sub parse { || $expect eq 'next heading or eof'; $expect eq 'more change data or trailer' || $self->_do_parse_error($file, $NR, - _g( "found blank line where expected %s", - $expect )); + sprintf(_g("found blank line where expected %s"), + $expect)); $blanklines++; } else { $self->_do_parse_error($file, $NR, _g( "unrecognised line" ), @@ -305,8 +304,8 @@ sub parse { $expect eq 'next heading or eof' || do { $entry->{ERROR} = [ $file, $NR, - _g( "found eof where expected %s", - $expect ) ]; + sprintf(_g("found eof where expected %s"), + $expect) ]; $self->_do_parse_error( @{$entry->{ERROR}} ); }; unless ($entry->is_empty) { @@ -316,8 +315,8 @@ sub parse { if ($self->{config}{infile}) { close $fh or do { - $self->_do_fatal_error( _g( "can't close file %s: %s", - $file, $! )); + $self->_do_fatal_error( _g("can't close file %s: %s"), + $file, $!); return undef; }; } -- 2.39.5