Simplify error handling

This commit is contained in:
Kamil Śliwak 2020-11-17 17:39:43 +01:00
parent 1a8683597f
commit 3bd071d4e4
3 changed files with 13 additions and 56 deletions

View File

@ -104,32 +104,14 @@ do
FILETMP=$(mktemp -d) FILETMP=$(mktemp -d)
cd "$FILETMP" cd "$FILETMP"
set +e # NOTE: The command returns the name of the input file if it's not a multi-source file
OUTPUT=$("$SPLITSOURCES" "$solfile") OUTPUT=$("$SPLITSOURCES" "$solfile")
SPLITSOURCES_RC=$? NSOURCES=$((NSOURCES - 1))
set -e while IFS="" read -r current_file_name
if [ ${SPLITSOURCES_RC} == 0 ] do
then testImportExportEquivalence "$current_file_name" "$OUTPUT"
# echo $OUTPUT NSOURCES=$((NSOURCES + 1))
NSOURCES=$((NSOURCES - 1)) done <<< "$OUTPUT"
for i in $OUTPUT;
do
testImportExportEquivalence "$i" "$OUTPUT"
NSOURCES=$((NSOURCES + 1))
done
elif [ ${SPLITSOURCES_RC} == 1 ]
then
testImportExportEquivalence "$solfile"
else
# All other return codes will be treated as critical errors. The script will exit.
echo -e "\nGot unexpected return code ${SPLITSOURCES_RC} from ${SPLITSOURCES}. Aborting."
cd "$WORKINGDIR"
# Delete temporary files
rm -rf "$FILETMP"
exit 1
fi
cd "$WORKINGDIR" cd "$WORKINGDIR"
# Delete temporary files # Delete temporary files

View File

@ -17,14 +17,6 @@ hasMultipleSources = False
createdSources = [] createdSources = []
def uncaught_exception_hook(exc_type, exc_value, exc_traceback):
# The script `scripts/ASTImportTest.sh` will interpret return code 3
# as a critical error (because of the uncaught exception) and will
# terminate further execution.
print("Unhandled exception: %s", "".join(traceback.format_exception(exc_type, exc_value, exc_traceback)), file=sys.stderr)
sys.exit(3)
def extractSourceName(line): def extractSourceName(line):
if line.find("/") > -1: if line.find("/") > -1:
filePath = line[13: line.rindex("/")] filePath = line[13: line.rindex("/")]
@ -57,7 +49,6 @@ def writeSourceToFile(lines):
if __name__ == '__main__': if __name__ == '__main__':
filePath = sys.argv[1] filePath = sys.argv[1]
sys.excepthook = uncaught_exception_hook
# decide if file has multiple sources # decide if file has multiple sources
with open(filePath, mode='rb', encoding='utf8', newline='') as f: with open(filePath, mode='rb', encoding='utf8', newline='') as f:
@ -71,6 +62,5 @@ if __name__ == '__main__':
for src in createdSources: for src in createdSources:
srcString += src + ' ' srcString += src + ' '
print(srcString) print(srcString)
sys.exit(0)
else: else:
sys.exit(1) print(filePath)

View File

@ -38,27 +38,12 @@ function testFile
} }
while read -r file; do while read -r file; do
set +e # NOTE: The command returns the name of the input file if it's not a multi-source file
OUTPUT=$($SPLITSOURCES "$file") OUTPUT="$($SPLITSOURCES "$file")"
RETURN_CODE=$?
set -e
FAILED=0
if [ $RETURN_CODE -eq 0 ] testFile "$OUTPUT"
then FAILED=$?
# shellcheck disable=SC2086 rm -r "${FILETMP:?}"/* 2> /dev/null || true
testFile $OUTPUT
FAILED=$?
rm -r "${FILETMP:?}"/*
elif [ $RETURN_CODE -eq 1 ]
then
testFile "$file"
FAILED=$?
else
# NOTE: The split script is expected to print error details to stderr in this case.
echo "$SPLITSOURCES exited with code $RETURN_CODE while processing $file."
exit 3
fi
if [ $FAILED -eq 1 ] if [ $FAILED -eq 1 ]
then then