decodeUnknownExit is a synchronous decoder that returns an Exit value instead of throwing.
Exit is an Effect data structure for representing outcomes explicitly: either Success (with a value)
or Failure (with a cause).
Exit.Successcontains the decoded value.Exit.Failurecontains the decode error (aSchemaError) in thecause.
import { Cause, Exit, Schema } from "effect";
const schema = Schema.Struct({ name: Schema.String, age: Schema.Number,});
const decode = Schema.decodeUnknownExit(schema);
// Happy pathconst ok = decode({ name: "Alice", age: 30 });
if (Exit.isSuccess(ok)) { console.log("Decoded Value:", ok.value);}
// Error pathconst bad = decode({ name: 42, age: "30" });
if (Exit.isFailure(bad)) { console.log("Error Message:", Cause.pretty(bad.cause));}In the example above, I use Cause.pretty(bad.cause) to turn the Effect Cause (a structured error tree) into a
human-readable string for logs.