multicurl: fix cat: '': No such file or directory when called without -o

$temp_file is only created when curl is invoked with -o (the -o loop
above), but the post-success null/error check always ran `cat "$temp_file"`.
When a caller omits -o (e.g. check-health.sh's Cosmos reference RPC), the
variable is empty, so bash executed `cat ""` and printed
"cat: '': No such file or directory" — once per show-status run.

In that no-o case the body is already captured in $output, so read the
response from $output when $temp_file is unset, and from $temp_file when
it exists. Behaviour with -o is unchanged; the result==null / JSON-RPC
error skip-to-next-URL fallback is preserved in both paths.

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2026-07-06 14:00:11 +00:00
parent ea15f31844
commit 57db6a16fa

View File

@@ -47,7 +47,14 @@ for url in "${urls[@]}"; do
# null result (a lagging endpoint that doesn't have the requested block/data yet).
# Without the result==null check the first endpoint's {"result":null} was accepted as
# success and the remaining fallback URLs were never tried.
if cat "$temp_file" | jq -e 'has("error") or (.result == null)' > /dev/null 2>&1; then
# $temp_file only exists when curl was called with -o (see the -o loop above).
# When a caller omits -o, the body is already in $output, so reading cat "" would
# emit "cat: '': No such file or directory". Read from whichever place holds the body.
response_body="$output"
if [ -n "$temp_file" ]; then
response_body=$(cat "$temp_file")
fi
if echo "$response_body" | jq -e 'has("error") or (.result == null)' > /dev/null 2>&1; then
continue # Try the next URL
fi