Skip to content

refactor(api): make v2 error contracts exact end to end - #458

Open
Makisuo wants to merge 3 commits into
mainfrom
codex/unify-v2-error-contract
Open

refactor(api): make v2 error contracts exact end to end#458
Makisuo wants to merge 3 commits into
mainfrom
codex/unify-v2-error-contract

Conversation

@Makisuo

@Makisuo Makisuo commented Aug 13, 2026

Copy link
Copy Markdown
Collaborator

What changed

  • made every v2 expected failure a self-describing HttpTaggedError whose tag, HTTP status, safe body, retry policy, and recovery action live in one definition
  • removed generic v2 status-family wrappers and declared the exact reachable tags on each endpoint and in OpenAPI
  • preserved warehouse, query-engine, alert, Tinybird token, and PlanetScale OAuth failures instead of relabeling them at route or service boundaries
  • derived warehouse unions, handler tables, and endpoint schemas from canonical class tuples; removed the duplicated metadata registry and compatibility alias
  • encoded managed warehouse routing in the query type so ingest-only endpoints cannot accidentally advertise read-routing errors
  • split ambiguous resource and warehouse failures, including alert resource not-found tags and result-decode versus cluster-schema failures
  • made the worker bootstrap fallback share its definition with the v2 contract
  • aligned the Alchemy client and web retry behavior with the canonical body, exact server tags, body-driven retry metadata, and Effect Clock
  • kept v1 wire behavior intact with compatibility adapters only at v1 boundaries

Why

The previous stack had several overlapping error systems. Exact service errors were routinely collapsed and reconstructed, endpoint specs overdeclared status buckets, and clients had to infer behavior from HTTP status or fields inside a generic tag.

Now an expected failure keeps one identity from its source through the HTTP response and client. Endpoint contracts enumerate only the tags they can actually emit, while transport-only failures remain in the transport boundary.

Breaking changes

This intentionally breaks consumers of the old generic v2 and Alchemy client error classes. Consumers should branch on the exact semantic _tag. The canonical response remains { error: { _tag, type, code, title, message, retryable, recovery, ... } }.

Validation

  • bun run typecheck: 40/40 tasks
  • bun run lint:effect
  • API: 1,742 passed, 202 skipped
  • domain/OpenAPI: 477 passed
  • query engine: 1,017 passed
  • web: 1,540 passed
  • Alchemy client: 26 passed
  • formatting and git diff --check
  • the monorepo concurrent run hit one untouched 5-second CLI timing test; that test passed in 16 ms when rerun alone

View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.

@Makisuo Makisuo changed the title refactor(api): preserve v2 error tags end to end refactor(api): make v2 error contracts exact end to end Aug 13, 2026
@Makisuo
Makisuo marked this pull request as ready for review August 13, 2026 18:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant