Skip to content

Commit

Permalink
Adjust exit codes
Browse files Browse the repository at this point in the history
  • Loading branch information
Tom Scavo committed Oct 22, 2016
1 parent bb4bb31 commit e0ed764
Showing 1 changed file with 17 additions and 15 deletions.
32 changes: 17 additions & 15 deletions bin/http_xsltproc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,8 @@ if [ ! -d "$CACHE_DIR" ]; then
/bin/mkdir "$CACHE_DIR"
exit_code=$?
if [ $exit_code -ne 0 ]; then
echo "ERROR: $script_name failed to create dir: $CACHE_DIR" >&2
exit $exit_code
echo "ERROR: $script_name failed to create dir $CACHE_DIR (exit code: $exit_code)" >&2
exit 2
fi
fi
$verbose_mode && printf "$script_name using cache directory: %s\n" "$CACHE_DIR"
Expand All @@ -210,8 +210,8 @@ for lib_filename in $LIB_FILENAMES; do
source "$lib_file" >&2
exit_code=$?
if [ $exit_code -ne 0 ]; then
echo "ERROR: $script_name failed to source script $lib_file" >&2
exit $exit_code
echo "ERROR: $script_name failed to source script $lib_file (exit code: $exit_code)" >&2
exit 2
fi
done

Expand All @@ -233,10 +233,10 @@ else
fi
if [ ! -d "$TMP_DIR" ]; then
/bin/mkdir "$TMP_DIR"
exit_status=$?
if [ $exit_status -ne 0 ]; then
echo "ERROR: $script_name failed to create dir: $TMP_DIR" >&2
exit $exit_status
exit_code=$?
if [ $exit_code -ne 0 ]; then
echo "ERROR: $script_name failed to create dir $TMP_DIR (exit code: $exit_code)" >&2
exit 2
fi
fi

Expand All @@ -253,8 +253,10 @@ $verbose_mode && printf "$script_name requesting resource: %s\n" "$xml_location"
conditional_get $local_opts -d "$CACHE_DIR" -t "$TMP_DIR" "$xml_location" > "$xml_file"
exit_code=$?
if [ $exit_code -ne 0 ]; then
echo "ERROR: $script_name failed to get resource: $location" >&2
printf "See output log: %s\n" "$TMP_DIR/$conditional_get_log" >&2
if [ $exit_code -gt 1 ]; then
echo "ERROR: $script_name failed to get resource: $location" >&2
printf "See output log: %s\n" "$TMP_DIR/$conditional_get_log" >&2
fi
exit $exit_code
fi
$verbose_mode && printf "$script_name successfully obtained XML file: %s\n" "$xml_file"
Expand All @@ -265,24 +267,24 @@ $verbose_mode && printf "$script_name writing xsltproc output to file: %s\n" "$x
exit_code=$?
if [ $exit_code -ne 0 ]; then
echo "ERROR: ${script_name}: xsltproc failed with status code: $exit_code" >&2
exit $exit_code
exit 3
fi
$verbose_mode && printf "$script_name successfully executed xsltproc\n"

if [ -z "$out_file" ]; then
/bin/cat "$xsltproc_out_file"
exit_code=$?
if [ $exit_code -ne 0 ]; then
echo "ERROR: ${script_name} unable to cat output to stdout" >&2
exit $exit_code
echo "ERROR: ${script_name} unable to cat output with status code: $exit_code" >&2
exit 3
fi
else
$verbose_mode && printf "$script_name writing output to file: %s\n" "$out_file"
/bin/cp "$xsltproc_out_file" "$out_file"
exit_code=$?
if [ $exit_code -ne 0 ]; then
echo "ERROR: ${script_name} unable to copy output to file: $out_file" >&2
exit $exit_code
echo "ERROR: ${script_name} unable to copy output to file $out_file (exit code: $exit_code)" >&2
exit 3
fi
fi

Expand Down

0 comments on commit e0ed764

Please sign in to comment.