Skip to content

Commit 656f299

Browse files
BB-84Crekram1-node
andauthored
fix(core): tolerate AlreadyExists in FSUtil.ensureDir (anomalyco#36542)
Co-authored-by: Aiden Cline <aidenpcline@gmail.com>
1 parent 04bdf77 commit 656f299

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

packages/core/src/fs-util.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,14 @@ export namespace FSUtil {
114114
})
115115

116116
const ensureDir = Effect.fn("FileSystem.ensureDir")(function* (path: string) {
117-
yield* fs.makeDirectory(path, { recursive: true })
117+
yield* fs.makeDirectory(path, { recursive: true }).pipe(
118+
// Bun on Windows can throw EEXIST here despite recursive mode.
119+
// https://github.com/oven-sh/bun/issues/21901
120+
Effect.catchIf(
121+
(error) => error.reason._tag === "AlreadyExists",
122+
(error) => isDir(path).pipe(Effect.flatMap((exists) => (exists ? Effect.void : Effect.fail(error)))),
123+
),
124+
)
118125
})
119126

120127
const writeWithDirs = Effect.fn("FileSystem.writeWithDirs")(function* (

0 commit comments

Comments
 (0)