From 97aade2ba5c29a01478cb0586bb9d2aad8faf6d8 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 19 Aug 2025 19:56:09 +0000 Subject: [PATCH 1/5] Initial plan From 6c4b34cacd044d0cb8d3a6386d893634ccce002e Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 19 Aug 2025 20:04:18 +0000 Subject: [PATCH 2/5] Fix jq error in fetch_all_assets function when GitHub API returns empty array Co-authored-by: shenxianpeng <3353385+shenxianpeng@users.noreply.github.com> --- lib/utils.bash | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/lib/utils.bash b/lib/utils.bash index cc716cb..c6fa3cd 100644 --- a/lib/utils.bash +++ b/lib/utils.bash @@ -46,9 +46,24 @@ sort_versions() { } fetch_all_assets() { - curl -s -H "Accept: application/vnd.github.v3+json" \ - https://api.github.com/repos/${GH_REPO}/releases | - jq -r '.[0].assets[] | "\(.name) \(.browser_download_url)"' + local response + response=$(curl -s -H "Accept: application/vnd.github.v3+json" \ + "https://api.github.com/repos/${GH_REPO}/releases") + + # Check if response is valid JSON and has releases + if ! echo "$response" | jq empty 2>/dev/null; then + fail "Failed to fetch releases from GitHub API. Invalid JSON response." + fi + + # Check if there are any releases + local release_count + release_count=$(echo "$response" | jq 'length') + if [ "$release_count" -eq 0 ]; then + fail "No releases found in repository ${GH_REPO}." + fi + + # Extract assets from the first release safely + echo "$response" | jq -r '.[0].assets[]? | "\(.name) \(.browser_download_url)"' } validate_platform() { From d55fbbfd989b2d38fc0a95c28ff47f2306574b88 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 19 Aug 2025 20:13:06 +0000 Subject: [PATCH 3/5] 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 <3353385+shenxianpeng@users.noreply.github.com> --- lib/utils.bash | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/utils.bash b/lib/utils.bash index c6fa3cd..72d36ae 100644 --- a/lib/utils.bash +++ b/lib/utils.bash @@ -50,11 +50,19 @@ fetch_all_assets() { response=$(curl -s -H "Accept: application/vnd.github.v3+json" \ "https://api.github.com/repos/${GH_REPO}/releases") - # Check if response is valid JSON and has releases + # Check if response is valid JSON if ! echo "$response" | jq empty 2>/dev/null; then fail "Failed to fetch releases from GitHub API. Invalid JSON response." fi + # Check if response is an array (releases endpoint returns array) + if ! echo "$response" | jq -e 'type == "array"' >/dev/null 2>&1; then + # Response is not an array, likely an error from GitHub API + local error_message + error_message=$(echo "$response" | jq -r '.message // "Unknown API error"' 2>/dev/null || echo "API returned unexpected format") + fail "GitHub API error: ${error_message}. Please check your network connection and GitHub API status." + fi + # Check if there are any releases local release_count release_count=$(echo "$response" | jq 'length') From f44b895b2f9bc93a2f34ad291adf2ab380527f18 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 19 Aug 2025 21:30:11 +0000 Subject: [PATCH 4/5] Add debug logging to fetch_all_assets function Co-authored-by: shenxianpeng <3353385+shenxianpeng@users.noreply.github.com> --- lib/utils.bash | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/utils.bash b/lib/utils.bash index 72d36ae..acf16c9 100644 --- a/lib/utils.bash +++ b/lib/utils.bash @@ -50,6 +50,10 @@ fetch_all_assets() { response=$(curl -s -H "Accept: application/vnd.github.v3+json" \ "https://api.github.com/repos/${GH_REPO}/releases") + # Debug: Log response type and content for debugging + log "DEBUG: Response type: $(echo "$response" | jq -r 'type' 2>/dev/null || echo 'invalid-json')" + log "DEBUG: Response preview: $(echo "$response" | head -c 200)" + # Check if response is valid JSON if ! echo "$response" | jq empty 2>/dev/null; then fail "Failed to fetch releases from GitHub API. Invalid JSON response." @@ -70,6 +74,8 @@ fetch_all_assets() { fail "No releases found in repository ${GH_REPO}." fi + log "DEBUG: About to extract assets from response" + # Extract assets from the first release safely echo "$response" | jq -r '.[0].assets[]? | "\(.name) \(.browser_download_url)"' } From a4ca60f40a06dd47fd4236e26979608c4a6a8523 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 19 Aug 2025 21:32:17 +0000 Subject: [PATCH 5/5] Use defensive jq command to prevent array indexing errors Co-authored-by: shenxianpeng <3353385+shenxianpeng@users.noreply.github.com> --- lib/utils.bash | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/lib/utils.bash b/lib/utils.bash index acf16c9..d44340a 100644 --- a/lib/utils.bash +++ b/lib/utils.bash @@ -50,10 +50,6 @@ fetch_all_assets() { response=$(curl -s -H "Accept: application/vnd.github.v3+json" \ "https://api.github.com/repos/${GH_REPO}/releases") - # Debug: Log response type and content for debugging - log "DEBUG: Response type: $(echo "$response" | jq -r 'type' 2>/dev/null || echo 'invalid-json')" - log "DEBUG: Response preview: $(echo "$response" | head -c 200)" - # Check if response is valid JSON if ! echo "$response" | jq empty 2>/dev/null; then fail "Failed to fetch releases from GitHub API. Invalid JSON response." @@ -74,10 +70,9 @@ fetch_all_assets() { fail "No releases found in repository ${GH_REPO}." fi - log "DEBUG: About to extract assets from response" - - # Extract assets from the first release safely - echo "$response" | jq -r '.[0].assets[]? | "\(.name) \(.browser_download_url)"' + # Extract assets from the first release safely with built-in type checking + # This provides additional protection against edge cases + echo "$response" | jq -r 'if type == "array" and length > 0 then .[0].assets[]? | "\(.name) \(.browser_download_url)" else empty end' } validate_platform() {