Index: trunk/ippScripts/scripts/magic_destreak.pl
===================================================================
--- trunk/ippScripts/scripts/magic_destreak.pl	(revision 21435)
+++ trunk/ippScripts/scripts/magic_destreak.pl	(revision 22430)
@@ -26,4 +26,13 @@
 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 $magicdstool   = can_run('magicdstool') or (warn "Can't find magicdstool" and $missing_tools = 1);
+my $streaksremove = can_run('streaksremove') or (warn "Can't find streaksremove" and $missing_tools = 1);
+if ($missing_tools) {
+    warn("Can't find required tools.");
+    exit($PS_EXIT_CONFIG_ERROR);
+}
 
 # Parse the command-line arguments
@@ -66,5 +75,9 @@
     defined $component and
     defined $outroot;
-    
+
+# 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], $magic_ds_id, $component, $PS_EXIT_UNKNOWN_ERROR ); };
+
 
 my ($skycell_args, $class_id, $skycell_id);
@@ -87,13 +100,4 @@
 
 
-# Look for programs we need
-my $missing_tools;
-my $magicdstool   = can_run('magicdstool') or (warn "Can't find magicdstool" and $missing_tools = 1);
-my $streaksremove = can_run('streaksremove') or (warn "Can't find streaksremove" and $missing_tools = 1);
-if ($missing_tools) {
-    warn("Can't find required tools.");
-    exit($PS_EXIT_CONFIG_ERROR);
-}
-
 my $mdcParser = PS::IPP::Metadata::Config->new; # Parser for metadata config files
 
@@ -128,5 +132,5 @@
     if (! -e $outroot ) {
         my $code = system "mkdir -p $outroot";
-        &my_die("cannot create output directory $outroot", $magic_ds_id, $component, 
+        &my_die("cannot create output directory $outroot", $magic_ds_id, $component,
                 $code >> 8) if $code;
     }
@@ -143,5 +147,5 @@
         if (! -e $recoveryroot ) {
             my $code = system "mkdir -p $recoveryroot";
-            &my_die("cannot create output directory $outroot", $magic_ds_id, $component, 
+            &my_die("cannot create output directory $outroot", $magic_ds_id, $component,
                     $code >> 8) if $code;
         }
@@ -151,5 +155,5 @@
 
 # get skycell list if needed
-my ($sfh, $skycell_list);          
+my ($sfh, $skycell_list);
 if ($skycell_args) {
     my $command = "$magicdstool -magic_ds_id $magic_ds_id -getskycells $skycell_args";
