From fef23a929c8e8c0fd348c4b488facbb415ac875e Mon Sep 17 00:00:00 2001 From: Theo Brigitte Date: Sun, 1 Dec 2024 16:15:46 +0100 Subject: [PATCH] More consistent exit codes --- bin/list.sh | 6 +++--- bin/order.sh | 9 ++++----- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/bin/list.sh b/bin/list.sh index dae6360..4c14e6a 100755 --- a/bin/list.sh +++ b/bin/list.sh @@ -80,7 +80,7 @@ main() { ;; *) echo_stderr 'Internal error!' - exit 1 + exit 3 ;; esac done @@ -89,7 +89,7 @@ main() { echo_stderr "Error: COUNTRY is not set" echo_stderr usage - exit 1 + exit 3 fi COUNTRY="${COUNTRY^^}" @@ -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" diff --git a/bin/order.sh b/bin/order.sh index 02e0104..42e1ede 100755 --- a/bin/order.sh +++ b/bin/order.sh @@ -21,7 +21,6 @@ echo_stderr() { jq_stderr() { echo "$@" | $JQ_BIN -cr . 1>&2 - exit } # Helper function - prints an error message and exits @@ -468,7 +467,7 @@ main() { ;; *) echo_stderr 'Internal error!' - exit 1 + exit 3 ;; esac done @@ -477,7 +476,7 @@ main() { echo_stderr "Error: COUNTRY is not set" echo_stderr usage - exit 1 + exit 3 fi COUNTRY="${COUNTRY^^}" @@ -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" @@ -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"