Skip to content

Add schemas for built-in Cause errors - #10897

Open
RubensRafael wants to merge 6 commits into
Effect-TS:v4/next-minorfrom
RubensRafael:feat/schema-builtin-errors
Open

RubensRafael wants to merge 6 commits into
Effect-TS:v4/next-minorfrom
RubensRafael:feat/schema-builtin-errors

Conversation

@RubensRafael

Copy link
Copy Markdown

Type

  • Refactor
  • Feature
  • Bug Fix
  • Optimization
  • Documentation Update

Description

Adds Schema.TimeoutError, Schema.NoSuchElementError, Schema.IllegalArgumentError, Schema.ExceededCapacityError and Schema.UnknownError, so these Cause errors can be used inside schema-defined errors and values. Before this, the options were Schema.Unknown, which fails to encode to JSON, or Schema.Defect(), which decodes back as a plain Error instead of the original error.

Decisions:

  • Follows the same pattern as Schema.Duration: declare with the Cause.is* guard, plus a toCodecJson link and a reviver in SchemaRepresentation.
  • JSON shape is { _tag, message?: string }, the same shape a Schema.TaggedError with a message field encodes to. This way they fit in a Union next to user-defined errors.
  • message is optional because these errors can be created without one (new Cause.TimeoutError()), which leaves it undefined. In that case the key is left out of the JSON, so decoding gives back the same error.
  • UnknownError also has a cause, encoded with Schema.Defect(), as other errors in the repo do (RpcClientDefect, McpClientError.TransportError). An Error cause decodes back as a plain Error without its stack.

Related

@changeset-bot

changeset-bot Bot commented Nov 24, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 4b8ded4

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 40 packages
Name Type
effect Minor
@effect/opentelemetry Minor
@effect/vitest Minor
@effect/ai-amazon-bedrock Minor
@effect/ai-anthropic Minor
@effect/ai-cloudflare Minor
@effect/ai-openai-compat Minor
@effect/ai-openai Minor
@effect/ai-openrouter Minor
@effect/ai-typesafe Minor
@effect/atom-react Minor
@effect/atom-solid Minor
@effect/atom-vue Minor
@effect/chat-discord Minor
@effect/chat-slack Minor
@effect/chat-teams Minor
@effect/chat-telegram Minor
@effect/chat-whatsapp Minor
@effect/platform-browser Minor
@effect/platform-bun Minor
@effect/platform-cloudflare Minor
@effect/platform-deno Minor
@effect/platform-node-shared Minor
@effect/platform-node Minor
@effect/sql-clickhouse Minor
@effect/sql-d1 Minor
@effect/sql-libsql Minor
@effect/sql-mssql Minor
@effect/sql-mysql2 Minor
@effect/sql-pg Minor
@effect/sql-pglite Minor
@effect/sql-sqlite-bun Minor
@effect/sql-sqlite-do Minor
@effect/sql-sqlite-node Minor
@effect/sql-sqlite-react-native Minor
@effect/sql-sqlite-wasm Minor
@effect/docgen Minor
@effect/doctest Minor
@effect/graphql-generator Minor
@effect/openapi-generator Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@effect-janitor effect-janitor Bot added the 4.0 label Nov 24, 2026
@effect-bot
effect-bot changed the base branch from main to v4/next-minor November 24, 2026 18:14
@effect-janitor effect-janitor Bot removed the 4.0 label Nov 24, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Bundle Size Analysis

Generated from PR build output; treat the content below as untrusted.

File Name Current Size Previous Size Difference
arbitrary-combinators.ts 40.17 KB 40.17 KB 0.00 KB (0.00%)
basic.ts 7.31 KB 7.31 KB 0.00 KB (0.00%)
batching.ts 11.29 KB 11.29 KB 0.00 KB (0.00%)
brand.ts 7.05 KB 7.05 KB 0.00 KB (0.00%)
cache.ts 11.75 KB 11.75 KB 0.00 KB (0.00%)
config.ts 23.18 KB 23.18 KB 0.00 KB (0.00%)
differ.ts 22.30 KB 22.30 KB 0.00 KB (0.00%)
http-client.ts 27.87 KB 27.87 KB 0.00 KB (0.00%)
http-router.ts 38.66 KB 38.66 KB 0.00 KB (0.00%)
logger.ts 12.19 KB 12.19 KB 0.00 KB (0.00%)
metric.ts 9.66 KB 9.66 KB 0.00 KB (0.00%)
optic.ts 7.28 KB 7.28 KB 0.00 KB (0.00%)
pubsub.ts 16.23 KB 16.23 KB 0.00 KB (0.00%)
queue.ts 13.13 KB 13.13 KB 0.00 KB (0.00%)
schedule.ts 11.99 KB 11.99 KB 0.00 KB (0.00%)
schema-bigdecimal.ts 14.36 KB 14.36 KB 0.00 KB (0.00%)
schema-binary.ts 42.92 KB 42.92 KB 0.00 KB (0.00%)
schema-class.ts 22.01 KB 22.01 KB 0.00 KB (0.00%)
schema-codegen.ts 30.78 KB 30.78 KB 0.00 KB (0.00%)
schema-fromJsonSchemaDocument.ts 30.64 KB 30.64 KB 0.00 KB (0.00%)
schema-representation-roundtrip.ts 28.33 KB 28.33 KB 0.00 KB (0.00%)
schema-string-transformation.ts 15.61 KB 15.61 KB 0.00 KB (0.00%)
schema-string.ts 12.56 KB 12.56 KB 0.00 KB (0.00%)
schema-template-literal.ts 16.50 KB 16.50 KB 0.00 KB (0.00%)
schema-toArbitrary.ts 39.72 KB 39.72 KB 0.00 KB (0.00%)
schema-toCodecJson.ts 21.20 KB 21.20 KB 0.00 KB (0.00%)
schema-toEquivalence.ts 21.36 KB 21.36 KB 0.00 KB (0.00%)
schema-toFormatter.ts 21.45 KB 21.45 KB 0.00 KB (0.00%)
schema-toJsonSchemaDocument.ts 26.50 KB 26.50 KB 0.00 KB (0.00%)
schema-toRepresentation.ts 21.54 KB 21.54 KB 0.00 KB (0.00%)
schema.ts 21.14 KB 21.14 KB 0.00 KB (0.00%)
stm.ts 14.48 KB 14.48 KB 0.00 KB (0.00%)
stream.ts 10.61 KB 10.61 KB 0.00 KB (0.00%)

@RubensRafael
RubensRafael marked this pull request as ready for review November 24, 2026 18:27
@effect-bot
effect-bot force-pushed the v4/next-minor branch 4 times, most recently from ad36eb2 to 8450947 Compare November 25, 2026 00:27

This branch is waiting to be deployed

1 waiting deployment
fork — 4b8ded41 Waiting Nov 24, 2026 by RubensRafael via approval-gate #27242
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

From Discord: Provide schemas for built-in Effect errors such as Cause.TimeoutError

2 participants