History

Keep kernel core failures typed

Rhys Sullivan committed 6 months ago

Commit 025cdf61 parent b039b6e3 files · +16 −13Browse files

Unified · Split

3 files
  1. packages/kernel/core/src/code-recovery.ts +1 −0
  2. packages/kernel/core/src/effect-errors.ts +1 −3
  3. packages/kernel/core/src/validation.ts +14 −10
packages/kernel/core/src/code-recovery.ts+1−0
@@ -139,6 +139,7 @@ export const recoverExecutionBody = (code: string): string => { · 138 unmodified lines
139139 const source = extractCandidateSource(code);
140140 if (!source) return "";
141141
142+ // oxlint-disable-next-line executor/no-try-catch-or-throw -- boundary: Babel parser throws for malformed candidate code, then recovery falls back to heuristics
142143 try {
143144 return renderParsedBody(source);
144145 } catch {
packages/kernel/core/src/effect-errors.ts+1−3
@@ -3,11 +3,9 @@ import * as Data from "effect/Data"; · 2 unmodified lines
33 export class KernelCoreEffectError extends Data.TaggedError("KernelCoreEffectError")<{
44 readonly module: string;
55 readonly message: string;
6+ readonly cause?: unknown;
67 }> {}
78
8−export const kernelCoreEffectError = (module: string, message: string) =>
9− new KernelCoreEffectError({ module, message });
10−
119 /**
1210 * Default failure type for any `CodeExecutor.execute` implementation —
1311 * surfaces sandbox-level defects (isolate crash, module load failure,
packages/kernel/core/src/validation.ts+14−10
@@ -1,7 +1,7 @@
11 import type { StandardSchemaV1 } from "@standard-schema/spec";
22 import * as Effect from "effect/Effect";
33
4−import { kernelCoreEffectError } from "./effect-errors";
4+import { KernelCoreEffectError } from "./effect-errors";
55
66 const getSchemaValidator = (
77 schema: unknown,
@@ -55,25 +55,29 @@ export const validateInput = (input: { · 47 unmodified lines
5555 const validate = getSchemaValidator(input.schema);
5656 if (!validate) {
5757 return Effect.fail(
58− kernelCoreEffectError(
59− "validation",
60− `Tool ${input.path} has no Standard Schema validator on inputSchema`,
61− ),
58+ new KernelCoreEffectError({
59+ module: "validation",
60+ message: `Tool ${input.path} has no Standard Schema validator on inputSchema`,
61+ }),
6262 );
6363 }
6464
6565 return Effect.tryPromise({
6666 try: () => Promise.resolve(validate(input.value)),
6767 catch: (cause) =>
68− kernelCoreEffectError("validation", `Validation error for ${input.path}: ${String(cause)}`),
68+ new KernelCoreEffectError({
69+ module: "validation",
70+ message: `Validation error for ${input.path}`,
71+ cause,
72+ }),
6973 }).pipe(
7074 Effect.flatMap((result) => {
7175 if ("issues" in result && result.issues) {
7276 return Effect.fail(
73− kernelCoreEffectError(
74− "validation",
75− `Input validation failed for ${input.path}: ${formatIssues(result.issues)}`,
76− ),
77+ new KernelCoreEffectError({
78+ module: "validation",
79+ message: `Input validation failed for ${input.path}: ${formatIssues(result.issues)}`,
80+ }),
7781 );
7882 }
7983 return Effect.succeed(result.value);