IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jun 1, 2026, 4:53:16 PM (7 weeks ago)
Author:
eugene
Message:

working on modernizing the error_code trapping

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ipp-pstamp-20260421/pstamp/scripts/pstamp_parser_run.pl

    r42981 r43048  
    1313use Getopt::Long qw( GetOptions );
    1414use File::Basename qw( basename dirname);
     15use Scalar::Util qw(looks_like_number);
    1516use File::Copy;
    1617use POSIX qw( strftime );
     
    128129    # if the uri is an http uri download the file
    129130    my $command = "$dsget --uri $uri --filename $new_uri --timeout 120";
    130     my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    131         run(command => $command, verbose => $verbose);
     131    my ( $success, $error_msg, $full_buf, $stdout_buf, $stderr_buf ) =
     132        run(command => $command, verbose => $verbose);
     133    my $error_code = &parse_error_message ($success, $error_msg, $command);
    132134    unless ($success) {
    133         my_die("Unable to perform $command error code: $error_code", $req_id, $error_code >> 8);
     135        my_die("Unable to perform $command error code: $error_code", $req_id, $error_code);
    134136    }
    135137} elsif ($uri ne $new_uri) {
     
    204206    $command   .= " -dbname $dbname" if $dbname;
    205207    $command   .= " -dbserver $dbserver" if $dbserver;
    206     my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    207         run(command => $command, verbose => $verbose);
     208    my ( $success, $error_msg, $full_buf, $stdout_buf, $stderr_buf ) =
     209        run(command => $command, verbose => $verbose);
     210    my $error_code = &parse_error_message ($success, $error_msg, $command);
    208211    unless ($success) {
    209212        die("Unable to perform $command error code: $error_code");
     
    227230
    228231    my $command = "$parse_cmd";
    229     my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    230         run(command => $command, verbose => $verbose);
     232    my ( $success, $error_msg, $full_buf, $stdout_buf, $stderr_buf ) =
     233        run(command => $command, verbose => $verbose);
     234    my $error_code = &parse_error_message ($success, $error_msg, $command);
    231235
    232236    # save the contents of stderr (if any) to a file. This is relevant if
     
    254258        }
    255259    } else {
    256         $fault = $error_code >> 8;
     260        $fault = $error_code;
    257261    }
    258262}
     
    326330    exit $fault;
    327331}
     332
     333# if the program exited normally, the exit value is returned
     334# if the program exited with a signal (abort, crash, etc), PS_EXIT_PROG_ERROR (4) is returned
     335# if the program failed to run, -PS_EXIT_PROG_ERROR (-4) is returned
     336sub parse_error_message {
     337    my $success = shift;
     338    my $error_msg = shift;
     339    my $command = shift;
     340
     341    if ($success) { return 0; }
     342
     343    print "raw error_msg: $error_msg\n";
     344    print "full command: $command\n";
     345
     346    if (&looks_like_number($error_msg)) { return (($error_msg >> 8) or ($PS_EXIT_PROG_ERROR)); }
     347       
     348    # which of these match?
     349    my ($error_code) = $error_msg =~ m/exited with value (\d+)/;
     350    if (defined $error_code) { return $error_code; }
     351   
     352    ($error_code) = $error_msg =~ m/died with signal (\d+)/;
     353#   if (defined $error_code) { return (128 + $error_code); }
     354    if (defined $error_code) { return ($PS_EXIT_PROG_ERROR); }
     355   
     356    # probably failed to execute:
     357    return (-1*$PS_EXIT_PROG_ERROR);
     358}
     359
Note: See TracChangeset for help on using the changeset viewer.