Skip to content

Commit e2bb5af

Browse files
committed
Fix isPlatformError check: use instanceof instead of Predicate.isTagged
Predicate.isTagged(u, 'PlatformError') checks u._tag === 'PlatformError', but PlatformError is a union of BadArgument (_tag: 'BadArgument') and SystemError (_tag: 'SystemError'), so the check never matched. This silently broke the AlreadyExists race-condition recovery in getOrCreateRandom. Use 'instanceof PlatformError.PlatformError' instead, consistent with the existing check in the remove function.
1 parent 4af9463 commit e2bb5af

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

apps/server/src/auth/Layers/ServerSecretStore.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as Crypto from "node:crypto";
22

3-
import { Effect, FileSystem, Layer, Path, Predicate } from "effect";
3+
import { Effect, FileSystem, Layer, Path } from "effect";
44
import * as PlatformError from "effect/PlatformError";
55

66
import { ServerConfig } from "../../config.ts";
@@ -28,9 +28,6 @@ export const makeServerSecretStore = Effect.gen(function* () {
2828

2929
const resolveSecretPath = (name: string) => path.join(serverConfig.secretsDir, `${name}.bin`);
3030

31-
const isPlatformError = (u: unknown): u is PlatformError.PlatformError =>
32-
Predicate.isTagged(u, "PlatformError");
33-
3431
const get: ServerSecretStoreShape["get"] = (name) =>
3532
fileSystem.readFile(resolveSecretPath(name)).pipe(
3633
Effect.map((bytes) => Uint8Array.from(bytes)),
@@ -105,7 +102,8 @@ export const makeServerSecretStore = Effect.gen(function* () {
105102
return create(name, generated).pipe(
106103
Effect.as(Uint8Array.from(generated)),
107104
Effect.catchTag("SecretStoreError", (error) =>
108-
isPlatformError(error.cause) && error.cause.reason._tag === "AlreadyExists"
105+
error.cause instanceof PlatformError.PlatformError &&
106+
error.cause.reason._tag === "AlreadyExists"
109107
? get(name).pipe(
110108
Effect.flatMap((created) =>
111109
created !== null

0 commit comments

Comments
 (0)