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)
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")
SPLITSOURCES_RC=$?
set -e
if [ ${SPLITSOURCES_RC} == 0 ]
then
# echo $OUTPUT
NSOURCES=$((NSOURCES - 1))
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
NSOURCES=$((NSOURCES - 1))
while IFS="" read -r current_file_name
do
testImportExportEquivalence "$current_file_name" "$OUTPUT"
NSOURCES=$((NSOURCES + 1))
done <<< "$OUTPUT"
cd "$WORKINGDIR"
# Delete temporary files

View File

@ -17,14 +17,6 @@ hasMultipleSources = False
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):
if line.find("/") > -1:
filePath = line[13: line.rindex("/")]
@ -57,7 +49,6 @@ def writeSourceToFile(lines):
if __name__ == '__main__':
filePath = sys.argv[1]
sys.excepthook = uncaught_exception_hook
# decide if file has multiple sources
with open(filePath, mode='rb', encoding='utf8', newline='') as f:
@ -71,6 +62,5 @@ if __name__ == '__main__':
for src in createdSources:
srcString += src + ' '
print(srcString)
sys.exit(0)
else:
sys.exit(1)
print(filePath)

View File

@ -38,27 +38,12 @@ function testFile
}
while read -r file; do
set +e
OUTPUT=$($SPLITSOURCES "$file")
RETURN_CODE=$?
set -e
FAILED=0
# NOTE: The command returns the name of the input file if it's not a multi-source file
OUTPUT="$($SPLITSOURCES "$file")"
if [ $RETURN_CODE -eq 0 ]
then
# shellcheck disable=SC2086
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
testFile "$OUTPUT"
FAILED=$?
rm -r "${FILETMP:?}"/* 2> /dev/null || true
if [ $FAILED -eq 1 ]
then