Skip to content

Commit 85e7833

Browse files
committed
fix(token): handle corrupted token file by unlinking before O_EXCL create
When the token file exists but contains invalid data (corrupted), the O_EXCL flag on the new file creation fails with EEXIST since the corrupt file is still on disk. Fix: unlink the corrupt file before attempting to create a new one. Found during UAT on Windows.
1 parent ffbfbbd commit 85e7833

1 file changed

Lines changed: 2 additions & 1 deletion

File tree

src/token.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,9 @@ export function getOrCreateToken(): string {
5555
try {
5656
const existing = fs.readFileSync(TOKEN_PATH, 'utf-8').trim();
5757
if (TOKEN_REGEX.test(existing)) return existing;
58-
// File exists but is corrupted — will be recreated below
58+
// File exists but is corrupted — remove it so O_EXCL create succeeds
5959
console.error('[token] Token file corrupted, regenerating');
60+
try { fs.unlinkSync(TOKEN_PATH); } catch { /* already gone */ }
6061
} catch {
6162
// File doesn't exist or can't be read — create a new one
6263
}

0 commit comments

Comments
 (0)