mirror of
https://github.com/jmagar/unraid-mcp.git
synced 2026-03-01 16:04:24 -08:00
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:
@@ -5,12 +5,25 @@
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
QUERY_SCRIPT="$SCRIPT_DIR/../scripts/unraid-query.sh"
|
||||
|
||||
if [[ ! -x "$QUERY_SCRIPT" ]]; then
|
||||
echo "Error: Query script not found or not executable: $QUERY_SCRIPT" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
QUERY='{ array { disks { name device temp status isSpinning } } }'
|
||||
|
||||
echo "=== Disk Health Report ==="
|
||||
echo ""
|
||||
|
||||
RESPONSE=$("$QUERY_SCRIPT" -q "$QUERY" -f raw)
|
||||
RESPONSE=$("$QUERY_SCRIPT" -q "$QUERY" -f raw) || {
|
||||
echo "Error: Query failed." >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
if [[ -z "$RESPONSE" ]] || ! echo "$RESPONSE" | jq -e . > /dev/null 2>&1; then
|
||||
echo "Error: Invalid or empty response from query." >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "$RESPONSE" | jq -r '.array.disks[] | "\(.name) (\(.device)): \(.temp)°C - \(.status) - \(if .isSpinning then "Spinning" else "Spun down" end)"'
|
||||
|
||||
|
||||
Reference in New Issue
Block a user