IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jun 1, 2026, 4:53:16 PM (2 months 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/pstampparse.pl

    r42981 r43048  
    1515use File::Temp qw(tempfile);
    1616use File::Basename qw(basename);
     17use Scalar::Util qw(looks_like_number);
    1718use Carp;
    1819use POSIX;
     
    126127{
    127128    my $command = "echo $request_file_name | $fields -x 0 EXTNAME EXTVER REQ_NAME ACTION EMAIL";
    128     my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     129    my ( $success, $error_msg, $full_buf, $stdout_buf, $stderr_buf ) =
    129130        run(command => $command, verbose => $verbose);
     131    my $error_code = &parse_error_message ($success, $error_msg, $command);
    130132
    131133    # note fields doesn't return zero when it succeeds.
     
    184186    my $command = "$pstamptool -listreq  -name $req_name -not_req_id $req_id";
    185187    # no verbose so that error message about request not found doesn't appear in parse_error.txt
    186     my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     188    my ( $success, $error_msg, $full_buf, $stdout_buf, $stderr_buf ) =
    187189        run(command => $command, verbose => 0);
    188     my $exitStatus = $error_code >> 8;
     190    my $error_code = &parse_error_message ($success, $error_msg, $command);
     191    my $exitStatus = $error_code;
    189192    if ($success) {
    190193        # -listreq succeeded there is already a request in the database with this name
     
    781784
    782785    my $base = basename($image->{image});
    783     if (! $base =~ /.fits$/ ) {
     786    if (! ($base =~ /.fits$/) ) {
    784787        my_die("unexpected image file name found $image->{image}", $PS_EXIT_PROG_ERROR);
    785788    }
     
    11361139
    11371140    if (!$no_update) {
    1138         my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     1141        my ( $success, $error_msg, $full_buf, $stdout_buf, $stderr_buf ) =
    11391142            run(command => $command, verbose => $verbose);
     1143        my $error_code = &parse_error_message ($success, $error_msg, $command);
    11401144        unless ($success) {
    1141             my $fault = $error_code >> 8;
     1145            my $fault = $error_code;
    11421146            print STDERR "$command failed with fault $fault\n";
    11431147            if ($fault < $PSTAMP_FIRST_ERROR_CODE) {
     
    14211425    exit $fault;
    14221426}
     1427
     1428# if the program exited normally, the exit value is returned
     1429# if the program exited with a signal (abort, crash, etc), PS_EXIT_PROG_ERROR (4) is returned
     1430# if the program failed to run, -PS_EXIT_PROG_ERROR (-4) is returned
     1431sub parse_error_message {
     1432    my $success = shift;
     1433    my $error_msg = shift;
     1434    my $command = shift;
     1435
     1436    if ($success) { return 0; }
     1437
     1438    print "raw error_msg: $error_msg\n";
     1439    print "full command: $command\n";
     1440
     1441    if (&looks_like_number($error_msg)) { return (($error_msg >> 8) or ($PS_EXIT_PROG_ERROR)); }
     1442       
     1443    # which of these match?
     1444    my ($error_code) = $error_msg =~ m/exited with value (\d+)/;
     1445    if (defined $error_code) { return $error_code; }
     1446   
     1447    ($error_code) = $error_msg =~ m/died with signal (\d+)/;
     1448#   if (defined $error_code) { return (128 + $error_code); }
     1449    if (defined $error_code) { return ($PS_EXIT_PROG_ERROR); }
     1450   
     1451    # probably failed to execute:
     1452    return (-1*$PS_EXIT_PROG_ERROR);
     1453}
     1454
Note: See TracChangeset for help on using the changeset viewer.