| @@ -1,7 +1,7 @@ |
| 1 | import type { StandardSchemaV1 } from "@standard-schema/spec"; | 1 | import type { StandardSchemaV1 } from "@standard-schema/spec"; |
| 2 | import * as Effect from "effect/Effect"; | 2 | import * as Effect from "effect/Effect"; |
| 3 | | 3 | |
| 4 | import { kernelCoreEffectError } from "./effect-errors"; | 4 | import { KernelCoreEffectError } from "./effect-errors"; |
| 5 | | 5 | |
| 6 | const getSchemaValidator = ( | 6 | const getSchemaValidator = ( |
| 7 | schema: unknown, | 7 | schema: unknown, |
| @@ -55,25 +55,29 @@ export const validateInput = (input: { · 47 unmodified lines |
| 55 | const validate = getSchemaValidator(input.schema); | 55 | const validate = getSchemaValidator(input.schema); |
| 56 | if (!validate) { | 56 | if (!validate) { |
| 57 | return Effect.fail( | 57 | return Effect.fail( |
| 58 | kernelCoreEffectError( | 58 | new KernelCoreEffectError({ |
| 59 | "validation", | 59 | module: "validation", |
| 60 | `Tool ${input.path} has no Standard Schema validator on inputSchema`, | 60 | message: `Tool ${input.path} has no Standard Schema validator on inputSchema`, |
| 61 | ), | 61 | }), |
| 62 | ); | 62 | ); |
| 63 | } | 63 | } |
| 64 | | 64 | |
| 65 | return Effect.tryPromise({ | 65 | return Effect.tryPromise({ |
| 66 | try: () => Promise.resolve(validate(input.value)), | 66 | try: () => Promise.resolve(validate(input.value)), |
| 67 | catch: (cause) => | 67 | 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 | }), |
| 69 | }).pipe( | 73 | }).pipe( |
| 70 | Effect.flatMap((result) => { | 74 | Effect.flatMap((result) => { |
| 71 | if ("issues" in result && result.issues) { | 75 | if ("issues" in result && result.issues) { |
| 72 | return Effect.fail( | 76 | return Effect.fail( |
| 73 | kernelCoreEffectError( | 77 | new KernelCoreEffectError({ |
| 74 | "validation", | 78 | module: "validation", |
| 75 | `Input validation failed for ${input.path}: ${formatIssues(result.issues)}`, | 79 | message: `Input validation failed for ${input.path}: ${formatIssues(result.issues)}`, |
| 76 | ), | 80 | }), |
| 77 | ); | 81 | ); |
| 78 | } | 82 | } |
| 79 | return Effect.succeed(result.value); | 83 | return Effect.succeed(result.value); |