File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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 {
You can’t perform that action at this time.
0 commit comments