@@ -80,9 +80,11 @@ echo -e "${YELLOW}Fetching latest release information...${NC}"
8080
8181# Try to fetch release info without authentication first (for public repos)
8282LATEST_RELEASE=$( curl -s " https://api.github.com/repos/$REPO /releases/latest" )
83+ CURL_EXIT_CODE=$?
8384
8485# Check if the response indicates authentication is required (private repo)
85- if [ $? -ne 0 ] || [ -z " $LATEST_RELEASE " ] || echo " $LATEST_RELEASE " | grep -q ' "message".*"Not Found"' ; then
86+ # Only try authentication if curl failed OR we got a "Not Found" message OR response is empty
87+ if [ $CURL_EXIT_CODE -ne 0 ] || [ -z " $LATEST_RELEASE " ] || echo " $LATEST_RELEASE " | grep -q ' "message".*"Not Found"' ; then
8688 echo -e " ${BLUE} Repository appears to be private, trying with authentication...${NC} "
8789
8890 # Check if we have GitHub token for private repo access
@@ -105,14 +107,27 @@ if [ $? -ne 0 ] || [ -z "$LATEST_RELEASE" ] || echo "$LATEST_RELEASE" | grep -q
105107
106108 # Retry with authentication
107109 LATEST_RELEASE=$( curl -s -H " Authorization: token $AUTH_HEADER_VALUE " " https://api.github.com/repos/$REPO /releases/latest" )
110+ CURL_EXIT_CODE=$?
108111fi
109112
110- if [ $? -ne 0 ] || [ -z " $LATEST_RELEASE " ]; then
113+ if [ $CURL_EXIT_CODE -ne 0 ] || [ -z " $LATEST_RELEASE " ]; then
111114 echo -e " ${RED} Error: Failed to fetch release information${NC} "
112115 echo " Please check your internet connection and try again."
113116 exit 1
114117fi
115118
119+ # Check if we got a valid response (should contain tag_name)
120+ if ! echo " $LATEST_RELEASE " | grep -q ' "tag_name":' ; then
121+ echo -e " ${RED} Error: Invalid API response received${NC} "
122+
123+ # Check if the response contains an error message
124+ if echo " $LATEST_RELEASE " | grep -q ' "message"' ; then
125+ echo -e " ${RED} GitHub API Error:${NC} "
126+ echo " $LATEST_RELEASE " | grep ' "message"' | sed ' s/.*"message": *"\([^"]*\)".*/\1/'
127+ fi
128+ exit 1
129+ fi
130+
116131# Extract tag name and download URLs
117132TAG_NAME=$( echo " $LATEST_RELEASE " | grep ' "tag_name":' | sed -E ' s/.*"([^"]+)".*/\1/' )
118133DOWNLOAD_URL=" https://github.com/$REPO /releases/download/$TAG_NAME /$DOWNLOAD_BINARY "
@@ -122,6 +137,14 @@ ASSET_URL=$(echo "$LATEST_RELEASE" | grep -B 3 "\"name\": \"$DOWNLOAD_BINARY\""
122137
123138if [ -z " $TAG_NAME " ]; then
124139 echo -e " ${RED} Error: Could not determine latest release version${NC} "
140+ echo -e " ${BLUE} Debug: Full API response:${NC} " >&2
141+ echo " $LATEST_RELEASE " >&2
142+ echo " "
143+ echo " This could mean:"
144+ echo " 1. No releases found in the repository"
145+ echo " 2. API response format is unexpected"
146+ echo " 3. Token doesn't have sufficient permissions"
147+ echo " 4. Repository doesn't exist or is inaccessible"
125148 exit 1
126149fi
127150
0 commit comments