@@ -7,32 +7,43 @@ export async function clearAccountStorageArtifacts(params: {
77 backupPaths : string [ ] ;
88 logError : ( message : string , details : Record < string , unknown > ) => void ;
99} ) : Promise < void > {
10- await fs . writeFile (
11- params . resetMarkerPath ,
12- JSON . stringify ( { version : 1 , createdAt : Date . now ( ) } ) ,
13- { encoding : "utf-8" , mode : 0o600 } ,
14- ) ;
15- const clearPath = async ( targetPath : string ) : Promise < void > => {
10+ const clearPath = async (
11+ targetPath : string ,
12+ required : boolean ,
13+ ) : Promise < void > => {
1614 try {
1715 await fs . unlink ( targetPath ) ;
1816 } catch ( error ) {
1917 const code = ( error as NodeJS . ErrnoException ) . code ;
20- if ( code !== "ENOENT" ) {
18+ if ( code === "ENOENT" ) {
19+ return ;
20+ }
21+ if ( required ) {
2122 params . logError ( "Failed to clear account storage artifact" , {
2223 path : targetPath ,
2324 error : String ( error ) ,
2425 } ) ;
26+ throw error ;
2527 }
28+ params . logError ( "Failed to clear account storage artifact" , {
29+ path : targetPath ,
30+ error : String ( error ) ,
31+ } ) ;
2632 }
2733 } ;
2834
29- try {
30- await Promise . all ( [
31- clearPath ( params . path ) ,
32- clearPath ( params . walPath ) ,
33- ...params . backupPaths . map ( clearPath ) ,
34- ] ) ;
35- } catch {
36- // Individual path cleanup is already best-effort with per-artifact logging.
35+ await clearPath ( params . path , true ) ;
36+ await clearPath ( params . walPath , true ) ;
37+ await fs . writeFile (
38+ params . resetMarkerPath ,
39+ JSON . stringify ( { version : 1 , createdAt : Date . now ( ) } ) ,
40+ { encoding : "utf-8" , mode : 0o600 } ,
41+ ) ;
42+ for ( const backupPath of params . backupPaths ) {
43+ try {
44+ await clearPath ( backupPath , false ) ;
45+ } catch {
46+ // Non-critical artifacts are already logged best-effort.
47+ }
3748 }
3849}
0 commit comments