Extracting and formatting errors from the `effect/Schema` library can indeed be a bit complex due...

I'm trying to do some simple
FormData
validation with effect/Schema but It's cripplingly hard to understand how I extract errors...

Here's my snippet:

import { assertEquals } from "@std/assert";
import { Effect, Exit, Schema as S } from "effect"
import { isComposite, ParseError } from "effect/ParseResult";
//import { resourceLimits } from "worker_threads";

const ApiKeyState = S.Struct({
  success: S.Boolean,
  message: S.optional(S.String),
})

const ApiKeyFormSchema = S.Struct({
  name: S.String.pipe(S.minLength(5, { message: () => "Name must be at least 5 characters long" })),
})

const validateFormData = (schema: S.Schema.AnyNoContext, formData: FormData) => S.decodeUnknown(schema)(Object.fromEntries(formData.entries())).pipe(
  Effect.mapError(e => {
    // WHAT TO PUT HERE? `e` is such a complex type
    return 'hello world'
  })
)


The expected error result is:
{
  name: "Name must be at least 5 characters long"
}
Was this page helpful?