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_queue_update_cleanup.pl

    r42981 r43048  
    1010use Getopt::Long qw( GetOptions :config auto_help auto_version gnu_getopt );
    1111use Pod::Usage qw( pod2usage );
     12use Scalar::Util qw(looks_like_number);
    1213
    1314my $verbose;
     
    6667
    6768my $command = "$pstamptool -pendingdependent -includefaulted -simple";
    68 my  ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     69my  ( $success, $error_msg, $full_buf, $stdout_buf, $stderr_buf ) =
    6970    run(command => $command, verbose => $very_verbose);
     71my $error_code = &parse_error_message ($success, $error_msg, $command);
    7072unless ($success) {
    71     $error_code = (($error_code >> 8) or 1);
     73    $error_code = ($error_code or 1);
    7274    warn("$command failed. exit status: $error_code");
    7375    exit $error_code;
     
    8688        $command .= " -dbname $imagedb";
    8789
    88         my  ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     90        my  ( $success, $error_msg, $full_buf, $stdout_buf, $stderr_buf ) =
    8991            run(command => $command, verbose => $very_verbose);
     92        my $error_code = &parse_error_message ($success, $error_msg, $command);
    9093        unless ($success) {
    91             $error_code = (($error_code >> 8) or 1);
     94            $error_code = ($error_code or 1);
    9295            warn("$command failed. exit status: $error_code");
    9396            exit $error_code;
     
    97100
    98101exit 0;
     102
     103# if the program exited normally, the exit value is returned
     104# if the program exited with a signal (abort, crash, etc), PS_EXIT_PROG_ERROR (4) is returned
     105# if the program failed to run, -PS_EXIT_PROG_ERROR (-4) is returned
     106sub parse_error_message {
     107    my $success = shift;
     108    my $error_msg = shift;
     109    my $command = shift;
     110
     111    if ($success) { return 0; }
     112
     113    print "raw error_msg: $error_msg\n";
     114    print "full command: $command\n";
     115
     116    if (&looks_like_number($error_msg)) { return (($error_msg >> 8) or ($PS_EXIT_PROG_ERROR)); }
     117       
     118    # which of these match?
     119    my ($error_code) = $error_msg =~ m/exited with value (\d+)/;
     120    if (defined $error_code) { return $error_code; }
     121   
     122    ($error_code) = $error_msg =~ m/died with signal (\d+)/;
     123#   if (defined $error_code) { return (128 + $error_code); }
     124    if (defined $error_code) { return ($PS_EXIT_PROG_ERROR); }
     125   
     126    # probably failed to execute:
     127    return (-1*$PS_EXIT_PROG_ERROR);
     128}
Note: See TracChangeset for help on using the changeset viewer.