Index: trunk/ippScripts/scripts/magic_process.pl
===================================================================
--- trunk/ippScripts/scripts/magic_process.pl	(revision 29524)
+++ trunk/ippScripts/scripts/magic_process.pl	(revision 29625)
@@ -325,24 +325,4 @@
 }
 
-### Input result into database
-{
-    my $command = "$magictool -addresult";
-    $command   .= " -magic_id $magic_id";
-    $command   .= " -node $node";
-    $command   .= " -path_base $outroot";
-    $command   .= " -dbname $dbname" if defined $dbname;
-
-    # Add the processed file to the database
-    unless ($no_update) {
-        my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
-            run(command => $command, verbose => $verbose);
-        unless ($success) {
-            $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
-            &my_die("Unable to perform magictool -addresult: $error_code", $magic_id, $node, $error_code);
-        }
-    } else {
-        print "Skipping command: $command\n";
-    }
-}
 
 if ($node eq "root") {
@@ -376,4 +356,7 @@
         my $exposures = $mdcParser->parse_list(join "", @$stdout_buf);
         my $exp = $$exposures[0]; # Exposure of interest (should only be one)
+        if (!$exp) {
+            &my_die("magictool -exposure returned no output", $magic_id, $node, $PS_EXIT_UNKNOWN_ERROR);
+        }
 
         $exp_id = $exp->{exp_id};
@@ -429,9 +412,4 @@
             unless ($success) {
                 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
-                # XXX: This my_die isn't going to work because the result for the root node was already
-                # added to the database up above.
-                # There is a magicMask has a fault column. Maybe we should 
-                # use that and add a new revert mode that deletes the magicMask and the magicNodeResult
-                # for the root node.
                 &my_die("Unable to perform magictool -addmask: $error_code", $magic_id, $node, $error_code);
             }
@@ -439,4 +417,27 @@
             print "Skipping command: $command\n";
         }
+    }
+}
+
+    ### Input result into database
+{
+    my $command = "$magictool -addresult";
+    $command   .= " -magic_id $magic_id";
+    $command   .= " -node $node";
+    $command   .= " -path_base $outroot";
+    $command   .= " -dbname $dbname" if defined $dbname;
+
+    # Add the processed file to the database
+    unless ($no_update) {
+        my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
+            run(command => $command, verbose => $verbose);
+        unless ($success) {
+            $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
+            # XXX: if this is the root node we need to revert delete the magicMask object
+            # inserted above
+            &my_die("Unable to perform magictool -addresult: $error_code", $magic_id, $node, $error_code);
+        }
+    } else {
+        print "Skipping command: $command\n";
     }
 }
