Index: trunk/ippScripts/scripts/chip_imfile.pl
===================================================================
--- trunk/ippScripts/scripts/chip_imfile.pl	(revision 21371)
+++ trunk/ippScripts/scripts/chip_imfile.pl	(revision 22430)
@@ -25,4 +25,15 @@
 use Getopt::Long qw( GetOptions :config auto_help auto_version gnu_getopt );
 use Pod::Usage qw( pod2usage );
+
+# Look for programs we need
+my $missing_tools;
+my $chiptool = can_run('chiptool') or (warn "Can't find chiptool" and $missing_tools = 1);
+my $ppImage = can_run('ppImage') or (warn "Can't find ppImage" and $missing_tools = 1);
+my $ppConfigDump = can_run('ppConfigDump') or (warn "Can't find ppConfigDump" and $missing_tools = 1);
+my $ppStatsFromMetadata = can_run('ppStatsFromMetadata') or (warn "Can't find ppStatsFromMetadata" and $missing_tools = 1);
+if ($missing_tools) {
+    warn("Can't find required tools.");
+    exit($PS_EXIT_CONFIG_ERROR);
+}
 
 # Parse the command-line arguments
@@ -53,9 +64,13 @@
     defined $chip_id and
     defined $class_id and
-    defined $chip_imfile_id and 
+    defined $chip_imfile_id and
     defined $uri and
     defined $camera and
     defined $outroot and
     defined $run_state;
+
+# Unhandled exceptions should be passed on to my_die so they get pushed into the database
+$SIG{__DIE__} = sub { die @_ if $^S;
+                      my_die( $_[0], $exp_id, $chip_id, $class_id, $PS_EXIT_UNKNOWN_ERROR ); };
 
 $ipprc->define_camera($camera);
@@ -69,15 +84,4 @@
     print STDOUT "Starting script $0 on $host\n\n";
     print STDOUT "COMMAND IS: @ARGV\n\n";
-}
-
-# Look for programs we need
-my $missing_tools;
-my $chiptool = can_run('chiptool') or (warn "Can't find chiptool" and $missing_tools = 1);
-my $ppImage = can_run('ppImage') or (warn "Can't find ppImage" and $missing_tools = 1);
-my $ppConfigDump = can_run('ppConfigDump') or (warn "Can't find ppConfigDump" and $missing_tools = 1);
-my $ppStatsFromMetadata = can_run('ppStatsFromMetadata') or (warn "Can't find ppStatsFromMetadata" and $missing_tools = 1);
-if ($missing_tools) {
-    warn("Can't find required tools.");
-    exit($PS_EXIT_CONFIG_ERROR);
 }
 
@@ -132,6 +136,6 @@
         $command .= " -threads $threads" if defined $threads;
         $command .= " -dbname $dbname" if defined $dbname;
-	$command .= " -image_id $chip_imfile_id" if defined $chip_imfile_id;
-	$command .= " -source_id $source_id" if defined $source_id;
+        $command .= " -image_id $chip_imfile_id" if defined $chip_imfile_id;
+        $command .= " -source_id $source_id" if defined $source_id;
         $command .= " -dumpconfig $configuration";
         $command .= " -tracedest $traceDest -log $logDest";
@@ -142,6 +146,6 @@
         $command .= " -threads $threads" if defined $threads;
         $command .= " -dbname $dbname" if defined $dbname;
-	$command .= " -image_id $chip_imfile_id" if defined $chip_imfile_id;
-	$command .= " -source_id $source_id" if defined $source_id;
+        $command .= " -image_id $chip_imfile_id" if defined $chip_imfile_id;
+        $command .= " -source_id $source_id" if defined $source_id;
         $command .= " -tracedest $traceDest -log $logDest";
         $command .= " -Db PPIMAGE:PHOTOM FALSE";
