Skip to content

Commit

Permalink
More consistent exit codes
Browse files Browse the repository at this point in the history
  • Loading branch information
TheoBrigitte committed Dec 1, 2024
1 parent 9c04975 commit fef23a9
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
6 changes: 3 additions & 3 deletions bin/list.sh
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ main() {
;;
*)
echo_stderr 'Internal error!'
exit 1
exit 3
;;
esac
done
Expand All @@ -89,7 +89,7 @@ main() {
echo_stderr "Error: COUNTRY is not set"
echo_stderr
usage
exit 1
exit 3
fi
COUNTRY="${COUNTRY^^}"

Expand All @@ -112,7 +112,7 @@ main() {
# Check for error: empty data, invalid json, or empty list
if test -z "$DATA" || ! echo "$DATA" | $JQ_BIN -e . &>/dev/null || echo "$DATA" | $JQ_BIN -e '.plans | length == 0' &>/dev/null; then
echo_stderr "> failed to fetch data from $OVH_URL"
exit 1
exit 2
fi
echo "> fetched servers"

Expand Down
9 changes: 4 additions & 5 deletions bin/order.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ echo_stderr() {

jq_stderr() {
echo "$@" | $JQ_BIN -cr . 1>&2
exit
}

# Helper function - prints an error message and exits
Expand Down Expand Up @@ -468,7 +467,7 @@ main() {
;;
*)
echo_stderr 'Internal error!'
exit 1
exit 3
;;
esac
done
Expand All @@ -477,7 +476,7 @@ main() {
echo_stderr "Error: COUNTRY is not set"
echo_stderr
usage
exit 1
exit 3
fi
COUNTRY="${COUNTRY^^}"

Expand All @@ -498,7 +497,7 @@ main() {
cart_id="$(echo "$cart" | $JQ_BIN -r .cartId)"
if [ -z "$cart_id" ]; then
echo_stderr "cart_id is empty"
exit 1
exit 3
fi
echo "> cart created id=$cart_id"

Expand All @@ -521,7 +520,7 @@ main() {
item_id="$(echo "$cart_updated" | $JQ_BIN -r .itemId)"
if [ -z "$item_id" ]; then
echo_stderr "> item_id is empty"
exit 1
exit 3
fi
echo "> cart updated with item id=$item_id"

Expand Down

0 comments on commit fef23a9

Please sign in to comment.