Skip to content

Commit 01baedc

Browse files
committed
fix(ci): deduplicate volatile file helpers
1 parent 653af06 commit 01baedc

File tree

2 files changed

+14
-24
lines changed

2 files changed

+14
-24
lines changed

packages/app/src/lib/usecases/volatile-files.ts

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,27 +8,22 @@ const volatileWriteRetryAttempts = 5
88
export const isNotFoundSystemError = (error: PlatformError): boolean =>
99
error._tag === "SystemError" && error.reason === "NotFound"
1010

11+
const succeedNullOnNotFound = (error: PlatformError): Effect.Effect<null, PlatformError> =>
12+
isNotFoundSystemError(error)
13+
? Effect.succeed(null)
14+
: Effect.fail(error)
15+
1116
export const statIfPresent = (
1217
fs: FileSystem.FileSystem,
1318
targetPath: string
1419
): Effect.Effect<FileSystem.File.Info | null, PlatformError> =>
15-
fs.stat(targetPath).pipe(
16-
Effect.catchTag("SystemError", (error) =>
17-
isNotFoundSystemError(error)
18-
? Effect.succeed(null)
19-
: Effect.fail(error))
20-
)
20+
fs.stat(targetPath).pipe(Effect.catchTag("SystemError", succeedNullOnNotFound))
2121

2222
export const readFileStringIfPresent = (
2323
fs: FileSystem.FileSystem,
2424
filePath: string
2525
): Effect.Effect<string | null, PlatformError> =>
26-
fs.readFileString(filePath).pipe(
27-
Effect.catchTag("SystemError", (error) =>
28-
isNotFoundSystemError(error)
29-
? Effect.succeed(null)
30-
: Effect.fail(error))
31-
)
26+
fs.readFileString(filePath).pipe(Effect.catchTag("SystemError", succeedNullOnNotFound))
3227

3328
const writeFileStringAttempt = (
3429
fs: FileSystem.FileSystem,

packages/lib/src/usecases/volatile-files.ts

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,27 +8,22 @@ const volatileWriteRetryAttempts = 5
88
export const isNotFoundSystemError = (error: PlatformError): boolean =>
99
error._tag === "SystemError" && error.reason === "NotFound"
1010

11+
const succeedNullOnNotFound = (error: PlatformError): Effect.Effect<null, PlatformError> =>
12+
isNotFoundSystemError(error)
13+
? Effect.succeed(null)
14+
: Effect.fail(error)
15+
1116
export const statIfPresent = (
1217
fs: FileSystem.FileSystem,
1318
targetPath: string
1419
): Effect.Effect<FileSystem.File.Info | null, PlatformError> =>
15-
fs.stat(targetPath).pipe(
16-
Effect.catchTag("SystemError", (error) =>
17-
isNotFoundSystemError(error)
18-
? Effect.succeed(null)
19-
: Effect.fail(error))
20-
)
20+
fs.stat(targetPath).pipe(Effect.catchTag("SystemError", succeedNullOnNotFound))
2121

2222
export const readFileStringIfPresent = (
2323
fs: FileSystem.FileSystem,
2424
filePath: string
2525
): Effect.Effect<string | null, PlatformError> =>
26-
fs.readFileString(filePath).pipe(
27-
Effect.catchTag("SystemError", (error) =>
28-
isNotFoundSystemError(error)
29-
? Effect.succeed(null)
30-
: Effect.fail(error))
31-
)
26+
fs.readFileString(filePath).pipe(Effect.catchTag("SystemError", succeedNullOnNotFound))
3227

3328
const writeFileStringAttempt = (
3429
fs: FileSystem.FileSystem,

0 commit comments

Comments
 (0)