IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jan 25, 2007, 7:10:31 PM (19 years ago)
Author:
Paul Price
Message:

Adding error handling; not yet tested --- there may be compilation errors.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/ippScripts/scripts/phase2.pl

    r11298 r11316  
    88use PS::IPP::Metadata::Stats;
    99use Data::Dumper;
    10 use PS::IPP::Config;
     10use PS::IPP::Config qw(
     11    $PS_EXIT_SUCCESS
     12    $PS_EXIT_UNKNOWN_ERROR
     13    $PS_EXIT_SYS_ERROR
     14    $PS_EXIT_CONFIG_ERROR
     15    $PS_EXIT_PROG_ERROR
     16    $PS_EXIT_DATA_ERROR
     17    $PS_EXIT_TIMEOUT_ERROR
     18    );
    1119my $ipprc = PS::IPP::Config->new(); # IPP configuration
    1220use File::Spec;
     
    5159my $p2tool = can_run('p2tool') or (warn "Can't find p2tool" and $missing_tools = 1);
    5260my $ppImage = can_run('ppImage') or (warn "Can't find ppImage" and $missing_tools = 1);
    53 die "Can't find required tools.\n" if $missing_tools;
     61if ($missing_tools) {
     62    warn("Can't find required tools.");
     63    exit($PS_EXIT_CONFIG_ERROR);
     64}
    5465
    5566unless (defined $workdir) {
     
    7990    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    8091        run(command => $command, verbose => 1);
    81     die "Unable to perform ppImage on $input: $error_code\n" if not $success;
    82     die "Couldn't find expected output file: $outputImage\n" if not -f $outputImage;
    83     die "Couldn't find expected output file: $outputBin1\n" if not -f $outputBin1;
    84     die "Couldn't find expected output file: $outputBin2\n" if not -f $outputBin2;
    85     die "Couldn't find expected output file: $outputStats\n" if not -f $outputStats;
     92    unless ($success) {
     93        $error_code >> 8;
     94        &my_die("Unable to perform ppImage: $error_code", $exp_tag, $class_id, $error_code);
     95    }
     96    &my_die("Couldn't find expected output file: $outputImage\n", $exp_tag, $class_id, $PS_EXIT_SYS_ERROR) unless -f $outputImage;
     97    &my_die("Couldn't find expected output file: $outputBin1\n", $exp_tag, $class_id, $PS_EXIT_SYS_ERROR) unless -f $outputBin1;
     98    &my_die("Couldn't find expected output file: $outputBin2\n", $exp_tag, $class_id, $PS_EXIT_SYS_ERROR) unless -f $outputBin2;
     99    &my_die("Couldn't find expected output file: $outputStats\n", $exp_tag, $class_id, $PS_EXIT_SYS_ERROR) unless -f $outputStats;
    86100}
    87101
     
    90104{
    91105    my $statsFile;              # File handle
    92     open $statsFile, $outputStats or die "Can't open statistics file $outputStats: $!\n";
     106    open $statsFile, $outputStats or &my_die("Can't open statistics file $outputStats: $!", $exp_tag, $class_id, $PS_EXIT_SYS_ERROR);
    93107    my @contents = <$statsFile>; # Contents of file
    94108    close $statsFile;
    95109    my $mdcParser = PS::IPP::Metadata::Config->new;     # Parser for metadata config files
    96     my $metadata = $mdcParser->parse(join "", @contents)
    97             or die "unable to parse metadata config doc";
     110    my $metadata = $mdcParser->parse(join "", @contents) or
     111        &my_die("Unable to parse metadata config doc", $exp_tag, $class_id, $PS_EXIT_PROG_ERROR);
    98112    $stats = PS::IPP::Metadata::Stats->new(); # Stats parser
    99     $stats->parse($metadata) or die "Unable to find all values in statistics output.\n";
     113    $stats->parse($metadata) or
     114        &my_die("Unable to find all values in statistics output.\n", $exp_tag, $class_id, $PS_EXIT_PROG_ERROR);
    100115}
    101116
     
    120135    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    121136        run(command => $command, verbose => 1);
    122     die "Unable to perform p2tool -addprocessedimfile for $expTag/$classId: $error_code\n"
    123         if not $success;
     137    unless ($success) {
     138        $error_code >> 8;
     139        warn("Unable to perform p2tool -addprocessedimfile: $error_code\n");
     140        exit($error_code);
     141    }
    124142
    125143    unlink $outputStats;
     144}
     145
     146
     147sub my_die
     148{
     149    my $msg = shift; # Warning message on die
     150    my $exp_tag = shift; # Exposure tag
     151    my $class_id = shift; # Class identifier
     152    my $exit_code = shift; # Exit code to add
     153
     154    warn($msg);
     155    if ($exp_tag and $class_id) {
     156        my $command = "$dettool -addprocessedimfile -exp_tag $exp_tag -class_id $class_id -code $exit_code";
     157        $command .= " -dbname $dbname" if defined $dbname;
     158        system ($command);
     159    }
     160    exit $exit_code;
    126161}
    127162
Note: See TracChangeset for help on using the changeset viewer.