Skip to content

Commit d55fbbf

Browse files
Copilotshenxianpeng
andcommitted
Fix jq error when GitHub API returns object instead of array
- Add check to verify response is array before indexing with [0] - Handle GitHub API error objects (rate limits, auth errors, etc.) - Extract error messages from API response for better debugging - Resolves "Cannot index object with number" jq error Co-authored-by: shenxianpeng <[email protected]>
1 parent 6c4b34c commit d55fbbf

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

lib/utils.bash

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,19 @@ fetch_all_assets() {
5050
response=$(curl -s -H "Accept: application/vnd.github.v3+json" \
5151
"https://api.github.com/repos/${GH_REPO}/releases")
5252

53-
# Check if response is valid JSON and has releases
53+
# Check if response is valid JSON
5454
if ! echo "$response" | jq empty 2>/dev/null; then
5555
fail "Failed to fetch releases from GitHub API. Invalid JSON response."
5656
fi
5757

58+
# Check if response is an array (releases endpoint returns array)
59+
if ! echo "$response" | jq -e 'type == "array"' >/dev/null 2>&1; then
60+
# Response is not an array, likely an error from GitHub API
61+
local error_message
62+
error_message=$(echo "$response" | jq -r '.message // "Unknown API error"' 2>/dev/null || echo "API returned unexpected format")
63+
fail "GitHub API error: ${error_message}. Please check your network connection and GitHub API status."
64+
fi
65+
5866
# Check if there are any releases
5967
local release_count
6068
release_count=$(echo "$response" | jq 'length')

0 commit comments

Comments
 (0)