Index: trunk/psModules/src/imcombine/pmImageCombine.c
===================================================================
--- trunk/psModules/src/imcombine/pmImageCombine.c	(revision 23975)
+++ trunk/psModules/src/imcombine/pmImageCombine.c	(revision 23989)
@@ -132,4 +132,8 @@
         // Combine all the pixels, using the specified stat.
         if (!psVectorStats(stats, pixelData, pixelErrors, pixelMasks, 0xff)) {
+	    psError(PS_ERR_UNKNOWN, false, "failure to measure stats");
+	    return false;
+	}
+	if (isnan(stats->sampleMean)) {
             combine->data.F32[y][x] = NAN;
             psFree(buffer);
@@ -137,5 +141,5 @@
         }
         float combinedPixel = stats->sampleMean; // Value of the combination
-
+	
         if (iter == 0) {
             // Save the value produced with no rejection, since it may be useful later
@@ -364,5 +368,7 @@
     // Get the median
     psStats *stats = psStatsAlloc(PS_STAT_SAMPLE_MEDIAN);
-    psVectorStats(stats, pixels, NULL, mask, 1);
+    if (!psVectorStats(stats, pixels, NULL, mask, 1)) {
+	psError(PS_ERR_UNKNOWN, false, "failure to measure stats");
+    }
     float median = stats->sampleMedian;
     psFree(stats);
Index: trunk/psModules/src/imcombine/pmReadoutCombine.c
===================================================================
--- trunk/psModules/src/imcombine/pmReadoutCombine.c	(revision 23975)
+++ trunk/psModules/src/imcombine/pmReadoutCombine.c	(revision 23989)
@@ -384,23 +384,27 @@
             // Combination
             if (!psVectorStats(stats, pixels, errors, mask, 1)) {
-                // Can't do much about it, but it's not worth worrying about
-                psErrorClear();
+		psError(PS_ERR_UNKNOWN, false, "error in pixel stats");
+		return false;
+	    }
+	    
+	    outputImage[yOut][xOut] = psStatsGetValue(stats, params->combine);
+
+	    if (isnan(outputImage[yOut][xOut])) {
                 outputImage[yOut][xOut] = NAN;
                 outputMask[yOut][xOut] = params->blank;
+                sigma->data.F32[yOut][xOut] = NAN;
                 if (params->variances) {
                     outputVariance[yOut][xOut] = NAN;
                 }
-                sigma->data.F32[yOut][xOut] = NAN;
-            } else {
-                outputImage[yOut][xOut] = psStatsGetValue(stats, params->combine);
-                outputMask[yOut][xOut] = isfinite(outputImage[yOut][xOut]) ? 0 : params->blank;
-                if (params->variances) {
-                    float stdev = psStatsGetValue(stats, combineStdev);
-                    outputVariance[yOut][xOut] = PS_SQR(stdev); // Variance
-                    // XXXX this is not the correct formal error.
-                    // also, the weighted mean is not obviously the correct thing here
-                }
-                sigma->data.F32[yOut][xOut] = psStatsGetValue(stats, combineStdev);
-            }
+		continue;
+	    }
+	    outputMask[yOut][xOut] = 0;
+	    sigma->data.F32[yOut][xOut] = psStatsGetValue(stats, combineStdev);
+	    if (params->variances) {
+		float stdev = psStatsGetValue(stats, combineStdev);
+		outputVariance[yOut][xOut] = PS_SQR(stdev); // Variance
+		// XXXX this is not the correct formal error.
+		// also, the weighted mean is not obviously the correct thing here
+	    }
         }
     }
Index: trunk/psModules/src/imcombine/pmSubtraction.c
===================================================================
--- trunk/psModules/src/imcombine/pmSubtraction.c	(revision 23975)
+++ trunk/psModules/src/imcombine/pmSubtraction.c	(revision 23989)
@@ -822,4 +822,10 @@
     psFree(mask);
 
+    // XXX raise an error?
+    if (isnan(stats->sampleMean)) {
+        psFree(stats);
+        return -1;
+    }
+
     double mean, rms;                 // Mean and RMS of deviations
     if (numStamps < MIN_SAMPLE_STATS) {
Index: trunk/psModules/src/imcombine/pmSubtractionMatch.c
===================================================================
--- trunk/psModules/src/imcombine/pmSubtractionMatch.c	(revision 23975)
+++ trunk/psModules/src/imcombine/pmSubtractionMatch.c	(revision 23989)
@@ -830,12 +830,14 @@
     psFree(mask);
 
+    // XXX raise an error here or not?
+    if (isnan(stats->robustMedian)) {
+        psFree(stats);
+        return PM_SUBTRACTION_MODE_ERR;
+    }
+
     psLogMsg("psModules.imcombine", PS_LOG_INFO, "Median width ratio: %lf", stats->robustMedian);
     pmSubtractionMode mode = (stats->robustMedian <= 1.0 ? PM_SUBTRACTION_MODE_1 : PM_SUBTRACTION_MODE_2);
     psFree(stats);
 
-    // XXX EAM : I think Paul left some test code in here.  I've commented these lines out
-    // return PM_SUBTRACTION_MODE_2;
-    // exit(1);
-
     return mode;
 }
