Fixed proper error reporting if MySQL --store fails.
authorshort <>
Sun, 28 Nov 2004 08:14:53 +0000 (08:14 +0000)
committershort <>
Sun, 28 Nov 2004 08:14:53 +0000 (08:14 +0000)
perlmail-submit

index 4711b74..cc76cca 100755 (executable)
@@ -230,16 +230,32 @@ my($keyword,$interval)=@_;
                }
 }
 
                }
 }
 
+my $optwrap_err;
+sub optwrap
+{
+my($func,@args)=@_;
+
+       # Prevent successful return due to --forkoff in the case of failed --store when using:
+       # perlmail-submit --store --forkoff --submit
+       if (!eval { &{$func}(@args); 1; }) {
+               $optwrap_err||=$@||$!;
+               die "!FINISH";
+               die "NOTREACHED";
+               }
+}
 
 $Getopt::Long::ignorecase=0;
 
 $Getopt::Long::ignorecase=0;
-die if !GetOptions(
-                 "initdb" ,\&initdb,
-                 "store"  ,\&store,
-                 "forkoff",\&forkoff,
-                 "submit" ,\&submit,
-                 "pending",\&pending,
-                 "dump"   ,\&dump,
-                 "clean:s",\&clean,
+# &GetOptions will return success due to: die "!FINISH"
+# but our error detection is done by $optwrap_err.
+GetOptions(
+                 "initdb" ,sub { optwrap \&initdb,@_; },
+                 "store"  ,sub { optwrap \&store,@_; },
+                 "forkoff",sub { optwrap \&forkoff,@_; },
+                 "submit" ,sub { optwrap \&submit,@_; },
+                 "pending",sub { optwrap \&pending,@_; },
+                 "dump"   ,sub { optwrap \&dump,@_; },
+                 "clean:s",sub { optwrap \&clean,@_; },
                "V|version",sub { print "perlmail-submit: $VERSION\n"; exit 0; },
                );
                "V|version",sub { print "perlmail-submit: $VERSION\n"; exit 0; },
                );
+die $optwrap_err if defined $optwrap_err;
 exit 0;
 exit 0;