summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorCodinCat <[email protected]>2025-07-15 09:13:12 +0900
committerGitHub <[email protected]>2025-07-14 20:13:12 -0400
commitd6eff3b3a31192b3c37e03ebff278cbc8ace2023 (patch)
treebce1fab86d950a24658d45135a9041fa38ef6766
parente63a6d45c1e473c10dd7d5db75b06cba4953a1bc (diff)
downloadopencode-d6eff3b3a31192b3c37e03ebff278cbc8ace2023.tar.gz
opencode-d6eff3b3a31192b3c37e03ebff278cbc8ace2023.zip
improve error handling and logging for GitHub API failures in upgrade and install script (#972)
-rwxr-xr-xinstall2
-rw-r--r--packages/opencode/src/installation/index.ts8
2 files changed, 8 insertions, 2 deletions
diff --git a/install b/install
index e18bd7bbf..2a48cc1f4 100755
--- a/install
+++ b/install
@@ -48,7 +48,7 @@ if [ -z "$requested_version" ]; then
url="https://github.com/sst/opencode/releases/latest/download/$filename"
specific_version=$(curl -s https://api.github.com/repos/sst/opencode/releases/latest | awk -F'"' '/"tag_name": "/ {gsub(/^v/, "", $4); print $4}')
- if [[ $? -ne 0 ]]; then
+ if [[ $? -ne 0 || -z "$specific_version" ]]; then
echo "${RED}Failed to fetch version information${NC}"
exit 1
fi
diff --git a/packages/opencode/src/installation/index.ts b/packages/opencode/src/installation/index.ts
index 9dfe22432..ab631a8d2 100644
--- a/packages/opencode/src/installation/index.ts
+++ b/packages/opencode/src/installation/index.ts
@@ -140,6 +140,12 @@ export namespace Installation {
export async function latest() {
return fetch("https://api.github.com/repos/sst/opencode/releases/latest")
.then((res) => res.json())
- .then((data) => data.tag_name.slice(1) as string)
+ .then((data) => {
+ if (typeof data.tag_name !== "string") {
+ log.error("GitHub API error", data)
+ throw new Error("failed to fetch latest version")
+ }
+ return data.tag_name.slice(1) as string
+ })
}
}