IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Feb 17, 2010, 5:36:13 PM (16 years ago)
Author:
Paul Price
Message:

Being better about errors and their mapping to exit codes.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/ppSub/src/ppSub.c

    r26899 r26982  
    2424int main(int argc, char *argv[])
    2525{
    26 
    27 # if 0
    2826    psLibInit(NULL);
    29     pmVisualSetVisual(true);
    30     for (int order = 2; order < 11; order ++) {
    31         pmSubtractionDeconvolutionTest (order);
    32     }
    33     psLibFinalize();
    34     exit (1);
    35 # endif
    36 
    37     psExit exitValue = PS_EXIT_SUCCESS; // Exit value
    3827    psTimerStart("ppSub");
    39     psLibInit(NULL);
    4028
    4129    ppSubData *data = NULL;             // Processing data
    4230    pmConfig *config = pmConfigRead(&argc, argv, PPSUB_RECIPE); // Configuration
    4331    if (!config) {
    44         psErrorStackPrint(stderr, "Error reading configuration.");
    45         exitValue = PS_EXIT_CONFIG_ERROR;
    4632        goto die;
    4733    }
     
    5036
    5137    if (!pmModelClassInit()) {
    52         psErrorStackPrint(stderr, "Error initialising model classes.\n");
    53         exitValue = PS_EXIT_PROG_ERROR;
     38        psError(PPSUB_ERR_PROG, false, "Unable to initialise model classes.");
    5439        psFree(config);
    5540        goto die;
     
    5742
    5843    if (!psphotInit()) {
    59         psErrorStackPrint(stderr, "Error initialising psphot.\n");
    60         exitValue = PS_EXIT_PROG_ERROR;
     44        psError(PPSUB_ERR_PROG, false, "Error initialising psphot.");
    6145        psFree(config);
    6246        goto die;
     
    6650
    6751    if (!ppSubArguments(argc, argv, data)) {
    68         psErrorStackPrint(stderr, "Error reading arguments.\n");
    69         exitValue = PS_EXIT_CONFIG_ERROR;
     52        psError(PPSUB_ERR_ARGUMENTS, false, "Error reading arguments.");
    7053        goto die;
    7154    }
    7255
    7356    if (!ppSubCamera(data)) {
    74         psErrorStackPrint(stderr, "Error setting up camera.\n");
    75         exitValue = PS_EXIT_CONFIG_ERROR;
    7657        goto die;
    7758    }
    7859
    7960    if (!ppSubLoop(data)) {
    80         psErrorStackPrint(stderr, "Error performing subtraction.\n");
    81         exitValue = PS_EXIT_SYS_ERROR;
    8261        goto die;
    8362    }
     
    8766    psTimerStop();
    8867
    89     psString dump_file = psMetadataLookupStr(NULL, data->config->arguments, "-dumpconfig");
    90     if (dump_file) {
    91         if (!pmConfigDump(data->config, dump_file)) {
    92             psErrorStackPrint(stderr, "Unable to dump configuration.\n");
    93             exitValue = PS_EXIT_SYS_ERROR;
     68    if (data) {
     69        psString dump_file = psMetadataLookupStr(NULL, data->config->arguments, "-dumpconfig");
     70        if (dump_file) {
     71            if (!pmConfigDump(data->config, dump_file)) {
     72                psError(PPSUB_ERR_IO, false, "Unable to dump configuration.");
     73            }
    9474        }
     75        psFree(data);
    9576    }
    96     psFree(data);
    9777
    9878    pmVisualClose(); //close plot windows, if -visual is set
     
    10181    psLibFinalize();
    10282
     83    psExit exitValue = PS_EXIT_SUCCESS;        // Exit value for program
     84    psErrorCode errorCode = psErrorCodeLast(); // Error code
     85    if (errorCode != PS_ERR_NONE) {
     86        psErrorStackPrint(stderr, "Unable to perform subtraction.");
     87        switch (errorCode) {
     88          case PPSUB_ERR_UNKNOWN:
     89          case PS_ERR_UNKNOWN:
     90            exitValue = PS_EXIT_UNKNOWN_ERROR;
     91            break;
     92          case PS_ERR_IO:
     93          case PS_ERR_DB_CLIENT:
     94          case PS_ERR_DB_SERVER:
     95          case PS_ERR_BAD_FITS:
     96          case PS_ERR_OS_CALL_FAILED:
     97          case PPSUB_ERR_IO:
     98            exitValue = PS_EXIT_SYS_ERROR;
     99            break;
     100          case PS_ERR_BAD_PARAMETER_VALUE:
     101          case PS_ERR_BAD_PARAMETER_TYPE:
     102          case PS_ERR_BAD_PARAMETER_NULL:
     103          case PS_ERR_BAD_PARAMETER_SIZE:
     104          case PPSUB_ERR_ARGUMENTS:
     105          case PPSUB_ERR_CONFIG:
     106            exitValue = PS_EXIT_CONFIG_ERROR;
     107            break;
     108          case PPSUB_ERR_DATA:
     109          case PPSUB_ERR_NO_OVERLAP:
     110            exitValue = PS_EXIT_DATA_ERROR;
     111            break;
     112          case PS_ERR_UNEXPECTED_NULL:
     113          case PS_ERR_PROGRAMMING:
     114          case PPSUB_ERR_NOT_IMPLEMENTED:
     115          case PPSUB_ERR_PROG:
     116          default:
     117            // It's a programming error if we're not dealing with the error correctly
     118            exitValue = PS_EXIT_PROG_ERROR;
     119            break;
     120        }
     121    }
     122
    103123    exit(exitValue);
    104124}
Note: See TracChangeset for help on using the changeset viewer.