IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 23185


Ignore:
Timestamp:
Mar 4, 2009, 3:16:07 PM (17 years ago)
Author:
Paul Price
Message:

Removing all instances of die() and exit() --- we need the calling
script to do the error handling (i.e., push error status into
database). Wrapping Nebulous calls in eval{} blocks to prevent it
throwing exceptions that aren't caught in the calling script.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/PS-IPP-Config/lib/PS/IPP/Config.pm

    r21320 r23185  
    7171    unless (defined $class) {
    7272        carp "Programming error";
    73         exit($PS_EXIT_PROG_ERROR);
     73        return undef;
    7474    }
    7575
     
    8585    unless (open $file, $name) {
    8686        carp "Unable to open ipprc file $name: $!";
    87         exit($PS_EXIT_CONFIG_ERROR);
     87        return undef;
    8888    }
    8989    my @contents = <$file>;        # Contents of the ipprc file
     
    9595    unless (defined $path) {
    9696        carp "PATH is not set in $name\n";
    97         exit($PS_EXIT_CONFIG_ERROR);
     97        return undef;
    9898    }
    9999
     
    112112    bless $self, $class;
    113113
    114     $self->load_site();
    115     $self->load_system();
    116 
    117     $self->define_camera($camera) if defined $camera;
     114    $self->load_site() or return undef;
     115    $self->load_system() or return undef;
     116
     117    ( $self->define_camera($camera) or return undef ) if defined $camera;
    118118
    119119    return $self;
     
    148148                unless ($found) {
    149149                    carp "Unable to find camera configuration file $filename\n";
    150                     exit($PS_EXIT_CONFIG_ERROR);
     150                    return undef;
    151151                }
    152152            }
     
    158158
    159159    carp "Unable to find configuration file: $filename";
    160     exit($PS_EXIT_CONFIG_ERROR);
     160    return undef;
    161161}
    162162
     
    170170    unless (defined $self) {
    171171        carp "Programming error";
    172         exit($PS_EXIT_PROG_ERROR);
     172        return undef;
    173173    }
    174174
     
    176176    unless (defined $filename) {
    177177        carp "Unable to find site configuration file\n";
    178         exit($PS_EXIT_CONFIG_ERROR);
     178        return undef;
    179179    }
    180180
    181181    my $realfile = $self->_find_config($filename); # Resolved filename, after hunting the PATH
     182    ( carp "Unable to find site configuration" and return undef ) unless defined $realfile;
    182183
    183184    # Read the file
     
    185186    unless (open $file, $realfile) {
    186187        carp "Unable to open site configuration file $realfile: $!";
    187         exit($PS_EXIT_CONFIG_ERROR);
     188        return undef;
    188189    }
    189190
     
    194195    unless (defined $self->{_siteConfig}) {
    195196        carp "Failure to parse the site configuration file $realfile";
    196         exit($PS_EXIT_CONFIG_ERROR);
     197        return undef;
    197198    }
    198199
     
    207208    unless (defined $self) {
    208209        carp "Programming error";
    209         exit($PS_EXIT_PROG_ERROR);
     210        return undef;
    210211    }
    211212
     
    213214    unless (defined $filename) {
    214215        carp "Unable to find system configuration file\n";
    215         exit($PS_EXIT_CONFIG_ERROR);
     216        return undef;
    216217    }
    217218
    218219    my $realfile = $self->_find_config($filename); # Resolved filename, after hunting the PATH
     220    ( carp "Unable to find system configuration" and return undef ) unless defined $realfile;
    219221
    220222    # Read the file
     
    222224    unless (open $file, $realfile) {
    223225        carp "Unable to open system configuration file $realfile: $!";
    224         exit($PS_EXIT_CONFIG_ERROR);
     226        return undef;
    225227    }
    226228    my @contents = <$file>;
     
    230232    unless (defined $self->{_systemConfig}) {
    231233        carp "Failure to define system configuration";
    232         exit($PS_EXIT_CONFIG_ERROR);
     234        return undef;
    233235    }
    234236
     
    244246    unless (defined $self and defined $name) {
    245247        carp "Programming error";
    246         exit($PS_EXIT_PROG_ERROR);
     248        return undef;
    247249    }
    248250
     
    251253    unless (defined $filename) {
    252254        carp "Unable to find configuration file for camera $name\n";
    253         exit($PS_EXIT_CONFIG_ERROR);
     255        return undef;
    254256    }
    255257
    256258    my $realfile = $self->_find_config($filename); # Resolved filename, after hunting the PATH
     259    ( carp "Unable to find camera configuration" and return undef ) unless defined $realfile;
    257260
    258261    # Read the file
     
    260263    unless (open $file, $realfile) {
    261264        carp "Unable to open camera configuration file $realfile: $!";
    262         exit($PS_EXIT_CONFIG_ERROR);
     265        return undef;
    263266    }
    264267    my @contents = <$file>;
     
    269272    unless (defined $self->{camera}) {
    270273        carp "Failure to define camera";
    271         exit($PS_EXIT_CONFIG_ERROR);
     274        return undef;
    272275    }
    273276
     
    326329    unless (defined $self and defined $name) {
    327330        carp "Programming error";
    328         exit($PS_EXIT_PROG_ERROR);
     331        return undef;
    329332    }
    330333
     
    333336    unless (defined $pathname) {
    334337        carp "Unable to find datapath $name\n" ;
    335         exit($PS_EXIT_CONFIG_ERROR);
     338        return undef;
    336339    }
    337340
     
    340343
    341344# convert the database name and the table ID to a image source id
    342 sub source_id 
     345sub source_id
    343346{
    344347    my $self = shift;
     
    351354    my $admindb = "ippadmin";
    352355
    353     die "dbserver not defined in configuration" unless defined($dbserver);
    354     die "dbuser not defined in configuration" unless defined($dbuser);
    355     die "dbpassword not defined in configuration" unless defined($dbpassword);
    356     die "dbname not defined in configuration" unless defined($dbname);
     356    ( carp "dbserver not defined in configuration"  and return undef ) unless defined($dbserver);
     357    ( carp "dbuser not defined in configuration"  and return undef ) unless defined($dbuser);
     358    ( carp "dbpassword not defined in configuration"  and return undef ) unless defined($dbpassword);
     359    ( carp "dbname not defined in configuration"  and return undef ) unless defined($dbname);
    357360
    358361    my $dsn = "DBI:mysql:host=$dbserver;database=$admindb";
     
    363366    $stmt->execute();
    364367    my $ref = $stmt->fetchrow_hashref();
    365     die "ippdb $dbname not found" unless ($ref);
     368    ( carp "ippdb $dbname not found" and return undef ) unless ($ref);
    366369
    367370    my $proj_id = $ref->{proj_id};
     
    382385    if ($@) {
    383386        carp "Can't find Nebulous::Client.";
    384         exit($PS_EXIT_PROG_ERROR);
     387        return undef;
    385388    }
    386389
     
    390393    unless (defined $server) {
    391394        carp "Unable to find NEB_SERVER in camera configuration file.";
    392         exit($PS_EXIT_CONFIG_ERROR);
    393     }
    394 
    395     my $neb = Nebulous::Client->new( proxy => $server );
    396     unless (defined $neb) {
     395        return undef;
     396    }
     397
     398    my $neb = eval { Nebulous::Client->new( proxy => $server ); };
     399    if ($@ or not defined $neb) {
    397400        carp "Unable to find NEB_SERVER in camera configuration file.";
    398         exit($PS_EXIT_CONFIG_ERROR);
     401        return undef;
    399402    }
    400403
     
    415418    if ($scheme) {
    416419        $scheme = lc($scheme);
    417         # print "scheme: $scheme\n";
     420        # print "scheme: $scheme\n";
    418421
    419422        if ($scheme eq 'neb') {
    420             $self->_neb_start();
     423            $self->_neb_start() or ( carp "Can't start Nebulous" and return undef );
    421424            my $neb = $self->{nebulous}; # Nebulous handle
    422425            if ($create_if_doesnt_exist) {
    423                 unless ($neb->stat( $name )) {
    424                     # print "entry $name not found, creating...\n";
    425                     my $uri = $neb->create( $name );
    426                     unless(defined $uri) {
     426                my $status = eval { $neb->stat( $name ); };
     427                ( carp "Unable to stat Nebulous handle $name" and return undef ) if $@;
     428                unless ($status) {
     429                    # print "entry $name not found, creating...\n";
     430                    my $uri = eval { $neb->create( $name ); };
     431                    if ($@ or not defined $uri) {
    427432                        carp "unable to instantiate $name.";
    428                         exit($PS_EXIT_DATA_ERROR);
     433                        return undef;
    429434                    }
    430435                    my $path = URI->new( $uri )->path;
    431                     # print "created path: $path\n";
     436                    # print "created path: $path\n";
    432437                    return $path;
    433438                }
    434439            }
    435             my $path = $neb->find( $name );
    436             if (not defined $path) {
    437                 carp "neb entry $name not found, not created\n";
    438                 exit($PS_EXIT_DATA_ERROR);
    439             }
    440             # print "found path: $path\n";
     440            my $path = eval { $neb->find( $name ); };
     441            if ($@ or not defined $path) {
     442                carp "neb entry $name not found, not created\n";
     443                return undef;
     444            }
     445            # print "found path: $path\n";
    441446            return $path;
    442447        }
     
    444449        if ($scheme eq 'path' or $scheme eq 'file') {
    445450            # guaranteed to have a scheme (path:// or file://)
    446             $name = $self->convert_filename_absolute( $name );
    447             # print "resolved path to $name\n";
     451            $name = $self->convert_filename_absolute( $name ) or return undef;
     452            # print "resolved path to $name\n";
    448453        }
    449454    }
     
    454459        if (! -e $dir) {
    455460            my $rc = system "mkdir -p $dir";
    456             die "failed to create directory for $name" unless (!$rc);
     461            ( carp "failed to create directory for $name" and return undef ) unless (!$rc);
    457462        } elsif (! -d $dir ) {
    458             die "parent for $name exists and is not a directory";
    459         }
    460 
    461         open F, ">$name" or die "failed to create $name";
     463            carp "parent for $name exists and is not a directory";
     464            return undef;
     465        }
     466
     467        open F, ">$name" or ( carp "failed to create $name" and return undef );
    462468        close F;
    463         # print "created target $name\n";
     469        # print "created target $name\n";
    464470    }
    465471
     
    473479    my $name = shift;                # File name to check
    474480
    475     $self->file_prepare( $name );
     481    $self->file_prepare( $name ) or return undef;
    476482
    477483    my $scheme = file_scheme($name); # The scheme, e.g., file://, path://
     
    479485        $scheme = lc($scheme);
    480486        if ($scheme eq 'neb') {
    481             $self->_neb_start();
    482             return $self->{nebulous}->open_create( $name );
     487            $self->_neb_start() or ( carp "Unable to start Nebulous" and return undef );
     488            my $fh = eval { $self->{nebulous}->open_create( $name ); };
     489            if ($@ or not defined $fh) {
     490                carp "Unable to open/create Nebulous handle $name";
     491                return undef;
     492            }
     493            return $fh;
    483494        }
    484495        if ($scheme eq 'path' or $scheme eq 'file') {
    485496            # guaranteed to have a scheme (path:// or file://)
    486             $name = $self->convert_filename_absolute( $name );
     497            $name = $self->convert_filename_absolute( $name ) or return undef;
    487498        }
    488499    }
     
    490501    if (-f $name) {
    491502        carp "Unable to create file $name --- file exists.";
    492         exit($PS_EXIT_SYS_ERROR);
     503        return undef;
    493504    }
    494505
     
    496507    unless (open $fh, '>', $name) {
    497508        carp "Unable to create file $name --- $!";
    498         exit($PS_EXIT_SYS_ERROR);
     509        return undef;
    499510    }
    500511    return $fh;
     
    507518    my $name = shift;                # File name to check
    508519
    509     $self->file_prepare( $name );
     520    $self->file_prepare( $name ) or return undef;
    510521
    511522    my $scheme = file_scheme($name); # The scheme, e.g., file://, path://
     
    513524        $scheme = lc($scheme);
    514525        if ($scheme eq 'neb') {
    515             $self->_neb_start();
    516             return $self->{nebulous}->open_create( $name );
     526            $self->_neb_start() or ( carp "Unable to start Nebulous" and return undef );
     527            my $fh = eval { $self->{nebulous}->open_create( $name ) };
     528            if ($@ or not defined $fh) {
     529                carp "Unable to open/create Nebulous handle $name";
     530                return undef;
     531            }
     532            return $fh;
    517533        }
    518534        if ($scheme eq 'path' or $scheme eq 'file') {
    519535            # guaranteed to have a scheme (path:// or file://)
    520             $name = $self->convert_filename_absolute( $name );
     536            $name = $self->convert_filename_absolute( $name ) or return undef;
    521537        }
    522538    }
     
    525541    unless (open $fh, '>>', $name) {
    526542        carp "Unable to create file $name --- $!";
    527         exit($PS_EXIT_SYS_ERROR);
     543        return undef;
    528544    }
    529545    return $fh;
     
    536552    my $name = shift;                # File name to check
    537553
    538     $self->file_prepare( $name );
     554    $self->file_prepare( $name ) or return undef;
    539555
    540556    my $scheme = file_scheme($name); # The scheme, e.g., file://, path://
    541557    if (defined $scheme and lc($scheme) eq 'neb') {
    542         $self->_neb_start();
    543         $name = $self->{nebulous}->create( $name );
     558        $self->_neb_start() or ( carp "Unable to start Nebulous" and return undef );
     559        $name = eval { $self->{nebulous}->create( $name ) };
     560        if ($@ or not defined $name) {
     561            carp "Unable to create Nebulous handle $name";
     562            return undef;
     563        }
    544564    }
    545565
     
    555575    my $scheme = file_scheme($name); # The scheme, e.g., file://, path://
    556576    if (defined $scheme and lc($scheme) eq 'neb') {
    557         $self->_neb_start();
    558         return (defined $self->{nebulous}->find_instances( $name ) ? 1 : 0);
     577        $self->_neb_start() or ( carp "Unable to start Nebulous" and return undef );
     578        my $found = eval { $self->{nebulous}->find_instances( $name ); };
     579        ( carp "Unable to find instances of Nebulous handle $name" and return undef ) if $@;
     580        return (defined $found ? 1 : 0);
    559581    }
    560582
     
    569591    my $target = shift;                # Name of target file
    570592
    571     $self->file_prepare( $target );
     593    $self->file_prepare( $target ) or return undef;
    572594
    573595    my $scheme = file_scheme($target); # The scheme, e.g., file://, path://
    574596    if (defined $scheme and lc($scheme) eq 'neb') {
    575         $self->_neb_start();
    576         $target = $self->{nebulous}->create( $target );
     597        $self->_neb_start() or ( carp "Unable to start Nebulous" and return undef );
     598        $target = eval { $self->{nebulous}->create( $target ); };
     599        if ($@ or not defined $target) {
     600            carp "Unable to create Nebulous handle";
     601            return undef;
     602        }
    577603    }
    578604    $target = $self->file_resolve( $target );
    579605    $source = $self->file_resolve( $source );
    580606
    581     system("cp $source $target") == 0 or (carp "Can't copy file $source to $target." and
    582                                           exit($PS_EXIT_DATA_ERROR));
     607    system("cp $source $target") == 0 or ( carp "Can't copy file $source to $target." and return undef );
    583608    return 1;
    584609}
     
    593618    my $preserve = shift;
    594619
    595     die "pathname must be defined" unless ($pathname);
     620    ( carp "pathname must be defined" and return undef ) unless ($pathname);
    596621
    597622    my $fileRef;
     
    602627
    603628    if ($preserve) {
    604         # we want to keep the file just create it in the current directory 
     629        # we want to keep the file just create it in the current directory
    605630        $fileName = "./$base";
    606         open $fileRef, ">$fileName" or die "can't open $fileName for output";
     631        open $fileRef, ">$fileName" or ( carp "can't open $fileName for output" and return undef );
    607632    } else {
    608633        #  we really want a tempfile, so put it in /tmp
     
    621646    my $scheme = file_scheme($name); # The scheme, e.g., file://, path://
    622647    if (defined $scheme and lc($scheme) eq 'neb') {
    623         $self->_neb_start();
    624         $status = $self->{nebulous}->delete( $name );
     648        $self->_neb_start() or ( carp "Unable to start Nebulous" and return undef );
     649        $status = eval { $self->{nebulous}->delete( $name ); };
     650        ( carp "Unable to delete Nebulous handle $name" and return undef ) if $@;
    625651    } else {
    626         my $resolved = $self->file_resolve($name);
    627         if ($resolved && -e $resolved) {
     652        my $resolved = $self->file_resolve($name) or return undef;
     653        if (defined $resolved and -e $resolved) {
    628654            $status = unlink($resolved);
    629655        }
     
    638664    my $name = shift;
    639665
    640     die "need name" unless $name;
     666    ( carp "need redirection target" and return undef ) unless $name;
    641667
    642668    my $filename = $self->file_resolve($name, 1);
    643669
    644     die "cannot resolve $name" unless $filename;
     670    ( carp "cannot resolve $name" and return undef ) unless $filename;
    645671
    646672    if (! open(STDOUT, ">>$filename") ) {
     
    651677        while (! open STDOUT, ">>$filename" ) {
    652678            if ($try == $max_tries) {
    653                 die "failed to redirect stdout to $filename after trying $max_tries times";
     679                carp "failed to redirect stdout to $filename after trying $max_tries times";
     680                return undef;
    654681            }
    655682            sleep 5;
     
    658685        print STDERR "   redirect stdout to $filename succeded on try $try\n";
    659686    }
    660     open STDERR, ">>$filename" or die "failed to redirect stderr to $filename";
     687    open STDERR, ">>$filename" or ( carp "failed to redirect stderr to $filename" and return undef );
     688
     689    return 1;
    661690}
    662691
     
    676705    my $name = shift;                # File name for which to prepare
    677706    my $workdir = shift;        # Working directory
    678     my $template = shift;        # Template filename from which to get working directory if 
     707    my $template = shift;        # Template filename from which to get working directory if
    679708
    680709    if (defined $workdir) {
     
    692721    # not guaranteed to have a scheme (path:// or file://) - might be /PATH/foobar
    693722    # a relative path (PATH/foobar) is invalid here
    694     my $resolved = $self->convert_filename_absolute( $name );
     723    my $resolved = $self->convert_filename_absolute( $name ) or return undef;
    695724    my ( $vol, $dirs, $file ) = File::Spec->splitpath( $resolved );
    696725    unless (-d $dirs) {
    697         system("mkdir -p $dirs") == 0 or (carp "Can't create directory $dirs" and exit($PS_EXIT_DATA_ERROR));
     726        system("mkdir -p $dirs") == 0 or ( carp "Can't create directory $dirs" and return undef );
    698727    }
    699728
     
    716745    # not guaranteed to have a scheme (path:// or file://) - might be /PATH/foobar
    717746    # a relative path (PATH/foobar) is invalid here
    718     my $resolved = $self->convert_filename_absolute( $outroot );
     747    my $resolved = $self->convert_filename_absolute( $outroot ) or return undef;
    719748    my ( $vol, $dirs, $file ) = File::Spec->splitpath( $resolved );
    720749    unless (-d $dirs) {
    721         system("mkdir -p $dirs") == 0 or (carp "Can't create directory $dirs" and exit($PS_EXIT_DATA_ERROR));
     750        system("mkdir -p $dirs") == 0 or ( carp "Can't create directory $dirs" and return undef );
    722751    }
    723752
     
    734763    unless (defined $self and defined $name) {
    735764        carp "Programming error";
    736         exit($PS_EXIT_PROG_ERROR);
     765        return undef;
    737766    }
    738767
     
    741770
    742771    ## if this is already an absolute path (/PATH/file), just return the path
    743     unless (defined $scheme) { 
     772    unless (defined $scheme) {
    744773        if ($name =~ m|^/|) { return $name; }
    745774        # without a leading slash, this is an error
    746775        carp "Relative file name provided: relative paths are not permitted.";
    747         exit($PS_EXIT_SYS_ERROR);
     776        return undef;
    748777    }
    749778
     
    751780
    752781    if (lc($scheme) eq 'file') {
    753         # the above strips of the leading slash; replace it for file:// 
     782        # the above strips of the leading slash; replace it for file://
    754783        $name = '/' . $name;
    755784        return $name;
     
    764793    }
    765794
    766     # looks like we cannot reach here without an invalid scheme. 
    767     # programming error?
    768     # return $name;
    769 
    770     carp "Programming error";
    771     exit($PS_EXIT_PROG_ERROR);
     795    # It's already absolute
     796    return $name;
    772797}
    773798
     
    777802    my $self = shift;                # Configuration object
    778803    my $name = shift;                # raw name
    779    
     804
    780805    unless (defined $self and defined $name) {
    781806        carp "Programming error";
    782         exit($PS_EXIT_PROG_ERROR);
    783     }
    784    
     807        return undef;
     808    }
     809
    785810    # First, check to see if it's already in a relative form
    786811    my $scheme = file_scheme($name); # The scheme, e.g., file, path
     
    790815            # We may as well search for a 'better' path
    791816            # guaranteed to have a scheme (path:// or file://)
    792             $name = $self->convert_filename_absolute( $name );
     817            $name = $self->convert_filename_absolute( $name ) or return undef;
    793818        } elsif ($scheme eq 'neb') {
    794819            # No chance of changing anything --- move along
     
    796821        }
    797822    }
    798    
     823
    799824    $name = File::Spec->canonpath( $name); # Clean up
    800825    my @dirs = File::Spec->splitdir( $name );
    801    
     826
    802827    my $path_list = metadataLookupMD($self->{_siteConfig}, 'DATAPATH'); # List of paths
    803828    my $best_path;
     
    809834      $path =~ s|/*$||;
    810835      my @path_dirs = File::Spec->splitdir( $path );
    811      
     836
    812837      # Check if the path is suitable
    813838      next if scalar @path_dirs > scalar @dirs;
     
    823848      }
    824849  }
    825    
     850
    826851    $name =~ s|^/||;
    827852    $name =~ s|/$||;
     
    845870    unless (defined $self and defined $name and defined $type) {
    846871        carp "Programming error";
    847         exit($PS_EXIT_PROG_ERROR);
     872        return undef;
    848873    }
    849874
     
    854879            return undef;
    855880        }
    856        
     881
    857882        # rejections are saved as a recipe: REJECTIONS
    858883        my @rejContents = `ppConfigDump -dump-recipe REJECTIONS -camera $camera -`;
    859        
     884
    860885        # load from resulting psMetadataConfig
    861886        $self->{rejection} = $parser->parse( join '', @rejContents); # The rejection metadata
    862887        unless (defined $self->{rejection}) {
    863888            carp "Unable to parse REJECTION recipe for $camera.";
    864             exit($PS_EXIT_CONFIG_ERROR);
     889            return undef;
    865890        }
    866891    }
     
    873898          unless ($item->{class} eq "metadata") {
    874899              carp "$name within REJECTIONS is not of type METADATA";
    875               exit($PS_EXIT_PROG_ERROR);
     900              return undef;
    876901          }
    877902          my $limits = $item->{value}; # List of rejection limits
     
    880905          foreach my $limit (@$limits) {
    881906              if ($limit->{name} eq 'FILTER') {
    882                   if ($limit->{value} eq '*' or
    883                       (defined $filter and
    884                        $limit->{value} eq $filter)) {
     907                  if ($limit->{value} eq '*' or (defined $filter and $limit->{value} eq $filter)) {
    885908                      last;
    886909                  }
     
    888911              }
    889912          }
    890          
     913
    891914          foreach my $limit (@$limits) {
    892915              return $limit->{value} if $limit->{name} eq $name;
     
    915938    unless (defined $self and defined $name and defined $output) {
    916939        carp "Programming error: required inputs left undefined";
    917         exit($PS_EXIT_PROG_ERROR);
     940        return undef;
    918941    }
    919942
     
    929952            return undef;
    930953        }
    931        
     954
    932955        $filerules = metadataLookup($camera, 'FILERULES');        # File rules
    933956        unless (defined $filerules) {
     
    935958            return undef;
    936959        }
    937        
     960
    938961        if ($filerules->{class} eq "scalar" and $filerules->{type} eq "STR") {
    939962            # Allow indirection to a file
    940963            my $filename = $self->_find_config($filerules->{value}); # Resolved filename
     964            ( carp "Unable to find file rules file" and return undef ) unless defined $filename;
     965
    941966            # Read the file
    942967            my $file;                # File handle
    943968            unless (open $file, $filename) {
    944969                carp "Unable to open filerules file $filename: $!";
    945                 exit($PS_EXIT_CONFIG_ERROR);
     970                return undef;
    946971            }
    947972            my @contents = <$file>;
     
    973998        unless (defined $component) {
    974999            carp "Programming error";
    975             exit($PS_EXIT_PROG_ERROR);
     1000            return undef;
    9761001        }
    9771002        $filename =~ s/\{CHIP\.NAME\}/$component/;
     
    9801005
    9811006    return $filename;
    982 }   
     1007}
    9831008
    9841009# Return an EXTNAME From the EXTNAME.RULE table in the camera configuration
     
    9911016    unless (defined $self and defined $name) {
    9921017        carp "Programming error";
    993         exit($PS_EXIT_PROG_ERROR);
     1018        return undef;
    9941019    }
    9951020
     
    10151040        unless (defined $component) {
    10161041            carp "Programming error";
    1017             exit($PS_EXIT_PROG_ERROR);
     1042            return undef;
    10181043        }
    10191044        $extname =~ s/\{CHIP\.NAME\}/$component/;
     
    10211046
    10221047    return $extname;
    1023 }   
     1048}
    10241049
    10251050# Return catdir for tessellation, from TESSELLATIONS within the site configuration
     
    10311056    unless (defined $self and defined $self->{_siteConfig} and defined $tess_id) {
    10321057        carp "Programming error";
    1033         exit($PS_EXIT_PROG_ERROR);
     1058        return undef;
    10341059    }
    10351060
     
    10371062    unless (defined $tessellations) {
    10381063        carp "Can't find TESSELLATIONS in site configuration.\n";
    1039         exit($PS_EXIT_CONFIG_ERROR);
     1064        return undef;
    10401065    }
    10411066
     
    10501075    if (defined $scheme and lc($scheme) eq 'neb') {
    10511076        carp "Tessellation $tess_id refers to a Nebulous path: $catdir\n";
    1052         exit($PS_EXIT_CONFIG_ERROR);
     1077        return undef;
    10531078    }
    10541079
     
    10651090    unless (defined $self and defined $self->{_siteConfig} and defined $dvodb) {
    10661091        carp "Programming error";
    1067         exit($PS_EXIT_PROG_ERROR);
     1092        return undef;
    10681093    }
    10691094
     
    10711096    unless (defined $catdirs) {
    10721097        carp "Can't find DVO.CATDIRS in site configuration.\n";
    1073         exit($PS_EXIT_CONFIG_ERROR);
     1098        return undef;
    10741099    }
    10751100
     
    10841109    if (defined $scheme and lc($scheme) eq 'neb') {
    10851110        carp "DVO catdir $dvodb refers to a Nebulous path: $catdir\n";
    1086         exit($PS_EXIT_CONFIG_ERROR);
     1111        return undef;
    10871112    }
    10881113
     
    10981123    unless (defined $self and defined $self->{_siteConfig} and defined $dvodb) {
    10991124        carp "Programming error";
    1100         exit($PS_EXIT_PROG_ERROR);
     1125        return undef;
    11011126    }
    11021127
     
    11041129    unless (defined $catdirs) {
    11051130        carp "Can't find PSASTRO.CATDIRS in site configuration.\n";
    1106         exit($PS_EXIT_CONFIG_ERROR);
     1131        return undef;
    11071132    }
    11081133
     
    11171142    if (defined $scheme and lc($scheme) eq 'neb') {
    11181143        carp "PSASTRO catdir $dvodb refers to a Nebulous path: $catdir\n";
    1119         exit($PS_EXIT_CONFIG_ERROR);
     1144        return undef;
    11201145    }
    11211146
     
    11301155    unless (defined $self) {
    11311156        carp "Programming error";
    1132         exit($PS_EXIT_PROG_ERROR);
     1157        return undef;
    11331158    }
    11341159
     
    11581183    unless (defined $self and defined $reduction and defined $name) {
    11591184        carp "Programming error --- inputs undefined";
    1160         exit($PS_EXIT_PROG_ERROR);
     1185        return undef;
    11611186    }
    11621187
     
    11801205            return undef;
    11811206        }
    1182        
     1207
    11831208        if ($reductionClasses->{class} eq "scalar" and $reductionClasses->{type} eq "STR") {
    11841209            # Allow indirection to a file
    11851210            my $filename = $self->_find_config($reductionClasses->{value}); # Resolved filename
     1211            ( carp "Unable to find reduction classes file" and return undef ) unless defined $filename;
    11861212            # Read the file
    11871213            my $file;                # File handle
    11881214            unless (open $file, $filename) {
    11891215                carp "Unable to open reductionClasses file $filename: $!";
    1190                 exit($PS_EXIT_CONFIG_ERROR);
     1216                return undef;
    11911217            }
    11921218            my @contents = <$file>;
     
    12031229
    12041230    my $class = metadataLookupMD($reductionClasses, $reduction) or # Class of interest
    1205         (carp "Can't find $reduction in REDUCTION in camera configuration.\n" and
    1206          exit($PS_EXIT_CONFIG_ERROR));
     1231        ( carp "Can't find $reduction in REDUCTION in camera configuration.\n" and return undef );
    12071232
    12081233    my $actual = metadataLookupStr($class, $name) or # The actual recipe name of interest
    1209         (carp "Can't find $name in $class in REDUCTION in camera configuration.\n" and
    1210          exit($PS_EXIT_CONFIG_ERROR));
     1234        (carp "Can't find $name in $class in REDUCTION in camera configuration.\n" and return undef );
    12111235
    12121236    return $actual;
     
    12261250    }
    12271251
    1228     my $dvoImageExtract = can_run('dvoImageExtract') or die "Can't find dvoImageExtract";
    1229    
     1252    my $dvoImageExtract = can_run('dvoImageExtract') or ( carp "Can't find dvoImageExtract" and return undef );
     1253
    12301254    my $tess_dir = $self->tessellation_catdir( $tess_id ); # Tessellation catdir for DVO
    12311255    unless (defined $tess_dir) {
    12321256        carp "Can't get list of tessellations.";
    1233         return 0;
    1234     }
    1235     $tess_dir = $self->convert_filename_absolute( $tess_dir );
     1257        return undef;
     1258    }
     1259    $tess_dir = $self->convert_filename_absolute( $tess_dir ) or return undef;
    12361260
    12371261    unless ($self->file_exists( $outname )) {
    1238         my $outnameResolved = $self->file_create( $outname ); # Resolved filename, for Nebulous
     1262        my $outnameResolved = $self->file_create( $outname ) or return undef; # Resolved filename, for Nebulous
    12391263        my $command = "$dvoImageExtract -D CATDIR $tess_dir $skycell_id -o $outnameResolved";
    12401264        my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    12411265            run(command => $command, verbose => $verbose);
    1242         die "Unable to perform dvoImageExtract for $tess_id $skycell_id\n" unless ($success and $self->file_exists( $outname ));
     1266        ( carp "Unable to perform dvoImageExtract for $tess_id $skycell_id\n" and return undef ) unless ($success and $self->file_exists( $outname ));
    12431267    }
    12441268
     
    12581282        unless (defined $value) {
    12591283            carp "Unable to find environment variable $name";
    1260             exit($PS_EXIT_SYS_ERROR);
     1284            return undef;
    12611285        }
    12621286        $dir =~ s/\$\{?$name\}?/$value\//;
     
    12721296    unless (defined $mdc and defined $name) {
    12731297        carp "Programming error";
    1274         exit($PS_EXIT_PROG_ERROR);
     1298        return undef;
    12751299    }
    12761300
     
    12851309    return undef;
    12861310}
    1287    
     1311
    12881312
    12891313# Lookup the metadata, checking the type is STR
     
    13251349    unless (defined $mdc and defined $name) {
    13261350        carp "Programming error";
    1327         exit($PS_EXIT_PROG_ERROR);
     1351        return undef;
    13281352    }
    13291353
Note: See TracChangeset for help on using the changeset viewer.