Skip to content

Commit 328da7e

Browse files
committed
fix(policy): add EBUSY fallback and TOML parse recovery (google-gemini#19919)
1 parent 9c417c2 commit 328da7e

1 file changed

Lines changed: 15 additions & 3 deletions

File tree

packages/core/src/policy/config.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -548,9 +548,18 @@ export function createPolicyUpdater(
548548
} catch (error) {
549549
if (isNodeError(error) && error.code === 'ENOENT') {
550550
// File doesn't exist yet, start fresh
551+
} else if (!isNodeError(error)) {
552+
// TOML parse error — back up corrupted file and recover
553+
coreEvents.emitFeedback(
554+
'warning',
555+
`Syntax error found in policy file. Backing up corrupted file to ${policyFile}.bak and starting fresh.`,
556+
);
557+
await fs
558+
.copyFile(policyFile, `${policyFile}.bak`)
559+
.catch(() => {});
560+
existingData = {};
551561
} else {
552-
// Non-ENOENT read errors (e.g. EACCES) should abort persistence
553-
// to avoid silently overwriting the existing file with empty data
562+
// Real filesystem error (e.g. EACCES) — throw to prevent silent failure
554563
throw error;
555564
}
556565
}
@@ -612,7 +621,10 @@ export function createPolicyUpdater(
612621
} catch (renameError) {
613622
// Cross-device rename fails with EXDEV on some Linux mount configurations.
614623
// Fall back to copy + unlink which works across filesystems.
615-
if (isNodeError(renameError) && renameError.code === 'EXDEV') {
624+
if (
625+
isNodeError(renameError) &&
626+
(renameError.code === 'EXDEV' || renameError.code === 'EBUSY')
627+
) {
616628
await fs.copyFile(tmpFile, policyFile);
617629
await fs.unlink(tmpFile).catch(() => {});
618630
} else {

0 commit comments

Comments
 (0)