MCPcopy Create free account
hub / github.com/Effect-TS/effect / ErrorInstance

Function ErrorInstance

packages/effect/src/Schema.ts:10669–10693  ·  view source on GitHub ↗
(options?: ErrorOptions)

Source from the content-addressed store, hash-verified

10667 * @since 4.0.0
10668 */
10669export function ErrorInstance(options?: ErrorOptions): ErrorInstance {
10670 const key = getErrorOptionsKey(options)
10671 const cached = errorSchemaCache[key]
10672 if (cached !== undefined) {
10673 return cached
10674 }
10675 const normalizedOptions = getErrorOptions(key)
10676 const schema = instanceOf(globalThis.Error, {
10677 representation: {
10678 id: "effect/schema/Error",
10679 payload: normalizedOptions ?? null
10680 },
10681 toCode: () => ({
10682 runtime: normalizedOptions !== undefined
10683 ? `Schema.ErrorInstance(${format(normalizedOptions)})`
10684 : `Schema.ErrorInstance()`,
10685 Type: `globalThis.Error`
10686 }),
10687 expected: "Error",
10688 toCodecJson: () => link<globalThis.Error>()(JsonError, SchemaTransformation.errorFromJsonError(normalizedOptions)),
10689 toArbitrary: () => (fc) => fc.string().map((message) => new globalThis.Error(message))
10690 })
10691 errorSchemaCache[key] = schema
10692 return schema
10693}
10694
10695/**
10696 * Reviver for persisted {@link ErrorInstance} declarations.

Callers 1

Schema.tsFile · 0.70

Calls 6

formatFunction · 0.90
getErrorOptionsKeyFunction · 0.85
getErrorOptionsFunction · 0.85
instanceOfFunction · 0.70
linkFunction · 0.70
mapMethod · 0.45

Tested by

no test coverage detected