Ver código fonte

Properly use internerr to report about programming bugs

Use internerr for internal error conditions which happen only due to
programming bugs and should never occur, otherwise the code is wrong
and should be fixed.
Guillem Jover 17 anos atrás
pai
commit
cb30ab1729

+ 23 - 0
ChangeLog

@@ -1,3 +1,26 @@
+2008-12-08  Guillem Jover  <guillem@debian.org>
+
+	* dpkg-deb/build.c (do_build): Use internerr instead of ohshit. Do not
+	mark the string for translation.
+	* src/trigcmd.c (do_check): Use internerr instead of abort.
+	* lib/dump.c (w_status): Likewise.
+	* lib/triglib.c (trig_incorporate): Likewise. Remove <stdlib.h>
+	include.
+	* scripts/Dpkg/IPC.pm (_sanity_check_opts): Use internerr instead of
+	error.
+	(fork_and_exec): Likewise. Do not mark the string for translation.
+	(wait_child): Likewise.
+	* scripts/Dpkg/Source/Archive.pm: Use internerr instead of error from
+	Dpkg::ErrorHandling.
+	(_add_entry, add_file, add_directory): Likewise.
+	* scripts/Dpkg/Source/CompressedFile.pm: Likewise.
+	(get_filename): Likewise.
+	* scripts/Dpkg/Source/Compressor.pm: Likewise.
+	(_sanity_check): Likewise.
+	* scripts/Dpkg/Source/Package.p (do_extract, do_build): Likewise.
+	* scripts/Dpkg/Source/Patch.pm (add_diff_file): Use error instead of
+	internerr.
+
 2008-12-08  Guillem Jover  <guillem@debian.org>
 2008-12-08  Guillem Jover  <guillem@debian.org>
 
 
 	* lib/dpkg.h (do_internerr): Reorder arguments. Support format
 	* lib/dpkg.h (do_internerr): Reorder arguments. Support format

+ 1 - 0
debian/changelog

@@ -37,6 +37,7 @@ dpkg (1.15.0) UNRELEASED; urgency=low
   * Mark program names in dpkg-trigger.1 in bold.
   * Mark program names in dpkg-trigger.1 in bold.
   * Unmark dselect debug messages for translation.
   * Unmark dselect debug messages for translation.
   * Use a the warning function to uniformly print all warning messages.
   * Use a the warning function to uniformly print all warning messages.
+  * Properly use internerr to report about programming bugs.
 
 
   [ Raphael Hertzog ]
   [ Raphael Hertzog ]
   * Enhance dpkg-shlibdeps's error message when a library can't be found to
   * Enhance dpkg-shlibdeps's error message when a library can't be found to

+ 1 - 1
dpkg-deb/build.c

@@ -491,7 +491,7 @@ void do_build(const char *const *argv) {
       datamember = DATAMEMBER_CAT;
       datamember = DATAMEMBER_CAT;
       break;
       break;
     default:
     default:
-      ohshit(_("Internal error, compress_type `%i' unknown!"), compress_type);
+      internerr("unkown compress_type '%i'", compress_type);
     }
     }
     if (fstat(gzfd, &datastab))
     if (fstat(gzfd, &datastab))
       ohshite(_("failed to fstat tmpfile (data)"));
       ohshite(_("failed to fstat tmpfile (data)"));

+ 1 - 1
lib/dump.c

@@ -195,7 +195,7 @@ void w_status(struct varbuf *vb,
     assert(!AW);
     assert(!AW);
     break;
     break;
   default:
   default:
-    abort();
+    internerr("unknown package status '%d'", pigp->status);
   }
   }
 #undef PEND
 #undef PEND
 #undef AW
 #undef AW

+ 1 - 2
lib/triglib.c

@@ -26,7 +26,6 @@
 #include <dpkg-i18n.h>
 #include <dpkg-i18n.h>
 
 
 #include <assert.h>
 #include <assert.h>
-#include <stdlib.h>
 #include <unistd.h>
 #include <unistd.h>
 #include <errno.h>
 #include <errno.h>
 
 
@@ -755,7 +754,7 @@ trig_incorporate(enum modstatdb_rw cstatus, const char *admindir)
 		trigdef_yylex();
 		trigdef_yylex();
 		break;
 		break;
 	default:
 	default:
-		abort();
+		internerr("unknown trigdef_update_start return value '%d'", ur);
 	}
 	}
 
 
 	/* Right, that's it. New (empty) Unincorp can be installed. */
 	/* Right, that's it. New (empty) Unincorp can be installed. */

+ 9 - 9
scripts/Dpkg/IPC.pm

