Hyperlinkv0.8.0-beta.28

Schema

Schema.ErrorClassconsteffect/Schema.ts:12923
<Self = never, Brand = {}>(identifier: string): {
  <const Fields extends Struct.Fields>(
    fields: Fields,
    annotations?: Annotations.Declaration<Self, readonly [Struct<Fields>]>
  ): [Self] extends [never]
    ? MissingSelfGeneric<"Schema.ErrorClass">
    : Class<Self, Struct<Fields>, Cause_.YieldableError & Brand>
  <S extends Struct<Struct.Fields>>(
    schema: S,
    annotations?: Annotations.Declaration<Self, readonly [S]>
  ): [Self] extends [never]
    ? MissingSelfGeneric<"Schema.ErrorClass">
    : Class<Self, S, Cause_.YieldableError & Brand>
}

Creates a schema-backed error class that can be used as a typed, yieldable error in Effect programs. Combines Class validation with the YieldableError interface so instances can be yielded directly inside Effect.gen.

Example (Schema-backed error)

import { Effect, Schema } from "effect"

class NotFound extends Schema.ErrorClass<NotFound>("NotFound")({
  id: Schema.Number
}) {}

const program = Effect.gen(function*() {
  yield* new NotFound({ id: 1 })
})
constructorsClass
Source effect/Schema.ts:1292331 lines
export const ErrorClass: {
  <Self = never, Brand = {}>(identifier: string): {
    <const Fields extends Struct.Fields>(
      fields: Fields,
      annotations?: Annotations.Declaration<Self, readonly [Struct<Fields>]>
    ): [Self] extends [never] ? MissingSelfGeneric<"Schema.ErrorClass">
      : Class<Self, Struct<Fields>, Cause_.YieldableError & Brand>
    <S extends Struct<Struct.Fields>>(
      schema: S,
      annotations?: Annotations.Declaration<Self, readonly [S]>
    ): [Self] extends [never] ? MissingSelfGeneric<"Schema.ErrorClass"> : Class<Self, S, Cause_.YieldableError & Brand>
  }
} = <Self, Brand = {}>(identifier: string) =>
(
  schema: Struct.Fields | Struct<Struct.Fields>,
  annotations?: Annotations.Declaration<Self, readonly [Struct<Struct.Fields>]>
): [Self] extends [never] ? MissingSelfGeneric<"Schema.ErrorClass">
  : Class<Self, Struct<Struct.Fields>, Cause_.YieldableError & Brand> =>
{
  const struct = isStruct(schema) ? schema : Struct(schema)
  const self = makeClass(
    core.Error,
    identifier,
    struct,
    annotations,
    (identifier) => ({
      name: identifier
    })
  )
  return self
}
Referenced by 3 symbols