Index: trunk/psModules/src/config/pmConfig.c
===================================================================
--- trunk/psModules/src/config/pmConfig.c	(revision 27060)
+++ trunk/psModules/src/config/pmConfig.c	(revision 27083)
@@ -178,5 +178,5 @@
         char *envName = envStart + 1;   // Start of the environment variable name
         if (envName[0] == '\0') {
-            psError(PS_ERR_BAD_PARAMETER_VALUE, true, "Path %s contains a bad environment variable.\n", dir);
+            psError(PM_ERR_CONFIG, true, "Path %s contains a bad environment variable.\n", dir);
             return NULL;
         }
@@ -184,5 +184,5 @@
             envName++;
             if (envName[0] == '\0') {
-                psError(PS_ERR_BAD_PARAMETER_VALUE, true,
+                psError(PM_ERR_CONFIG, true,
                         "Path %s contains a bad environment variable.\n", dir);
                 return NULL;
@@ -276,5 +276,5 @@
 
     if (configPath == NULL) {
-        psError(PS_ERR_IO, true, "Cannot find %s configuration file (%s) in path\n", description, name);
+        psError(PM_ERR_CONFIG, true, "Cannot find %s configuration file (%s) in path\n", description, name);
         return false;
     }
@@ -300,5 +300,5 @@
     }
 
-    psError(PS_ERR_IO, true, "Cannot find %s configuration file %s in path\n", description, name);
+    psError(PM_ERR_CONFIG, true, "Cannot find %s configuration file %s in path\n", description, name);
     return false;
 
@@ -306,5 +306,5 @@
     *config = psMetadataConfigRead(NULL, &numBadLines, realName, true);
     if (numBadLines > 0) {
-        psError(PS_ERR_IO, false, "%d bad lines in %s configuration file (%s)",
+        psError(PM_ERR_CONFIG, false, "%d bad lines in %s configuration file (%s)",
                 numBadLines, description, realName);
         psFree (realName);
@@ -313,5 +313,5 @@
     }
     if (!*config) {
-        psError(PS_ERR_IO, true, "Unable to read %s configuration from %s",
+        psError(PM_ERR_CONFIG, true, "Unable to read %s configuration from %s",
                 description, realName);
         psFree (realName);
@@ -332,5 +332,5 @@
     }
     if (item->type != PS_DATA_STRING) {
-        psTrace("config", 2, "Element %s in %s metadata is not of type STR.\n",
+        psError(PM_ERR_CONFIG, true, "Element %s in %s metadata is not of type STR.\n",
                 item->name, description);
         return false;
@@ -340,5 +340,5 @@
     psMetadata *new = NULL;         // New metadata
     if (!pmConfigFileRead(&new, item->data.str, item->name)) {
-        psError(PM_ERR_CONFIG, false, "Trouble reading reading %s %s.\n",
+        psError(psErrorCodeLast(), false, "Trouble reading reading %s %s.\n",
                 description, item->name);
         psFree(new);
@@ -365,5 +365,5 @@
     while ((item = psMetadataGetAndIncrement(iter))) {
         if (!pmConfigFileIngest(item, description)) {
-            psError(PM_ERR_CONFIG, false, "Unable to read %s %s.", description, item->name);
+            psError(psErrorCodeLast(), false, "Unable to read %s %s.", description, item->name);
             psFree(iter);
             return false;
@@ -386,9 +386,9 @@
     psMetadata *formats = psMetadataLookupMetadata(&mdok, camera, "FORMATS"); // Formats
     if (!mdok || !formats) {
-        psError(PS_ERR_UNEXPECTED_NULL, true, "Unable to find FORMATS in camera configuration %s.\n", name);
+        psError(PM_ERR_CONFIG, true, "Unable to find FORMATS in camera configuration %s.\n", name);
         return false;
     }
     if (!metadataReadFiles(formats, "camera format")) {
-        psError(PS_ERR_UNKNOWN, false, "Unable to read formats within camera configuration %s.\n", name);
+        psError(psErrorCodeLast(), false, "Unable to read formats within camera configuration %s.\n", name);
         return false;
     }
@@ -490,10 +490,10 @@
     psMetadataItem *siteItem = psMetadataLookup(config->user, "SITE");
     if (!siteItem) {
-        psError(PS_ERR_BAD_PARAMETER_VALUE, true, "Unable to find SITE in user configuration.");
+        psError(PM_ERR_CONFIG, true, "Unable to find SITE in user configuration.");
         psFree(config);
         return NULL;
     }
     if (!pmConfigFileIngest(siteItem, "site configuration")) {
-        psError(PS_ERR_UNKNOWN, false, "Unable to read site configuration");
+        psError(psErrorCodeLast(), false, "Unable to read site configuration");
         psFree(config);
         return NULL;
@@ -504,10 +504,10 @@
     psMetadataItem *systemItem = psMetadataLookup(config->user, "SYSTEM");
     if (!systemItem) {
-        psError(PS_ERR_BAD_PARAMETER_VALUE, true, "Unable to find SYSTEM in user configuration.");
+        psError(PM_ERR_CONFIG, true, "Unable to find SYSTEM in user configuration.");
         psFree(config);
         return NULL;
     }
     if (!pmConfigFileIngest(systemItem, "system configuration")) {
-        psError(PS_ERR_UNKNOWN, false, "Unable to read system configuration");
+        psError(psErrorCodeLast(), false, "Unable to read system configuration");
         psFree(config);
         return NULL;
@@ -665,5 +665,6 @@
                 seed = strtoll(argv[argNum], &end, 0);
                 if (strlen(end) > 0) {
-                    psError(PS_ERR_IO, true, "Unable to read random number generator seed: %s", argv[argNum]);
+                    psError(PM_ERR_CONFIG, true, "Unable to read random number generator seed: %s",
+                            argv[argNum]);
                     psFree(config);
                     return NULL;
@@ -690,5 +691,5 @@
             psMetadata *cameras = psMetadataLookupMetadata(&mdok, config->system, "CAMERAS");
             if (!cameras) {
-                psError(PS_ERR_IO, false, "Unable to find CAMERAS in site configuration.\n");
+                psError(PM_ERR_CONFIG, false, "Unable to find CAMERAS in site configuration.\n");
                 psFree(config);
                 return NULL;
@@ -698,5 +699,5 @@
             char *cameraFile = psMetadataLookupStr(&mdok, cameras, cameraName); // The filename
             if (!cameraFile) {
-                psError(PS_ERR_IO, false, "%s is not listed in the site CAMERAS list\n", cameraName);
+                psError(PM_ERR_CONFIG, false, "%s is not listed in the site CAMERAS list\n", cameraName);
                 psFree(config);
                 return NULL;
@@ -705,5 +706,5 @@
             // load this camera's configuration informatoin
             if (!pmConfigFileRead(&config->camera, cameraFile, "camera")) {
-                psError(PM_ERR_CONFIG, false, "Problem reading %s", cameraName);
+                psError(psErrorCodeLast(), false, "Problem reading %s", cameraName);
                 psFree(config);
                 return NULL;
@@ -716,5 +717,5 @@
             // Read in the formats
             if (!cameraReadFormats(config->camera, cameraFile)) {
-                psError(PS_ERR_UNKNOWN, false, "Unable to read formats within camera configuration %s.\n",
+                psError(psErrorCodeLast(), false, "Unable to read formats within camera configuration %s.\n",
                         cameraFile);
                 psFree(config);
@@ -724,5 +725,5 @@
             // Read in any camera-specific calibrations
             if (!cameraReadCalibrations(config->camera, cameraName)) {
-                psError(PS_ERR_UNKNOWN, false,
+                psError(psErrorCodeLast(), false,
                         "Unable to read calibrations within camera configuration %s.\n",
                         cameraName);
@@ -735,5 +736,5 @@
 
             if (!pmConfigCameraSkycellVersion(config->system, cameraName)) {
-                psError(PS_ERR_UNKNOWN, false,
+                psError(psErrorCodeLast(), false,
                         "Unable to generate skycell versions of specified camera %s.\n",
                         cameraName);
@@ -743,5 +744,5 @@
 
             if (!pmConfigCameraMosaickedVersions(config->system, cameraName)) {
-                psError(PS_ERR_UNKNOWN, false,
+                psError(psErrorCodeLast(), false,
                         "Unable to generate mosaicked versions of specified camera %s.\n",
                         cameraName);
@@ -757,10 +758,10 @@
         psMetadata *cameras = psMetadataLookupMetadata(&mdok, config->system, "CAMERAS"); // List of cameras
         if (!mdok || !cameras) {
-            psError(PS_ERR_UNEXPECTED_NULL, true, "Unable to find CAMERAS in the system configuration.\n");
+            psError(PM_ERR_CONFIG, true, "Unable to find CAMERAS in the system configuration.\n");
             return false;
         }
 
         if (!metadataReadFiles(cameras, "camera configuration")) {
-            psError(PS_ERR_UNKNOWN, false, "Unable to read cameras within system configuration.\n");
+            psError(psErrorCodeLast(), false, "Unable to read cameras within system configuration.\n");
             psFree(config);
             return NULL;
@@ -790,10 +791,10 @@
 
         if (!pmConfigCameraSkycellVersionsAll(config->system)) {
-            psError(PS_ERR_UNKNOWN, false, "Unable to generate skycell versions of cameras.\n");
+            psError(psErrorCodeLast(), false, "Unable to generate skycell versions of cameras.\n");
             psFree(config);
             return NULL;
         }
         if (!pmConfigCameraMosaickedVersionsAll(config->system)) {
-            psError(PS_ERR_UNKNOWN, false, "Unable to generate mosaicked versions of cameras.\n");
+            psError(psErrorCodeLast(), false, "Unable to generate mosaicked versions of cameras.\n");
             psFree(config);
             return NULL;
@@ -803,5 +804,5 @@
     // Load the recipes from the camera file, if appropriate
     if(!pmConfigReadRecipes(config, PM_RECIPE_SOURCE_SYSTEM | PM_RECIPE_SOURCE_CAMERA)) {
-        psError(PS_ERR_IO, false, "Failed to read recipes from camera file");
+        psError(psErrorCodeLast(), false, "Failed to read recipes from camera file");
         psFree(config);
         return NULL;
@@ -818,5 +819,5 @@
 
     if (!pmConfigReadRecipes(config, PM_RECIPE_SOURCE_CL)) {
-        psError(PS_ERR_IO, false, "Failed to read recipes from command-line");
+        psError(psErrorCodeLast(), false, "Failed to read recipes from command-line");
         psFree(config);
         return NULL;
@@ -827,5 +828,5 @@
         psArgumentRemove(argNum, argc, argv);
         if (argNum + 1 >= *argc) {
-            psError(PS_ERR_BAD_PARAMETER_SIZE, true,
+            psError(PM_ERR_CONFIG, true,
                     "Filerule switch (-F) provided without old and new filerule.");
             psFree(config);
@@ -840,5 +841,5 @@
         psMetadata *cameras = psMetadataLookupMetadata(NULL, config->system, "CAMERAS"); // List of cameras
         if (!cameras) {
-            psError(PS_ERR_UNEXPECTED_NULL, false, "Unable to find CAMERAS in the site configuration.\n");
+            psError(PM_ERR_CONFIG, false, "Unable to find CAMERAS in the site configuration.\n");
             return false;
         }
@@ -1001,5 +1002,5 @@
     psMetadata *rule = psMetadataLookupMetadata(&mdStatus, cameraFormat, "RULE");
     if (! mdStatus || ! rule) {
-        psError(PS_ERR_UNKNOWN, false, "Unable to read rule for camera.");
+        psError(PM_ERR_CONFIG, false, "Unable to read rule for camera.");
         *valid = false;
         return false;
@@ -1010,5 +1011,5 @@
     psArray *keys = psListToArray (keyList);
     if (! keys) {
-        psError(PS_ERR_UNKNOWN, false, "Unable to read rule for camera.");
+        psError(PM_ERR_CONFIG, false, "Unable to read rule for camera.");
         *valid = false;
         return false;
@@ -1059,5 +1060,5 @@
         }
 
-        psError(PS_ERR_UNKNOWN, false, "Invalid type for RULE %s.", ruleItem->name);
+        psError(PM_ERR_CONFIG, false, "Invalid type for RULE %s.", ruleItem->name);
         *valid = false;
         psFree (keyList);
@@ -1094,5 +1095,5 @@
     psMetadata *formats = psMetadataLookupMetadata(&mdok, camera, "FORMATS"); // List of formats
     if (!mdok || !formats) {
-        psError(PS_ERR_UNKNOWN, false, "Unable to find list of FORMATS in camera %s", cameraName);
+        psError(PM_ERR_CONFIG, false, "Unable to find list of FORMATS in camera %s", cameraName);
         *status = false;
         return false;
@@ -1100,5 +1101,5 @@
 
     if (!metadataReadFiles(formats, "camera format")) {
-        psError(PS_ERR_UNKNOWN, false, "Unable to read cameras formats within camera configuration.\n");
+        psError(psErrorCodeLast(), false, "Unable to read cameras formats within camera configuration.\n");
         *status = false;
         return false;
@@ -1116,5 +1117,5 @@
         bool valid = false;
         if (!pmConfigValidateCameraFormat(&valid, testFormat, header)) {
-            psError (PS_ERR_UNKNOWN, false, "Error in config scripts for camera %s, format %s\n",
+            psError (psErrorCodeLast(), false, "Error in config scripts for camera %s, format %s\n",
                      cameraName, formatsItem->name);
             *status = false;
@@ -1162,10 +1163,10 @@
         psMetadata *cameras = psMetadataLookupMetadata(&mdok, config->system, "CAMERAS");
         if (! mdok || !cameras) {
-            psError(PS_ERR_IO, true, "Unable to find CAMERAS in the configuration.");
+            psError(PM_ERR_CONFIG, true, "Unable to find CAMERAS in the configuration.");
             return NULL;
         }
 
         if (!metadataReadFiles(cameras, "camera configuration")) {
-            psError(PS_ERR_UNKNOWN, false, "Unable to read cameras within site configuration.\n");
+            psError(psErrorCodeLast(), false, "Unable to read cameras within site configuration.\n");
             return NULL;
         }
@@ -1196,5 +1197,6 @@
             } else {
                 if (!status) {
-                    psError(PS_ERR_IO, false, "Error reading camera config data for %s", camerasItem->name);
+                    psError(psErrorCodeLast(), false, "Error reading camera config data for %s",
+                            camerasItem->name);
                     return NULL;
                 }
@@ -1205,5 +1207,5 @@
         // Done looking at all cameras
         if (!config->camera) {
-            psError(PS_ERR_IO, false, "Unable to find a camera that matches input FITS header!");
+            psError(PM_ERR_CONFIG, true, "Unable to find a camera that matches input FITS header!");
             return NULL;
         }
@@ -1211,5 +1213,6 @@
         // Now we have the camera, we can read the recipes
         if (readRecipes && !pmConfigReadRecipes(config, PM_RECIPE_SOURCE_CAMERA | PM_RECIPE_SOURCE_CL)) {
-            psError(PS_ERR_IO, false, "Error reading recipes from camera config for %s", config->cameraName);
+            psError(psErrorCodeLast(), false, "Error reading recipes from camera config for %s",
+                    config->cameraName);
             return NULL;
         }
@@ -1287,6 +1290,7 @@
 
     if (!found) {
-        psError(PS_ERR_IO, true, "Unable to find a format with the specified camera (%s) that matches the "
-                "given header.\n", baseName);
+        psError(PM_ERR_CONFIG, true,
+                "Unable to find a format with the specified camera (%s) that matches the given header.",
+                baseName);
         psFree (baseName);
         return NULL;
@@ -1319,5 +1323,5 @@
     psMetadata *cameras = psMetadataLookupMetadata(NULL, config->system, "CAMERAS");
     if (!cameras) {
-        psError(PS_ERR_IO, true, "Unable to find CAMERAS in the configuration.");
+        psError(PM_ERR_CONFIG, true, "Unable to find CAMERAS in the configuration.");
         return NULL;
     }
@@ -1325,5 +1329,5 @@
     psMetadataItem *item = psMetadataLookup(cameras, cameraName); // Item with camera of interest
     if (!pmConfigFileIngest(item, "camera configuration")) {
-        psError(PS_ERR_UNKNOWN, false, "Unable to ingest camera configuration.");
+        psError(psErrorCodeLast(), false, "Unable to ingest camera configuration.");
         return NULL;
     }
@@ -1341,5 +1345,5 @@
         item = psMetadataLookup(config->site, name);
         if (!item) {
-            psError(PS_ERR_BAD_PARAMETER_VALUE, true,
+            psError(PM_ERR_CONFIG, true,
                     "Unable to find %s in user or site configuration", name);
             return NULL;
@@ -1347,5 +1351,5 @@
     }
     if (item->type != type) {
-        psError(PS_ERR_BAD_PARAMETER_TYPE, true,
+        psError(PM_ERR_CONFIG, true,
                 "Type of %s (%x) in user/site configuration does not match expected (%x)",
                 name, item->type, type);
@@ -1364,5 +1368,5 @@
 #ifndef HAVE_PSDB
 
-    psError(PS_ERR_UNKNOWN, false,
+    psError(PM_ERR_PROG, false,
             "Cannot configure database: psModules was compiled without database support.");
     return NULL;
@@ -1413,5 +1417,5 @@
     psMetadata *rules = psMetadataLookupMetadata(&mdok, format, "RULE"); // How to identify this format
     if (!mdok || !rules) {
-        psError(PS_ERR_IO, true, "Unable to find RULE in camera format.\n");
+        psError(PM_ERR_CONFIG, true, "Unable to find RULE in camera format.\n");
         return false;
     }
@@ -1421,5 +1425,5 @@
     while ((rulesItem = psMetadataGetAndIncrement(rulesIter))) {
         if (!PS_DATA_IS_PRIMITIVE(rulesItem->type) && rulesItem->type != PS_DATA_STRING) {
-            psError(PS_ERR_UNKNOWN, false, "Invalid type for RULE %s.", rulesItem->name);
+            psError(PM_ERR_CONFIG, false, "Invalid type for RULE %s.", rulesItem->name);
             return false;
         }
@@ -1453,5 +1457,5 @@
           case PS_METADATA_ITEM_COMPARE_OP_NE:
             // It's not at all obvious what the value should be, so return an error.
-            psError(PS_ERR_IO, true,
+            psError(PM_ERR_CONFIG, true,
                     "RULE %s (defined by an OPeration) is not present or not consistent in output header",
                     rulesItem->name);
@@ -1536,5 +1540,5 @@
               default:
                 // rigid format, no comments allowed?
-                psError(PS_ERR_BAD_PARAMETER_VALUE, true, "Unable to parse file list: spaces detected.");
+                psError(PM_ERR_CONFIG, true, "Unable to parse file list: spaces detected.");
                 psFree(input);
                 fclose(f);
@@ -1569,5 +1573,5 @@
     if (!files) {
         psAbort("error parsing argument list");
-        psError(PS_ERR_IO, false, "error parsing argument list");
+        psError(psErrorCodeLast(), false, "error parsing argument list");
         psFree (files);
         return false;
@@ -1624,5 +1628,5 @@
         psMetadata *datapath = psMetadataLookupPtr (NULL, config->site, "DATAPATH");
         if (datapath == NULL) {
-            psError(PS_ERR_UNKNOWN, true, "DATAPATH is not defined in config.site");
+            psError(PM_ERR_CONFIG, true, "DATAPATH is not defined in config.site");
             psFree (newName);
             return NULL;
@@ -1632,5 +1636,5 @@
         char *mark = strchr (point, '/');
         if (mark == NULL) {
-            psError(PS_ERR_UNKNOWN, true, "syntax error in PATH-style name %s", newName);
+            psError(PM_ERR_CONFIG, true, "syntax error in PATH-style name %s", newName);
             psFree (newName);
             return false;
@@ -1640,5 +1644,5 @@
         char *realpath = psMetadataLookupStr (NULL, datapath, path);
         if (realpath == NULL) {
-            psError(PS_ERR_UNKNOWN, true,
+            psError(PM_ERR_CONFIG, true,
                     "path (%s) not defined in config.site:DATAPATH for PATH-style name %s",
                     path, newName);
@@ -1656,5 +1660,5 @@
         if (!checkPath(newName, create, trunc)) {
             // let checkPath()'s psError() call float up
-            psError(PS_ERR_UNKNOWN, false, "error from checkPath for path:// (%s)", newName);
+            psError(psErrorCodeLast(), false, "error from checkPath for path:// (%s)", newName);
             psFree (newName);
             return NULL;
@@ -1747,5 +1751,5 @@
     psMetadataItem *item = psMetadataLookup(camera, "FILERULES"); // Item with the file rule of interest
     if (!item) {
-        psError(PS_ERR_UNEXPECTED_NULL, false, "Unable to find FILERULES in the camera configuration.");
+        psError(PM_ERR_CONFIG, false, "Unable to find FILERULES in the camera configuration.");
         return NULL;
     }
@@ -1780,5 +1784,5 @@
     psMetadataItem *item = psMetadataLookup(camera, "FITSTYPES"); // Item with the file rule of interest
     if (!item) {
-        psError(PS_ERR_UNEXPECTED_NULL, false, "Unable to find FITSTYPES in the camera configuration.");
+        psError(PM_ERR_CONFIG, false, "Unable to find FITSTYPES in the camera configuration.");
         return NULL;
     }
