fix: harden shell scripts with error handling and null guards

- dashboard.sh: Add // [] jq null guard on .data.array.disks[] (L176-177)
  Resolves review thread PRRT_kwDOO6Hdxs5uvO21

- dashboard.sh: Default NAME to server key when env var unset (L221)
  Resolves review thread PRRT_kwDOO6Hdxs5uvO22

- unraid-query.sh: Check curl exit code, empty response, and JSON validity
  before piping to jq (L112-129)
  Resolves review thread PRRT_kwDOO6Hdxs5uvO24

- disk-health.sh: Guard against missing query script and invalid responses
  Resolves review thread PRRT_kwDOO6Hdxs5uvKrh
This commit is contained in:
Jacob Magar
2026-02-15 23:01:40 -05:00
parent fb86097709
commit c7ed077bb5
3 changed files with 32 additions and 5 deletions

View File

@@ -112,7 +112,21 @@ CURL_FLAGS=("-sL" "-X" "POST")
RESPONSE=$(curl "${CURL_FLAGS[@]}" "$URL" \
-H "Content-Type: application/json" \
-H "x-api-key: $API_KEY" \
-d "$PAYLOAD")
-d "$PAYLOAD") || {
echo "Error: curl request failed (exit code $?). Check URL and network connectivity." >&2
exit 1
}
if [[ -z "$RESPONSE" ]]; then
echo "Error: Empty response from server." >&2
exit 1
fi
if ! echo "$RESPONSE" | jq -e . > /dev/null 2>&1; then
echo "Error: Server returned invalid JSON. Response:" >&2
echo "$RESPONSE" | head -c 500 >&2
exit 1
fi
# Check for errors
if echo "$RESPONSE" | jq -e '.errors' > /dev/null 2>&1; then