Index: /trunk/psphot/src/psphotArguments.c
===================================================================
--- /trunk/psphot/src/psphotArguments.c	(revision 7343)
+++ /trunk/psphot/src/psphotArguments.c	(revision 7344)
@@ -1,9 +1,4 @@
 # include "psphot.h"
 # include <glob.h>
-
-static void usage (void) {
-    fprintf (stderr, "USAGE: psphot [-file image(s)] [-list imagelist] (output)\n");
-    exit (2);
-}
 
 pmConfig *psphotArguments (int *argc, char **argv) {
@@ -12,8 +7,8 @@
     bool status;
 
-    if (*argc == 1) usage ();
-
-    // basic pslib options
-    psLogSetFormat ("M");
+    if (*argc == 1) {
+	psError(PSPHOT_ERR_ARGUMENTS, true, "Too few arguments: %d", *argc);
+	return NULL;
+    }
 
     // these other options override the PSPHOT recipe options
@@ -105,4 +100,10 @@
     pmConfig *config = pmConfigRead(argc, argv);
 
+    if (config == NULL) {
+	psError(PSPHOT_ERR_CONFIG, false, "pmConfigRead returns NULL");
+	psFree(options);
+	return NULL;
+    }
+
     // Storage for other command-line arguments
     config->arguments = psMetadataAlloc ();
@@ -121,8 +122,14 @@
     // the input file is a required argument; if not found, we will exit
     status = pmConfigFileSetsMD (config->arguments, argc, argv, "INPUT", "-file", "-list");
-    if (!status) { usage ();}
+    if (!status) {
+	psError(PSPHOT_ERR_ARGUMENTS, false, "pmConfigFileSetsMD failed to parse arguments");
+	return NULL;
+    }
 
-    if (*argc != 2) usage ();
-
+    if (*argc != 2) {
+	psError(PSPHOT_ERR_ARGUMENTS, true, "Expected to see one more argument; saw %d", *argc - 1);
+	return NULL;
+    }
+    
     // output position is fixed
     psMetadataAddStr (config->arguments, PS_LIST_TAIL, "OUTPUT", 0, "", argv[1]);
