IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Aug 25, 2009, 3:24:19 PM (17 years ago)
Author:
bills
Message:

improve error handling

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/pstamp/scripts/pstamp_parser_run.pl

    r25058 r25195  
    1414use File::Basename qw( basename dirname);
    1515use POSIX qw( strftime );
     16use Carp;
     17use IPC::Cmd 0.36 qw( can_run run );
     18
     19use PS::IPP::Metadata::Config;
     20use PS::IPP::Metadata::Stats;
     21use PS::IPP::Metadata::List qw( parse_md_list );
     22
     23use PS::IPP::Config qw( :standard );
    1624
    1725my $req_id;
     
    3947}
    4048
    41 die "--req_id --uri --product are required"
     49my_die("--req_id --uri --product are required", $req_id, $PS_EXIT_CONFIG_ERROR)
    4250    if !defined($req_id) or
    4351       !defined($uri) or
    4452       !defined($product);
    45 
    46 use IPC::Cmd 0.36 qw( can_run run );
    47 
    48 use PS::IPP::Metadata::Config;
    49 use PS::IPP::Metadata::Stats;
    50 use PS::IPP::Metadata::List qw( parse_md_list );
    51 
    52 use PS::IPP::Config qw($PS_EXIT_SUCCESS
    53                        $PS_EXIT_UNKNOWN_ERROR
    54                        $PS_EXIT_SYS_ERROR
    55                        $PS_EXIT_CONFIG_ERROR
    56                        $PS_EXIT_PROG_ERROR
    57                        $PS_EXIT_DATA_ERROR
    58                        $PS_EXIT_TIMEOUT_ERROR
    59                        metadataLookupStr
    60                        metadataLookupBool
    61                        caturi
    62                        );
    6353
    6454my $ipprc = PS::IPP::Config->new(); # IPP Configuration
     
    8070my $datedir = "$pstamp_workdir/$datestr";
    8171if (! -e $datedir ) {
    82     mkdir $datedir or die "failed to create working directory $datedir for request id $req_id";
     72    mkdir $datedir or my_die( "failed to create working directory $datedir for request id $req_id", $req_id,
     73        $PS_EXIT_CONFIG_ERROR);
    8374}
    8475
    8576my $workdir = "$datedir/$req_id";
    8677if (! -e $workdir ) {
    87     mkdir $workdir or die "failed to create working directory $workdir for request id $req_id";
     78    mkdir $workdir or my_die("failed to create working directory $workdir for request id $req_id", $req_id,
     79        $PS_EXIT_CONFIG_ERROR);
    8880}
    8981
     
    119111        run(command => $command, verbose => $verbose);
    120112    unless ($success) {
    121         die("Unable to perform $command error code: $error_code");
     113        my_die("Unable to perform $command error code: $error_code", $req_id, $error_code >> 8);
    122114    }
    123115} elsif ($uri ne $new_uri) {
    124116    # put a link to the file into the workdir
    125117    if (-e $new_uri) {
    126         unlink $new_uri or die "failed to unlink $new_uri";
     118        unlink $new_uri or my_die("failed to unlink $new_uri", $req_id, $PS_EXIT_UNKNOWN_ERROR);
    127119    }
    128120    if (! symlink $uri, $new_uri) {
    129         die ("failed to link request file $uri to workdir $workdir");
     121        my_die ("failed to link request file $uri to workdir $workdir", $req_id, $PS_EXIT_UNKNOWN_ERROR);
    130122    }
    131123}
    132124$uri = $new_uri;
    133125
    134 die "request file $uri not found" if ! -e $uri;
     126my_die("request file $uri not found", $req_id, $PS_EXIT_UNKNOWN_ERROR) if ! -e $uri;
    135127
    136128#  if product was not defined (in database), use the default
     
    263255    }
    264256}
     257
     258sub my_die {
     259    my $msg = shift;
     260    my $req_id = shift;
     261    my $fault = shift;
     262
     263    carp($msg);
     264
     265    my $command = "$pstamptool -updatereq -req_id $req_id  -fault $fault";
     266    $command   .= " -dbname $dbname" if $dbname;
     267    $command   .= " -dbserver $dbserver" if $dbserver;
     268    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     269        run(command => $command, verbose => $verbose);
     270    unless ($success) {
     271        die("Unable to perform $command error code: $error_code");
     272    }
     273    exit $fault;
     274}
Note: See TracChangeset for help on using the changeset viewer.