Skip to content

Commit bcdc6cc

Browse files
chore(lint): enforce tryCatchInEffectGen
1 parent e594e71 commit bcdc6cc

5 files changed

Lines changed: 40 additions & 33 deletions

File tree

‎apps/server/src/mcp/AcpMcpStdioBridge.ts‎

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import * as NodeReadline from "node:readline";
44

55
import * as Cause from "effect/Cause";
66
import * as Effect from "effect/Effect";
7+
import * as Result from "effect/Result";
78
import * as Fiber from "effect/Fiber";
89
import * as Scope from "effect/Scope";
910
import * as Stream from "effect/Stream";
@@ -273,13 +274,11 @@ export function runAcpMcpStdioBridge(options: AcpMcpStdioBridgeOptions): Effect.
273274
line: string,
274275
): Effect.fn.Return<void> {
275276
if (line.trim().length === 0) return;
276-
let parsed: unknown;
277-
try {
278-
parsed = JSON.parse(line);
279-
} catch {
277+
const parsed = yield* Effect.try((): unknown => JSON.parse(line)).pipe(Effect.result);
278+
if (Result.isFailure(parsed)) {
280279
return yield* respondWithError(null, "Parse error", -32700);
281280
}
282-
const envelope = asEnvelope(parsed);
281+
const envelope = asEnvelope(parsed.success);
283282
if (envelope === null) return;
284283
const isResponse = envelope.id !== undefined && ("result" in envelope || "error" in envelope);
285284
const isSessionHandshake =

‎apps/server/src/orchestration-v2/http.ts‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
} from "@t3tools/contracts";
66
import * as DateTime from "effect/DateTime";
77
import * as Effect from "effect/Effect";
8+
import * as Result from "effect/Result";
89
import * as Predicate from "effect/Predicate";
910
import * as Schema from "effect/Schema";
1011
import * as HttpApiBuilder from "effect/http-api/HttpApiBuilder";
@@ -245,9 +246,11 @@ export const layer = HttpApiBuilder.group(
245246
Effect.fn("environment.orchestration.threadHistoryPage")(function* (args) {
246247
yield* annotateEnvironmentRequest(args.endpoint.name);
247248
yield* requireEnvironmentScope(AuthOrchestrationReadScope);
248-
try {
249-
decodeThreadHistoryCursor(args.query.cursor);
250-
} catch (cause) {
249+
const decoded = yield* Effect.try(() =>
250+
decodeThreadHistoryCursor(args.query.cursor),
251+
).pipe(Effect.result);
252+
if (Result.isFailure(decoded)) {
253+
const cause = decoded.failure.cause;
251254
if (cause instanceof InvalidThreadHistoryCursorError)
252255
return yield* failEnvironmentInvalidRequest("invalid_history_cursor");
253256
return yield* failEnvironmentInternal("orchestration_thread_history_failed", cause);

‎packages/provider-acp/src/server/AcpSessionRuntime.ts‎

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import * as Crypto from "effect/Crypto";
1010
import * as Deferred from "effect/Deferred";
1111
import * as Duration from "effect/Duration";
1212
import * as Effect from "effect/Effect";
13+
import * as Result from "effect/Result";
1314
import * as Exit from "effect/Exit";
1415
import * as Fiber from "effect/Fiber";
1516
import * as Layer from "effect/Layer";
@@ -482,19 +483,18 @@ export function terminateLinuxCgroupLease(
482483
let lastRemovalFailure: { readonly cause: unknown } | null = null;
483484
for (let attempt = 0; attempt < 200; attempt += 1) {
484485
if (!lease.exists()) return;
485-
try {
486-
lease.kill();
487-
} catch (cause) {
486+
const killed = yield* Effect.try(() => lease.kill()).pipe(Effect.result);
487+
if (Result.isFailure(killed)) {
488+
const cause = killed.failure.cause;
488489
const code = (cause as NodeJS.ErrnoException | undefined)?.code;
489490
if (code !== "ENOENT") return yield* failure("kill", cause);
490491
if (!lease.exists()) return;
491492
yield* Effect.sleep("10 millis");
492493
continue;
493494
}
494-
let populated: boolean;
495-
try {
496-
populated = lease.populated();
497-
} catch (cause) {
495+
const populated = yield* Effect.try(() => lease.populated()).pipe(Effect.result);
496+
if (Result.isFailure(populated)) {
497+
const cause = populated.failure.cause;
498498
const code = (cause as NodeJS.ErrnoException | undefined)?.code;
499499
if (code === "ENOENT" && !lease.exists()) return;
500500
if (code === "ENOENT") {
@@ -503,21 +503,22 @@ export function terminateLinuxCgroupLease(
503503
}
504504
return yield* failure("read state for", cause);
505505
}
506-
if (populated) {
506+
if (populated.success) {
507507
lastRemovalFailure = null;
508508
yield* Effect.sleep("10 millis");
509509
continue;
510510
}
511-
try {
512-
lease.remove();
513-
lastRemovalFailure = null;
514-
} catch (cause) {
511+
const removed = yield* Effect.try(() => lease.remove()).pipe(Effect.result);
512+
if (Result.isFailure(removed)) {
513+
const cause = removed.failure.cause;
515514
const code = (cause as NodeJS.ErrnoException | undefined)?.code;
516515
if (code === "ENOENT" && !lease.exists()) return;
517516
if (code !== "EBUSY" && code !== "ENOTEMPTY" && code !== "ENOENT") {
518517
return yield* failure("remove", cause);
519518
}
520519
lastRemovalFailure = { cause };
520+
} else {
521+
lastRemovalFailure = null;
521522
}
522523
if (!lease.exists()) return;
523524
yield* Effect.sleep("10 millis");

‎packages/shared/src/nodeSqliteClient.ts‎

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import * as Cache from "effect/Cache";
66
import * as Clock from "effect/Clock";
77
import * as Duration from "effect/Duration";
88
import * as Effect from "effect/Effect";
9+
import * as Result from "effect/Result";
910
import * as Exit from "effect/Exit";
1011
import * as Fiber from "effect/Fiber";
1112
import { identity } from "effect/Function";
@@ -640,21 +641,23 @@ const startCheckpointWorker = Effect.fnUntraced(function* (
640641
}
641642
const frames = writer.prepare("PRAGMA wal_checkpoint(NOOP)");
642643
const sizeLimit = writer.prepare("PRAGMA journal_size_limit");
643-
let worker: NodeWorkerThreads.Worker;
644-
try {
645-
worker = new NodeWorkerThreads.Worker(checkpointWorkerSource, {
646-
eval: true,
647-
workerData: {
648-
filename,
649-
frames: CHECKPOINT_FRAMES,
650-
backpressureFrames: CHECKPOINT_BACKPRESSURE_FRAMES,
651-
idleMs: CHECKPOINT_IDLE_MS,
652-
},
653-
});
654-
} catch (cause) {
655-
yield* warn(String(cause));
644+
const started = yield* Effect.try(
645+
() =>
646+
new NodeWorkerThreads.Worker(checkpointWorkerSource, {
647+
eval: true,
648+
workerData: {
649+
filename,
650+
frames: CHECKPOINT_FRAMES,
651+
backpressureFrames: CHECKPOINT_BACKPRESSURE_FRAMES,
652+
idleMs: CHECKPOINT_IDLE_MS,
653+
},
654+
}),
655+
).pipe(Effect.result);
656+
if (Result.isFailure(started)) {
657+
yield* warn(String(started.failure.cause));
656658
return undefined;
657659
}
660+
const worker = started.success;
658661
const runFork = Effect.runForkWith(yield* Effect.context<never>());
659662
let stopped = false;
660663
let generation = 0;

‎tsconfig.base.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
"namespaceImportPackages": ["@effect/platform-node", "effect"],
2525
"effectFn": ["span", "inferred-span", "suggested-span"],
2626
"diagnosticSeverity": {
27+
"tryCatchInEffectGen": "error",
2728
"runEffectInsideEffect": "error",
2829
"schemaStructWithTag": "error",
2930
"preferTypedSchemaDecoder": "error",

0 commit comments

Comments
 (0)