Skip to content

Node-based terminal manager for AI coding agents — tmux-backed terminals and parallel agent sessions as draggable nodes on an infinite pan/zoom canvas. macOS, Linux, and a browser Server Edition.

fix(windows): keep the update-failed note valid JSON when nsExec answers error/timeout

reviewd6219a3fe018
diff --git a/build/installer.nsh b/build/installer.nsh
index 2905c8109..635bb9eef 100644
--- a/build/installer.nsh
+++ b/build/installer.nsh
@@ -48,7 +48,9 @@
ClearErrors
FileOpen $R3 "$R2\nodeterm\update-failed.json" w
${IfNot} ${Errors}
- FileWrite $R3 '{"reason":"preflight","code":$R0,"version":"${VERSION}"}'
+ # $R0 is quoted: nsExec answers "error" / "timeout" instead of an exit code when
+ # PowerShell could not run, and a bare word there would make the whole note invalid JSON.
+ FileWrite $R3 '{"reason":"preflight","code":"$R0","version":"${VERSION}"}'
FileClose $R3
${EndIf}
${EndIf}
diff --git a/scripts/windows-update-preflight.test.ts b/scripts/windows-update-preflight.test.ts
index ceedbabdc..00dacf0a4 100644
--- a/scripts/windows-update-preflight.test.ts
+++ b/scripts/windows-update-preflight.test.ts
@@ -111,6 +111,8 @@ describe('NSIS safety wiring', () => {
expect(unattended).toMatch(/\$\{If\} \$\{isUpdated\}/)
expect(unattended).toContain('ReadEnvStr $R2 LOCALAPPDATA')
expect(unattended).toContain('"$R2\\nodeterm\\update-failed.json"')
+ // nsExec can answer "error"/"timeout" instead of a number: the code must be a JSON string.
+ expect(unattended).toContain('"code":"$R0"')
const marker = unattended.indexOf('FileWrite')
const exec = unattended.indexOf('Exec \'"$INSTDIR\\${APP_EXECUTABLE_FILENAME}"\'')
expect(marker).toBeGreaterThan(0)
diff --git a/src/main/update-install-marker.test.ts b/src/main/update-install-marker.test.ts
index 8c736e0d8..644836de5 100644
--- a/src/main/update-install-marker.test.ts
+++ b/src/main/update-install-marker.test.ts
@@ -60,6 +60,23 @@ describe('update-failed marker (U6)', () => {
expect(f.removed).toEqual([FILE])
})
+ it('reads the code the installer actually writes: a quoted exit code, or nsExec\'s error word', () => {
+ expect(
+ consumeUpdateFailedMarker({
+ platform: 'win32',
+ localAppData: LAD,
+ ...fakeFs('{"reason":"preflight","code":"10","version":"0.4.5"}')
+ })
+ ).toEqual({ reason: 'preflight', code: 10, version: '0.4.5' })
+ expect(
+ consumeUpdateFailedMarker({
+ platform: 'win32',
+ localAppData: LAD,
+ ...fakeFs('{"reason":"preflight","code":"timeout","version":"0.4.5"}')
+ })
+ ).toEqual({ reason: 'preflight (timeout)', code: null, version: '0.4.5' })
+ })
+
it('says why in one line', () => {
expect(describeUpdateInstallFailure({ reason: 'preflight', code: 10, version: '0.4.5' })).toMatch(
/update to 0\.4\.5 did not install: nodeterm was still running/
diff --git a/src/main/update-install-marker.ts b/src/main/update-install-marker.ts
index b4b3f277d..1261f2238 100644
--- a/src/main/update-install-marker.ts
+++ b/src/main/update-install-marker.ts
@@ -54,9 +54,22 @@ export function consumeUpdateFailedMarker(deps: MarkerDeps): UpdateInstallFailur
} catch {
/* existence is the fact */
}
+ // The installer writes `code` as a STRING (nsExec answers `error` / `timeout` instead of an
+ // exit code when PowerShell could not run); a number is accepted too.
+ const rawCode = parsed.code
+ const code =
+ Number.isInteger(rawCode)
+ ? (rawCode as number)
+ : typeof rawCode === 'string' && /^\d{1,9}$/.test(rawCode)
+ ? Number(rawCode)
+ : null
+ const reason = typeof parsed.reason === 'string' ? parsed.reason : 'unknown'
return {
- reason: typeof parsed.reason === 'string' ? parsed.reason : 'unknown',
- code: Number.isInteger(parsed.code) ? (parsed.code as number) : null,
+ reason:
+ code === null && typeof rawCode === 'string' && /^[\w-]{1,32}$/.test(rawCode)
+ ? `${reason} (${rawCode})`
+ : reason,
+ code,
version: typeof parsed.version === 'string' ? parsed.version : null
}
}