IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 42580


Ignore:
Timestamp:
Jan 10, 2024, 12:37:40 PM (3 years ago)
Author:
eugene
Message:

fix error handling for xcsky.pl

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ipp-20230313/ippScripts/scripts/xcsky.pl

    r42574 r42580  
    1818
    1919use IPC::Cmd 0.36 qw( can_run run );
     20use Scalar::Util qw(looks_like_number);
    2021use PS::IPP::Metadata::Config;
    2122use PS::IPP::Metadata::List qw( parse_md_list );
     
    113114    my $command = "$xcskytool -inputs -xcsky_id $xcsky_id";
    114115    $command .= " -dbname $dbname" if defined $dbname;
    115     my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    116         run(command => $command, verbose => $verbose);
     116    my ( $success, $error_msg, $full_buf, $stdout_buf, $stderr_buf ) = run(command => $command, verbose => $verbose);
     117    my $error_code = &parse_error_message ($success, $error_msg, $command);
    117118    unless ($success) {
    118         $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    119         &my_die("Unable to perform xcskytool -inputs: $error_code", $xcsky_id, $error_code);
     119        &my_die("Unable to perform $command: $error_msg", $xcsky_id, $error_code);
    120120    }
    121121
     
    268268
    269269            unless ($no_op) {
    270                 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = run(command => $command, verbose => $verbose);
    271                 print "error code: $error_code\n";
    272                 unless ($success) {
    273                     $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    274                     &my_die("Unable to perform psphotStack: $error_code", $xcsky_id, $error_code);
    275                 }
     270                my ( $success, $error_msg, $full_buf, $stdout_buf, $stderr_buf ) = run(command => $command, verbose => $verbose);
     271                my $error_code = &parse_error_message ($success, $error_msg, $command);
     272                unless ($success) {
     273                    &my_die("Unable to perform psphotStack: $error_msg", $xcsky_id, $error_code);
     274                }
    276275
    277276                # my $outputStatsReal = $ipprc->file_resolve($outputStats);
     
    353352        }
    354353
    355         my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    356             run(command => $command, verbose => $verbose);
    357         unless ($success) {
    358             print "error: $error_code\n";
    359             $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    360             my $err_message = "Unable to perform: $command\n";
    361             warn($err_message);
     354        my ( $success, $error_msg, $full_buf, $stdout_buf, $stderr_buf ) = run(command => $command, verbose => $verbose);
     355        my $error_code = &parse_error_message ($success, $error_msg, $command);
     356        unless ($success) {
     357            warn("Unable to perform: $command\n");
    362358            exit $error_code;
    363359        }
    364360    }
    365361}
    366 
    367362
    368363sub my_die
     
    392387}
    393388
     389# if the program exited normally, the exit value is returned
     390# if the program exited with a signal (abort, crash, etc), PS_EXIT_PROG_ERROR (4) is returned
     391# if the program failed to run, -PS_EXIT_PROG_ERROR (-4) is returned
     392sub parse_error_message {
     393    my $success = shift;
     394    my $error_msg = shift;
     395    my $command = shift;
     396
     397    if ($success) { return 0; }
     398
     399    print "raw error_msg: $error_msg\n";
     400    print "full command: $command\n";
     401
     402    if (&looks_like_number($error_msg)) { return (($error_msg >> 8) or ($PS_EXIT_PROG_ERROR)); }
     403       
     404    # which of these match?
     405    my ($error_code) = $error_msg =~ m/exited with value (\d+)/;
     406    if (defined $error_code) { return $error_code; }
     407   
     408    ($error_code) = $error_msg =~ m/died with signal (\d+)/;
     409#   if (defined $error_code) { return (128 + $error_code); }
     410    if (defined $error_code) { return ($PS_EXIT_PROG_ERROR); }
     411   
     412    # probably failed to execute:
     413    return (-1*$PS_EXIT_PROG_ERROR);
     414}
     415
    394416END {
    395417    my $exit = $?;
Note: See TracChangeset for help on using the changeset viewer.