IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Apr 14, 2010, 3:53:21 PM (16 years ago)
Author:
rhenders
Message:

Improved error handling, specifically, now using standard IPP exit codes

File:
1 edited

Legend:

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

    r27433 r27684  
    1818#include "ippToPsps.h"
    1919
    20 extern bool ippToPsps_batchInit(IppToPsps *data);
    21 extern bool ippToPsps_batchDetection(IppToPsps *data);
    22 extern bool ippToPsps_batchStack(IppToPsps *data);
    23 extern bool ippToPsps_batchDifference(IppToPsps *data);
     20extern int ippToPsps_batchInit(IppToPsps *data);
     21extern int ippToPsps_batchDetection(IppToPsps *data);
     22extern int ippToPsps_batchStack(IppToPsps *data);
     23extern int ippToPsps_batchDifference(IppToPsps *data);
    2424
    2525// Destructor
    2626static void ippToPsps_Destructor(IppToPsps* this) {
    2727
    28     // if unsuccessful, then delete FITS file
    29     if (!this->success) {
    30 
    31         psError(PS_ERR_UNKNOWN, false, "Failed, so deleting %s", this->fitsOutPath);
    32 
    33         // if process failed, we need to delete that FITS file
    34         if (remove(this->fitsOutPath) == -1) {
    35 
    36             psError(PS_ERR_UNKNOWN, false, "Unable to delete %s", this->fitsOutPath);
    37         }
    38     }
    39     // ...otherwise, close file
    40     else {
    41 
    42         int status = 0;
    43         if (fits_close_file(this->fitsOut, &status)) {
    44 
    45             psError(PS_ERR_IO, false, "Unable to close FITS file %s", this->fitsOutPath);
    46             fits_report_error(stderr, status);
     28    // if we created an output file...
     29    if (this->fitsOut) {
     30
     31        // if unsuccessful, then delete FITS file
     32        if (this->exitCode != PS_EXIT_SUCCESS) {
     33
     34            psError(PS_ERR_UNKNOWN, false, "Failed, so deleting %s", this->fitsOutPath);
     35
     36            // if process failed, we need to delete that FITS file
     37            if (remove(this->fitsOutPath) == -1) {
     38
     39                psError(PS_ERR_UNKNOWN, false, "Unable to delete %s", this->fitsOutPath);
     40            }
     41        }
     42        // ...otherwise, close file
     43        else {
     44
     45            int status = 0;
     46            if (fits_close_file(this->fitsOut, &status)) {
     47
     48                psError(PS_ERR_IO, false, "Unable to close FITS file %s", this->fitsOutPath);
     49                fits_report_error(stderr, status);
     50            }
    4751        }
    4852    }
     
    7781
    7882        psError(PS_ERR_UNKNOWN, false, "Unable to open file at %s", this->fitsInPath);
    79         return NULL;
     83        return false;
    8084    }
    8185
     
    188192
    189193// Runs the requested process
    190 static bool ippToPsps_run(IppToPsps *this) {
    191 
    192     // which product?
    193     switch(this->product) {
    194 
    195         case PRODUCT_INIT:
    196             this->success = ippToPsps_batchInit(this);
    197             break;
    198         case PRODUCT_DETECTION:
    199             this->success = ippToPsps_batchDetection(this);
    200             break;
    201         case PRODUCT_STACK:
    202             this->success = ippToPsps_batchStack(this);
    203             break;
    204         case PRODUCT_DIFFERENCE:
    205             this->success = ippToPsps_batchDifference(this);
    206             break;
    207         default:
    208             psError(PS_ERR_UNKNOWN, false, "Unable to run for this product type (%d)", this->product);
    209             this->success = false;
    210             break;
    211     }
    212 
    213     return this->success;
     194static int ippToPsps_run(IppToPsps *this) {
     195
     196    if(this->exitCode == PS_EXIT_SUCCESS) {
     197
     198        // which product?
     199        switch(this->product) {
     200
     201            case PRODUCT_INIT:
     202                this->exitCode = ippToPsps_batchInit(this);
     203                break;
     204            case PRODUCT_DETECTION:
     205                this->exitCode = ippToPsps_batchDetection(this);
     206                break;
     207            case PRODUCT_STACK:
     208                this->exitCode = ippToPsps_batchStack(this);
     209                break;
     210            case PRODUCT_DIFFERENCE:
     211                this->exitCode = ippToPsps_batchDifference(this);
     212                break;
     213            default:
     214                psError(PS_ERR_UNKNOWN, false, "Unable to run for this product type (%d)", this->product);
     215                this->exitCode = false;
     216                break;
     217        }
     218    }
     219
     220    return this->exitCode;
    214221}
    215222
     
    236243    this->dvoConfig = dvoConfigRead(argc, argv);
    237244    this->pmconfig = pmConfigRead(argc, argv, NULL);
    238     this->success = false;
     245    this->exitCode = PS_EXIT_SUCCESS;
    239246    this->run = ippToPsps_run;
    240247
     
    242249
    243250        psError(PS_ERR_UNKNOWN, false, "Unable to read configuration.");
    244         return NULL;
     251        this->exitCode = PS_EXIT_CONFIG_ERROR;
     252        return this;
    245253    }
    246254
     
    248256
    249257        psFree(this);
    250         return NULL;
    251     }
    252 
    253     if (this->product != PRODUCT_INIT && !ippToPsps_readInputFilePaths(this)) return NULL;
     258        this->exitCode = PS_EXIT_CONFIG_ERROR;
     259        return this;
     260    }
     261
     262    if (this->product != PRODUCT_INIT && !ippToPsps_readInputFilePaths(this)) {
     263
     264        this->exitCode = PS_EXIT_DATA_ERROR;
     265        return this;
     266    }
    254267
    255268    if (this->product == PRODUCT_INIT)
     
    272285        fits_report_error(stderr, status);
    273286        psError(PS_ERR_IO, false, "Unable to create file at: '%s'", this->fitsOutPath);
    274         return NULL;
     287        this->exitCode = PS_EXIT_SYS_ERROR;
     288        return this;
    275289    }
    276290
    277291    this->config = ippToPspsConfig_Constructor(this->configsDir);
    278     if (this->config == NULL) return NULL;
     292    if (this->config == NULL) {
     293
     294        this->exitCode = PS_EXIT_CONFIG_ERROR;
     295        return this;
     296    }
    279297
    280298    // ready results file, if necessary
Note: See TracChangeset for help on using the changeset viewer.