Ignore:
Timestamp:
05/31/11 15:12:20 (13 years ago)
Author:
sdipsl
Message:
  • Better error handling within libGCM
  • Pre requisite to have more robust post-processing workflow
  • Improve verbosity to help users identify problem
  • Cosmetic
  • backward compatible
Location:
trunk/libIGCM/libIGCM_card
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/libIGCM/libIGCM_card/IGCM_card_PrintOption.awk

    r425 r475  
    124124 
    125125if (section_found == 0) { 
    126         print "Error: Section not found", section, option 
     126        print "Error: Section not found" 
    127127} else if (option_found == 0) { 
    128         print "Error: Option not found", section, option 
     128        print "Error: Option not found" 
    129129} else { 
    130130        print option_value 
  • trunk/libIGCM/libIGCM_card/IGCM_card_PrintSection.awk

    r373 r475  
    109109        print "Error: Section not found" 
    110110} else if (match(option_list,"null")) { 
    111         print "Error: Options not found" 
     111        print "Error: Option not found" 
    112112} else { 
    113113        print option_list 
  • trunk/libIGCM/libIGCM_card/IGCM_card_WriteOption.awk

    r373 r475  
    106106         
    107107        if (section_found == 0) { 
    108             print "Error: Section not found", section, option 
     108            print "Error: Section not found" 
    109109        } else if (option_found == 0) { 
    110             print "Error: Option not found", section, option 
     110            print "Error: Option not found" 
    111111        }        
    112112         
  • trunk/libIGCM/libIGCM_card/libIGCM_card.ksh

    r472 r475  
    5252#D-* Purpose: Print an option from a given file.card and section 
    5353#D-* Usage: IGCM_card_PrintOption file.card section option 
     54#D-* Only used by IGCM_card_Test.ksh 
    5455#D- 
    5556function IGCM_card_PrintOption 
    5657{ 
    5758    IGCM_debug_PushStack "IGCM_card_PrintOption" $@ 
    58     if [ -r "$1" ] ; then 
     59    if ( [ -r "$1" ] && [ -f "$1" ] ) ; then 
    5960        gawk -f ${libIGCM}/libIGCM_card/IGCM_card_PrintOption.awk "$@" 
    6061    else 
    61         echo "--Error--> IGCM_card_PrintOption $@" 
    62         echo "           $1 is not readable" 
     62        echo 
     63        IGCM_debug_Print 1 "--Error--> IGCM_card_PrintOption $@" 
     64        IGCM_debug_Print 1 "           $1 is not readable" 
    6365        IGCM_debug_Exit "IGCM_card_PrintOption" 
    6466    fi 
     
    7072#D-* Purpose: Print all options from a given file.card and section 
    7173#D-* Usage: IGCM_card_PrintSection file.card section 
     74#D-* Only used by IGCM_card_Test.ksh 
    7275#D- 
    7376function IGCM_card_PrintSection 
    7477{ 
    7578    IGCM_debug_PushStack "IGCM_card_PrintSection" $@ 
    76     if [ -r "$1" ] ; then 
     79    if ( [ -r "$1" ] && [ -f "$1" ] ) ; then 
    7780        gawk -f ${libIGCM}/libIGCM_card/IGCM_card_PrintSection.awk -- "$@" 
    7881    else 
    79         echo "--Error--> IGCM_card_PrintSection $@" 
    80         echo "           $1 is not readable" 
     82        IGCM_debug_Print 1 "--Error--> IGCM_card_PrintSection $@" 
     83        IGCM_debug_Print 1 "           $1 is not readable" 
    8184        IGCM_debug_Exit "IGCM_card_PrintSection" 
    8285    fi 
     
    9396{ 
    9497    IGCM_debug_PushStack "IGCM_card_DefineVariableFromOption" $@ 
    95     if [ -r "$1" ] ; then 
     98    if ( [ -r "$1" ] && [ -f "$1" ] ) ; then 
    9699        # Get basename of card file ($1) 
    97100        typeset name1=${1##*/} 
     
    100103        typeset value=$( gawk -f ${libIGCM}/libIGCM_card/IGCM_card_PrintOption.awk -- "$@" ) 
    101104 
    102         if [ "${value}" = "Error: Option not found" ] ; then 
    103             echo "Error with readding of ${name} variable in ${1} ." 
    104             echo "Error: Option not found." 
     105        # Only if a section is missing we exit the job. 
     106        # We must allow missing option to keep backward compatibilty. 
     107        if [ "${value}" = "Error: Section not found" ] ; then 
     108            echo 
     109            IGCM_debug_Print 1 "Error with readding of ${name} variable in ${1}." 
     110            IGCM_debug_Print 1 "Error: Section ${2} not found" 
    105111            IGCM_debug_Exit 
    106112            IGCM_debug_Verif_Exit 
     
    108114        eval ${name}=${value} 
    109115    else 
    110         echo "--Error--> IGCM_card_DefineVariableFromOption $@" 
    111         echo "           $1 is not readable" 
     116        echo 
     117        IGCM_debug_Print 1 "--Error--> IGCM_card_DefineVariableFromOption" 
     118        IGCM_debug_Print 1 "--Error--> $1 is not readable" 
    112119        IGCM_debug_Exit "IGCM_card_DefineVariableFromOption" 
     120        IGCM_debug_Verif_Exit 
    113121    fi 
    114122    IGCM_debug_PopStack "IGCM_card_DefineVariableFromOption" 
     
    124132{ 
    125133    IGCM_debug_PushStack "IGCM_card_DefineArrayFromOption" $@ 
    126     if [ -r "$1" ] ; then 
     134    if ( [ -r "$1" ] && [ -f "$1" ] ) ; then 
    127135        # Get basename of card file ($1) 
    128136        typeset name1=${1##*/} 
     
    133141        set +A ${name} -- $( gawk -f ${libIGCM}/libIGCM_card/IGCM_card_PrintOption.awk -- "$@" | gawk -- 'BEGIN {FS="[() ,]+"} {for (i=2; i <= NF-1; i++) printf("%s ",$i)}' ) 
    134142    else 
    135         echo "--Error--> IGCM_card_DefineArrayFromOption $@" 
    136         echo "           $1 is not readable" 
     143        echo 
     144        IGCM_debug_Print 1 "--Error--> IGCM_card_DefineArrayFromOption $@" 
     145        IGCM_debug_Print 1 "           $1 is not readable" 
    137146        IGCM_debug_Exit "IGCM_card_DefineArrayFromOption" 
    138147    fi 
     
    149158{ 
    150159    IGCM_debug_PushStack "IGCM_card_DefineArrayFromSection" $@ 
    151     if [ -r "$1" ] ; then 
     160    if ( [ -r "$1" ] && [ -f "$1" ] ) ; then 
    152161        # Get basename of card file ($1) 
    153162        typeset name1=${1##*/} 
     
    157166        eval ${name}[0]=${NULL_STR} 
    158167        set +A ${name} -- $( gawk -f ${libIGCM}/libIGCM_card/IGCM_card_PrintSection.awk -- "$@" ) 
    159     else 
    160         echo "--Error--> IGCM_card_DefineArrayFromSection $@" 
    161         echo "           $1 is not readable" 
     168        if [ "$( eval echo \${${name}[@]} )" = "Error: Section not found" ] ; then 
     169            echo 
     170            IGCM_debug_Print 1 "Error with readding of ${name} variable in ${1}." 
     171            IGCM_debug_Print 1 "Error: Section ${2} not found" 
     172            IGCM_debug_Exit 
     173            IGCM_debug_Verif_Exit 
     174        fi 
     175    else 
     176        IGCM_debug_Print 1 "--Error--> IGCM_card_DefineArrayFromSection $@" 
     177        IGCM_debug_Print 1 "           $1 is not readable" 
    162178        IGCM_debug_Exit "IGCM_card_DefineArrayFromSection" 
    163179    fi 
     
    178194{ 
    179195    IGCM_debug_PushStack "IGCM_card_WriteOption" $@ 
    180     if [ -r "$1" ] && [ -w "$1" ] ; then 
     196    if ( [ -r "$1" ] && [ -w "$1" ]  && [ -f "$1" ] ) ; then 
    181197        typeset tmpfile=tmpfile_$$ 
    182198        ( IGCM_card_PrintOption "$1" "$2" "$3" | grep "not found" ) > ${tmpfile} 
     
    185201            echo "!!! Problem with IGCM_card_WriteOption !!!" 
    186202            echo "Try to write : " $@ 
    187             echo "You have to correcte some script."  
     203            echo "You have to correct some script."  
    188204            echo "We won't do anything else !" 
    189205            exit 1 
    190206        fi 
    191         rm ${tmpfile} 
     207        \rm ${tmpfile} 
    192208 
    193209        # The tmpfile uses now the real path of the card to be modified,  
     
    204220 
    205221    else 
    206         echo "--Error--> IGCM_card_WriteOption $@" 
    207         echo "           $1 is not readable or not writable" 
     222        echo 
     223        IGCM_debug_Print 1 "--Error--> IGCM_card_WriteOption $@" 
     224        IGCM_debug_Print 1 "           $1 is not readable or not writable" 
    208225        IGCM_debug_Exit "IGCM_card_WriteOption" 
    209226    fi 
     
    249266    IGCM_debug_PushStack "IGCM_card_WriteArrayOption" $@ 
    250267 
    251     if [ -r "$1" ] && [ -w "$1" ] ; then 
     268    if ( [ -r "$1" ] && [ -w "$1" ]  && [ -f "$1" ] ) ; then 
    252269        typeset tmpfile=tmpfile_$$ 
    253270        if [ X"${4}" != X"" ]; then 
     
    258275        fi 
    259276    else 
    260         echo "--Error--> IGCM_card_WriteArrayOption $@" 
    261         echo "           $1 is not readable or not writable" 
     277        echo 
     278        IGCM_debug_Print 1 "--Error--> IGCM_card_WriteArrayOption $@" 
     279        IGCM_debug_Print 1 "           $1 is not readable or not writable" 
    262280        IGCM_debug_Exit "IGCM_card_WriteArrayOption" 
    263281    fi 
     
    294312    if diff IGCM_card_Test.ref.failed ${libIGCM}/libIGCM_card/IGCM_card_Test.ref > /dev/null 2>&1 ; then  
    295313        echo "Check libIGCM_card ...............................................[ OK ]" 
    296         rm -f IGCM_card_Test.ref.failed 
     314        IGCM_sys_Rm IGCM_card_Test.ref.failed 
    297315    else  
    298316        echo "Check libIGCM_card ...........................................[ FAILED ]" 
Note: See TracChangeset for help on using the changeset viewer.