@@ -128,7 +128,7 @@ listed in the array before calling exec.
 sub _sanity_check_opts {
 sub _sanity_check_opts {
     my (%opts) = @_;
     my (%opts) = @_;
 
 
-    error("exec parameter is mandatory in fork_and_exec()")
+    internerr("exec parameter is mandatory in fork_and_exec()")
 	unless $opts{"exec"};
 	unless $opts{"exec"};
 
 
     my $to = my $error_to = my $from = 0;
     my $to = my $error_to = my $from = 0;
@@ -137,11 +137,11 @@ sub _sanity_check_opts {
 	$error_to++ if $opts{"error_to_$_"};
 	$error_to++ if $opts{"error_to_$_"};
 	$from++ if $opts{"from_$_"};
 	$from++ if $opts{"from_$_"};
     }
     }
-    error("not more than one of to_* parameters is allowed")
+    internerr("not more than one of to_* parameters is allowed")
 	if $to > 1;
 	if $to > 1;
-    error("not more than one of error_to_* parameters is allowed")
+    internerr("not more than one of error_to_* parameters is allowed")
 	if $error_to > 1;
 	if $error_to > 1;
-    error("not more than one of from_* parameters is allowed")
+    internerr("not more than one of from_* parameters is allowed")
 	if $from > 1;
 	if $from > 1;
 
 
     foreach (qw(to_string error_to_string from_string
     foreach (qw(to_string error_to_string from_string
@@ -149,16 +149,16 @@ sub _sanity_check_opts {
     {
     {
 	if (exists $opts{$_} and
 	if (exists $opts{$_} and
 	    (!ref($opts{$_}) or ref($opts{$_}) ne 'SCALAR')) {
 	    (!ref($opts{$_}) or ref($opts{$_}) ne 'SCALAR')) {
-	    error("parameter $_ must be a scalar reference");
+	    internerr("parameter $_ must be a scalar reference");
 	}
 	}
     }
     }
 
 
     if (exists $opts{"env"} and ref($opts{"env"}) ne 'HASH') {
     if (exists $opts{"env"} and ref($opts{"env"}) ne 'HASH') {
-	error("parameter env must be a hash reference");
+	internerr("parameter env must be a hash reference");
     }
     }
 
 
     if (exists $opts{"delete_env"} and ref($opts{"delete_env"}) ne 'ARRAY') {
     if (exists $opts{"delete_env"} and ref($opts{"delete_env"}) ne 'ARRAY') {
-	error("parameter delete_env must be an array reference");
+	internerr("parameter delete_env must be an array reference");
     }
     }
 
 
     return %opts;
     return %opts;
@@ -173,7 +173,7 @@ sub fork_and_exec {
     } elsif (not ref($opts{"exec"})) {
     } elsif (not ref($opts{"exec"})) {
 	push @prog, $opts{"exec"};
 	push @prog, $opts{"exec"};
     } else {
     } else {
-	error(_g("invalid exec parameter in fork_and_exec()"));
+	internerr("invalid exec parameter in fork_and_exec()");
     }
     }
     my ($from_string_pipe, $to_string_pipe, $error_to_string_pipe);
     my ($from_string_pipe, $to_string_pipe, $error_to_string_pipe);
     if ($opts{"to_string"}) {
     if ($opts{"to_string"}) {
@@ -308,7 +308,7 @@ non-zero return code).
 sub wait_child {
 sub wait_child {
     my ($pid, %opts) = @_;
     my ($pid, %opts) = @_;
     $opts{"cmdline"} ||= _g("child process");
     $opts{"cmdline"} ||= _g("child process");
-    error(_g("no PID set, cannot wait end of process")) unless $pid;
+    internerr("no PID set, cannot wait end of process") unless $pid;
     $pid == waitpid($pid, 0) or syserr(_g("wait for %s"), $opts{"cmdline"});
     $pid == waitpid($pid, 0) or syserr(_g("wait for %s"), $opts{"cmdline"});
     unless ($opts{"nocheck"}) {
     unless ($opts{"nocheck"}) {
 	subprocerr($opts{"cmdline"}) if $?;
 	subprocerr($opts{"cmdline"}) if $?;

+ 3 - 3
scripts/Dpkg/Source/Archive.pm

@@ -52,7 +52,7 @@ sub create {
 
 
 sub _add_entry {
 sub _add_entry {
     my ($self, $file) = @_;
     my ($self, $file) = @_;
-    error("call create first") unless $self->{"tar_input"};
+    internerr("call create first") unless $self->{"tar_input"};
     $file = $2 if ($file =~ /^\Q$self->{'cwd'}\E\/(.+)$/); # Relative names
     $file = $2 if ($file =~ /^\Q$self->{'cwd'}\E\/(.+)$/); # Relative names
     print({ $self->{'tar_input'} } "$file\0") ||
     print({ $self->{'tar_input'} } "$file\0") ||
 	    syserr(_g("write on tar input"));
 	    syserr(_g("write on tar input"));
@@ -64,7 +64,7 @@ sub add_file {
     if ($self->{"chdir"}) {
     if ($self->{"chdir"}) {
         $testfile = File::Spec->catfile($self->{"chdir"}, $file);
         $testfile = File::Spec->catfile($self->{"chdir"}, $file);
     }
     }
-    error("add_file() doesn't handle directories") if not -l $testfile and -d _;
+    internerr("add_file() doesn't handle directories") if not -l $testfile and -d _;
     $self->_add_entry($file);
     $self->_add_entry($file);
 }
 }
 
 
@@ -74,7 +74,7 @@ sub add_directory {
     if ($self->{"chdir"}) {
     if ($self->{"chdir"}) {
         $testfile = File::Spec->catdir($self->{"chdir"}, $file);
         $testfile = File::Spec->catdir($self->{"chdir"}, $file);
     }
     }
-    error("add_directory() only handles directories") unless not -l $testfile and -d _;
+    internerr("add_directory() only handles directories") unless not -l $testfile and -d _;
     $self->_add_entry($file);
     $self->_add_entry($file);
 }
 }
 
 

+ 2 - 2
scripts/Dpkg/Source/CompressedFile.pm

@@ -83,8 +83,8 @@ sub get_filename {
     my $comp = $self->{"compression"};
     my $comp = $self->{"compression"};
     if ($self->{'add_comp_ext'}) {
     if ($self->{'add_comp_ext'}) {
 	if ($comp eq "auto") {
 	if ($comp eq "auto") {
-	    error("automatic detection of compression is " .
-	          "incompatible with add_comp_ext");
+	    internerr("automatic detection of compression is " .
+	              "incompatible with add_comp_ext");
 	} elsif ($comp eq "none") {
 	} elsif ($comp eq "none") {
 	    return $self->{"filename"};
 	    return $self->{"filename"};
 	} else {
 	} else {

+ 2 - 2
scripts/Dpkg/Source/Compressor.pm

@@ -96,8 +96,8 @@ sub _sanity_check {
         $to++ if $opts{"to_$_"};
         $to++ if $opts{"to_$_"};
         $from++ if $opts{"from_$_"};
         $from++ if $opts{"from_$_"};
     }
     }
-    error("exactly one to_* parameter is needed") if $to != 1;
-    error("exactly one from_* parameter is needed") if $from != 1;
+    internerr("exactly one to_* parameter is needed") if $to != 1;
+    internerr("exactly one from_* parameter is needed") if $from != 1;
     return %opts;
     return %opts;
 }
 }
 
 

+ 4 - 2
scripts/Dpkg/Source/Package.pm

@@ -372,7 +372,8 @@ sub extract {
 }
 }
 
 
 sub do_extract {
 sub do_extract {
-    error("Dpkg::Source::Package doesn't know how to unpack a source package. Use one of the subclasses.");
+    internerr("Dpkg::Source::Package doesn't know how to unpack a " .
+              "source package. Use one of the subclasses.");
 }
 }
 
 
 # Function used specifically during creation of a source package
 # Function used specifically during creation of a source package
@@ -387,7 +388,8 @@ sub build {
 }
 }
 
 
 sub do_build {
 sub do_build {
-    error("Dpkg::Source::Package doesn't know how to build a source package. Use one of the subclasses.");
+    internerr("Dpkg::Source::Package doesn't know how to build a " .
+              "source package. Use one of the subclasses.");
 }
 }
 
 
 sub can_build {
 sub can_build {

+ 1 - 2
scripts/Dpkg/Source/Patch.pm

@@ -111,8 +111,7 @@ sub add_diff_file {
                        "original or modified version)"), $new);
                        "original or modified version)"), $new);
         } else {
         } else {
             chomp;
             chomp;
-            internerr(_g("unknown line from diff -u on %s: `%s'"),
-                      $new, $_);
+            error(_g("unknown line from diff -u on %s: `%s'"), $new, $_);
         }
         }
         print({ $self->{'handle'} } $_) || syserr(_g("failed to write"));
         print({ $self->{'handle'} } $_) || syserr(_g("failed to write"));
     }
     }

+ 1 - 1
src/trigcmd.c

@@ -177,7 +177,7 @@ do_check(void)
 	case -2:
 	case -2:
 		exit(0);
 		exit(0);
 	default:
 	default:
-		abort();
+		internerr("unknown trigdef_update_start return value '%d'", uf);
 	}
 	}
 }
 }