Index: trunk/ppStack/src/ppStackLoop.c
===================================================================
--- trunk/ppStack/src/ppStackLoop.c	(revision 26117)
+++ trunk/ppStack/src/ppStackLoop.c	(revision 27004)
@@ -22,5 +22,5 @@
     psTrace("ppStack", 1, "Setup....\n");
     if (!ppStackSetup(options, config)) {
-        psError(PS_ERR_UNKNOWN, false, "Unable to setup.");
+        psError(psErrorCodeLast(), false, "Unable to setup.");
         psFree(options);
         return false;
@@ -33,5 +33,5 @@
     psTrace("ppStack", 1, "Preparation for stacking: merging sources, determining target PSF....\n");
     if (!ppStackPrepare(options, config)) {
-        psError(PS_ERR_UNKNOWN, false, "Unable to prepare for stacking.");
+        psError(psErrorCodeLast(), false, "Unable to prepare for stacking.");
         psFree(options);
         return false;
@@ -45,5 +45,5 @@
     psTrace("ppStack", 1, "Convolving inputs to target PSF....\n");
     if (!ppStackConvolve(options, config)) {
-        psError(PS_ERR_UNKNOWN, false, "Unable to convolve images.");
+        psError(psErrorCodeLast(), false, "Unable to convolve images.");
         psFree(options);
         return false;
@@ -58,5 +58,5 @@
     ppStackThreadData *stack = ppStackThreadDataSetup(options, config, true);
     if (!stack) {
-        psError(PS_ERR_IO, false, "Unable to initialise stack threads.");
+        psError(psErrorCodeLast(), false, "Unable to initialise stack threads.");
         psFree(options);
         return false;
@@ -65,5 +65,5 @@
     // Prepare for combination
     if (!ppStackCombinePrepare(stack, options, config)) {
-        psError(PS_ERR_UNKNOWN, false, "Unable to prepare for combination.");
+        psError(psErrorCodeLast(), false, "Unable to prepare for combination.");
         psFree(stack);
         psFree(options);
@@ -74,5 +74,5 @@
     psTrace("ppStack", 1, "Initial stack of convolved images....\n");
     if (!ppStackCombineInitial(stack, options, config)) {
-        psError(PS_ERR_UNKNOWN, false, "Unable to perform initial combination.");
+        psError(psErrorCodeLast(), false, "Unable to perform initial combination.");
         psFree(stack);
         psFree(options);
@@ -86,5 +86,5 @@
     psTrace("ppStack", 1, "Reject pixels....\n");
     if (!ppStackReject(options, config)) {
-        psError(PS_ERR_UNKNOWN, false, "Unable to reject pixels.");
+        psError(psErrorCodeLast(), false, "Unable to reject pixels.");
         psFree(stack);
         psFree(options);
@@ -98,5 +98,5 @@
     psTrace("ppStack", 2, "Final stack of convolved images....\n");
     if (!ppStackCombineFinal(options->outRO, stack, options->convCovars, options, config, false, false)) {
-        psError(PS_ERR_UNKNOWN, false, "Unable to perform final combination.");
+        psError(psErrorCodeLast(), false, "Unable to perform final combination.");
         psFree(stack);
         psFree(options);
@@ -109,5 +109,5 @@
     psTrace("ppStack", 2, "Cleaning up after combination....\n");
     if (!ppStackCleanup(stack, options, config)) {
-        psError(PS_ERR_UNKNOWN, false, "Unable to clean up.");
+        psError(psErrorCodeLast(), false, "Unable to clean up.");
         psFree(stack);
         psFree(options);
@@ -125,5 +125,5 @@
         ppStackThreadData *stack = ppStackThreadDataSetup(options, config, false);
         if (!stack) {
-            psError(PS_ERR_IO, false, "Unable to initialise stack threads.");
+            psError(psErrorCodeLast(), false, "Unable to initialise stack threads.");
             psFree(options);
             return false;
@@ -131,5 +131,5 @@
         psTrace("ppStack", 2, "Stack of unconvolved images....\n");
         if (!ppStackCombineFinal(options->unconvRO, stack, options->origCovars, options, config, false, true)) {
-            psError(PS_ERR_UNKNOWN, false, "Unable to perform unconvolved combination.");
+            psError(psErrorCodeLast(), false, "Unable to perform unconvolved combination.");
             psFree(stack);
             psFree(options);
@@ -147,5 +147,5 @@
     psTrace("ppStack", 1, "Photometering stacked image....\n");
     if (!ppStackPhotometry(options, config)) {
-        psError(PS_ERR_UNKNOWN, false, "Unable to perform photometry.");
+        psError(psErrorCodeLast(), false, "Unable to perform photometry.");
         psFree(options);
         return false;
@@ -157,5 +157,5 @@
     psTrace("ppStack", 1, "Finishing up....\n");
     if (!ppStackFinish(options, config)) {
-        psError(PS_ERR_UNKNOWN, false, "Unable to finish up.");
+        psError(psErrorCodeLast(), false, "Unable to finish up.");
         psFree(options);
         return false;
