Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/kernel/core/src/code-recovery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ export const recoverExecutionBody = (code: string): string => {
const source = extractCandidateSource(code);
if (!source) return "";

// oxlint-disable-next-line executor/no-try-catch-or-throw -- boundary: Babel parser throws for malformed candidate code, then recovery falls back to heuristics
try {
return renderParsedBody(source);
} catch {
Expand Down
4 changes: 1 addition & 3 deletions packages/kernel/core/src/effect-errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@ import * as Data from "effect/Data";
export class KernelCoreEffectError extends Data.TaggedError("KernelCoreEffectError")<{
readonly module: string;
readonly message: string;
readonly cause?: unknown;
}> {}

export const kernelCoreEffectError = (module: string, message: string) =>
new KernelCoreEffectError({ module, message });

/**
* Default failure type for any `CodeExecutor.execute` implementation —
* surfaces sandbox-level defects (isolate crash, module load failure,
Expand Down
24 changes: 14 additions & 10 deletions packages/kernel/core/src/validation.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { StandardSchemaV1 } from "@standard-schema/spec";
import * as Effect from "effect/Effect";

import { kernelCoreEffectError } from "./effect-errors";
import { KernelCoreEffectError } from "./effect-errors";

const getSchemaValidator = (
schema: unknown,
Expand Down Expand Up @@ -55,25 +55,29 @@ export const validateInput = (input: {
const validate = getSchemaValidator(input.schema);
if (!validate) {
return Effect.fail(
kernelCoreEffectError(
"validation",
`Tool ${input.path} has no Standard Schema validator on inputSchema`,
),
new KernelCoreEffectError({
module: "validation",
message: `Tool ${input.path} has no Standard Schema validator on inputSchema`,
}),
);
}

return Effect.tryPromise({
try: () => Promise.resolve(validate(input.value)),
catch: (cause) =>
kernelCoreEffectError("validation", `Validation error for ${input.path}: ${String(cause)}`),
new KernelCoreEffectError({
module: "validation",
message: `Validation error for ${input.path}`,
cause,
}),
}).pipe(
Effect.flatMap((result) => {
if ("issues" in result && result.issues) {
return Effect.fail(
kernelCoreEffectError(
"validation",
`Input validation failed for ${input.path}: ${formatIssues(result.issues)}`,
),
new KernelCoreEffectError({
module: "validation",
message: `Input validation failed for ${input.path}: ${formatIssues(result.issues)}`,
}),
);
}
return Effect.succeed(result.value);
Expand Down
Loading