(options?: ErrorOptions)
| 10667 | * @since 4.0.0 |
| 10668 | */ |
| 10669 | export 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. |
no test coverage detected