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/psmkreq

    r40421 r43048  
    1717use File::Temp qw(tempfile);
    1818use File::Basename qw(basename);
     19use Scalar::Util qw(looks_like_number);
    1920use IPC::Cmd 0.36 qw( can_run run );
    2021use Carp;
     
    295296    my $command = "$pstamp_request_file --input $table_def_name --req_name $req_name";
    296297    $command .= " --output $output" if $output;
    297     my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     298    my ( $success, $error_msg, $full_buf, $stdout_buf, $stderr_buf ) =
    298299        run(command => $command, verbose => $verbose);
     300    my $error_code = &parse_error_message ($success, $error_msg, $command);
    299301    unless ($success) {
    300302        print STDERR @$stderr_buf;
    301         exit $error_code >> 8;
     303        exit $error_code;
    302304    }
    303305}
     
    447449
    448450}
     451
     452# if the program exited normally, the exit value is returned
     453# if the program exited with a signal (abort, crash, etc), PS_EXIT_PROG_ERROR (4) is returned
     454# if the program failed to run, -PS_EXIT_PROG_ERROR (-4) is returned
     455sub parse_error_message {
     456    my $success = shift;
     457    my $error_msg = shift;
     458    my $command = shift;
     459
     460    if ($success) { return 0; }
     461
     462    print "raw error_msg: $error_msg\n";
     463    print "full command: $command\n";
     464
     465    if (&looks_like_number($error_msg)) { return (($error_msg >> 8) or ($PS_EXIT_PROG_ERROR)); }
     466       
     467    # which of these match?
     468    my ($error_code) = $error_msg =~ m/exited with value (\d+)/;
     469    if (defined $error_code) { return $error_code; }
     470   
     471    ($error_code) = $error_msg =~ m/died with signal (\d+)/;
     472#   if (defined $error_code) { return (128 + $error_code); }
     473    if (defined $error_code) { return ($PS_EXIT_PROG_ERROR); }
     474   
     475    # probably failed to execute:
     476    return (-1*$PS_EXIT_PROG_ERROR);
     477}
     478
Note: See TracChangeset for help on using the changeset viewer.