Skip to content

Commit ec3f928

Browse files
zerone0xclaude
andcommitted
fix: validate version exists before upgrade
When upgrading to a specific version with `opencode upgrade <version>`, the command now validates that the version exists before attempting the upgrade. This prevents the false "Upgrade complete" message when users specify non-existent versions. For npm/pnpm/bun: Checks if the version exists in the npm registry For brew: Explains that only the latest version is available For curl: Validates against GitHub releases Fixes anomalyco#8422 Co-Authored-By: Claude <[email protected]>
1 parent 09ff3b9 commit ec3f928

2 files changed

Lines changed: 60 additions & 4 deletions

File tree

‎packages/opencode/src/cli/cmd/upgrade.ts‎

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,18 +50,40 @@ export const UpgradeCommand = {
5050
return
5151
}
5252

53+
// Validate version exists before attempting upgrade
54+
if (args.target) {
55+
const spinner = prompts.spinner()
56+
spinner.start("Checking version availability...")
57+
const exists = await Installation.versionExists(target, method)
58+
if (!exists) {
59+
spinner.stop("Version not found", 1)
60+
if (method === "brew") {
61+
prompts.log.error(`Version ${target} is not available via brew. Only the latest version can be installed.`)
62+
const latestVersion = await Installation.latest(method).catch(() => null)
63+
if (latestVersion) {
64+
prompts.log.info(`Available version: ${latestVersion}`)
65+
}
66+
} else {
67+
prompts.log.error(`Version ${target} was not found. Please check the version number and try again.`)
68+
}
69+
prompts.outro("Done")
70+
return
71+
}
72+
spinner.stop("Version available")
73+
}
74+
5375
prompts.log.info(`From ${Installation.VERSION} → ${target}`)
54-
const spinner = prompts.spinner()
55-
spinner.start("Upgrading...")
76+
const upgradeSpinner = prompts.spinner()
77+
upgradeSpinner.start("Upgrading...")
5678
const err = await Installation.upgrade(method, target).catch((err) => err)
5779
if (err) {
58-
spinner.stop("Upgrade failed", 1)
80+
upgradeSpinner.stop("Upgrade failed", 1)
5981
if (err instanceof Installation.UpgradeFailedError) prompts.log.error(err.data.stderr)
6082
else if (err instanceof Error) prompts.log.error(err.message)
6183
prompts.outro("Done")
6284
return
6385
}
64-
spinner.stop("Upgrade complete")
86+
upgradeSpinner.stop("Upgrade complete")
6587
prompts.outro("Done")
6688
},
6789
}

‎packages/opencode/src/installation/index.ts‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,4 +202,38 @@ export namespace Installation {
202202
})
203203
.then((data: any) => data.tag_name.replace(/^v/, ""))
204204
}
205+
206+
export const VersionNotFoundError = NamedError.create(
207+
"VersionNotFoundError",
208+
z.object({
209+
version: z.string(),
210+
method: z.string(),
211+
}),
212+
)
213+
214+
export async function versionExists(version: string, installMethod?: Method): Promise<boolean> {
215+
const detectedMethod = installMethod || (await method())
216+
217+
if (detectedMethod === "brew") {
218+
// Brew doesn't support installing specific versions easily
219+
// Only the current formula version is available
220+
const latestVersion = await latest(detectedMethod).catch(() => null)
221+
return version === latestVersion
222+
}
223+
224+
if (detectedMethod === "npm" || detectedMethod === "bun" || detectedMethod === "pnpm") {
225+
const registry = await iife(async () => {
226+
const r = (await $`npm config get registry`.quiet().nothrow().text()).trim()
227+
const reg = r || "https://registry.npmjs.org"
228+
return reg.endsWith("/") ? reg.slice(0, -1) : reg
229+
})
230+
// Check if the specific version exists
231+
const res = await fetch(`${registry}/opencode-ai/${version}`)
232+
return res.ok
233+
}
234+
235+
// For curl method, check GitHub releases
236+
const res = await fetch(`https://api.github.com/repos/anomalyco/opencode/releases/tags/v${version}`)
237+
return res.ok
238+
}
205239
}

0 commit comments

Comments
 (0)