nikcli upgrade fails on Windows: locked self-binary + swallowed Effect error (diagnosis & fix)
#187
SandroHub013
started this conversation in
General
Replies: 1 comment
|
/nikcli di che e fixata e mostra da che pr |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
nikcli upgradefails on Windows — locked self-binary + swallowed errorA detailed diagnosis and fix for the Windows self-upgrade failure. Verified reproducible on Windows with the standalone (curl) install.
Symptom
Running
nikcli upgrade(when a newer version exists) fails with a generic, unhelpful message:Root cause — two bugs, stacked
1. The self-binary is locked (the real failure)
On
win32,resolveUpgradeStrategyruns the PowerShell installer:The installer (
install.ps1) replacesnikcli.exewith a directCopy-Item. Butnikcli upgradeis itself the runningnikcli.exe, and Windows holds an image lock on it — so the copy fails:The installer then
exit 1.2. The real error is swallowed by
Effect.tryPromise(the bad message)The install layer wraps
upgradeImplin a baretryPromise:Effect.tryPromise(() => fn)wraps any thrown error in anUnknownException. So the typedUpgradeFailedError(which carries the useful message) is lost, and the handler incli/cmd/upgrade.ts……never matches and prints the generic Effect text instead of the actual reason.
The fix
A.
install.ps1(root +packages/web/public/install.ps1) — handle the locked binaryWindows lets you rename a running executable but not overwrite/delete it. So before copying, move the in-use binary aside:
Plus, at the start of the installer, clean up binaries left aside by previous runs (now that their owning process has exited):
Also:
Failnow writes to stderr too ([Console]::Error.WriteLine), so the message is captured even when the PowerShell host discardsWrite-Host.B.
packages/nikcli/src/installation/index.ts— preserve the typed errorAnd capture the installer output from whichever stream actually carries it (the PowerShell installer reports via
Write-Host→ stdout, not stderr):Verification
nikcli serveto hold the real image lock onnikcli.exe, ran the patched installer → succeeded (rename-aside), where the old installer failed. Binary restored afterwards.An error occurred in Effect.tryPromise. After: the real installer output —x Failed to download nikcli-ai-windows-x64.zip.nikcli.execan beMove-Item'd on Windows (the basis of the fix), unlike a plainFileStreamlock.toUpgradeError(preservesUpgradeFailedErrorby identity, wraps plainError, stringifies non-Error).bun test test/installation/effect-service.test.ts→ 27 pass / 0 fail.solid-js/storeerrors inpackages/pluginare unrelated).Notes
nikcli.exe.olduntil it exits; the.oldis removed on the next install/launch. This is expected and safe.install.ps1must be redeployed tonikcli.store/install.ps1, and a new release must be cut so the compiled binary contains theinstallation/index.tschange.Files changed
install.ps1·packages/web/public/install.ps1—Install-Filerename-aside, stale-.oldcleanup,Fail→ stderr, cache-bust.packages/nikcli/src/installation/index.ts—toUpgradeError,tryPromise({try,catch}), stdout/stderr capture.packages/nikcli/test/installation/effect-service.test.ts— coverage fortoUpgradeError.Happy to open a PR with these changes if that's useful.
All reactions