Skip to content

fix(cli): log the real cause of store failures instead of [object ErrorEvent] - #692

Merged
blove merged 2 commits into
mainfrom
blove/beautiful-payne-a9784a
Sep 17, 2026
Merged

blove merged 2 commits into
mainfrom
blove/beautiful-payne-a9784a

Conversation

@blove

@blove blove commented Sep 17, 2026

Copy link
Copy Markdown
Contributor

Fixes #689.

Problem

An unreachable Postgres behind @neondatabase/serverless surfaced as B4.run runtime failure — [object ErrorEvent] and a generic 500. The driver rejects a failed WebSocket connect with a DOM ErrorEvent, not an Error, so String(error) read none of the properties (message, error, code) that name the refused host.

Change

  • packages/cli/src/lib/dev/runtime-error-report.ts (new, edge-safe, no node: imports)
    • serializeError reads message, code and the nested chain (cause first, the DOM error property second) off anything thrown, with cycle and depth guards.
    • formatErrorChain renders one line per link, each with its code.
    • errorStackOf returns the wrapped Error's stack when the thrown object has none.
    • describeConnectionTarget keeps scheme, host, port and database and drops the user, password and query string. A string the URL parser rejects is never echoed.
  • Runtime catch-all (runtime-fetch-core.ts) logs and dedupes on the rendered chain, so distinct driver failures no longer collapse into one [object ErrorEvent] line.
  • Generated stores.mjs reports a store initialisation failure once per sanitised target with the store kind (postgres store initialisation failed against postgres://host:5432/db — …), and the pool 'error' warning uses the same renderer.
  • The helpers are exported from @b4run/cli/fetch and listed in docs/api/cli.

Tests

  • test/runtime-error-report.test.ts: ErrorEvent-like object, cause chains with codes, numeric codes, circular and runaway chains, primitives, stack lookup, and credential redaction (userinfo, ?password=, unparseable libpq strings).
  • test/edge-runtime-diagnostics.test.ts: an ErrorEvent thrown from requestStores logs the host and code, prints the wrapped stack, keeps the body opaque, and logs once.
  • test/hono-target.test.ts: the emitted stores.mjs carries the initialisation report and no String(error).

Verification

  • pnpm --filter @b4run/cli lint and typecheck clean.
  • Affected cli test files pass (runtime-error-report, edge-runtime-diagnostics, hono-target, vercel-target, fetch-entry-purity, server-errors, request-stores, runtime-fetch-handler). vercel-target showed 5 s timeouts on a box with load average over 140 and passed 95/95 when rerun.
  • node scripts/check-docs.mjs and --analyze-detailed-api-references pass; the docs inventory test passed 251/252 with the one failure being a spawn timeout of that same script under load.

Not released.

🤖 Generated with Claude Code

…orEvent]

A Postgres connection the @neondatabase/serverless WebSocket driver could not
open reached the runtime log as "B4.run runtime failure — [object ErrorEvent]":
the driver rejects with a DOM ErrorEvent, not an Error, and String(event) reads
none of the properties (message, error, code) that name the refused host.

- new edge-safe runtime-error-report.ts: serializeError follows cause/error
  chains off anything thrown (Error, ErrorEvent-like, plain object, primitive)
  with cycle and depth guards; formatErrorChain renders one line per link with
  each link's code; errorStackOf finds the wrapped Error's stack;
  describeConnectionTarget keeps scheme/host/port/database and drops the
  user, password and query string, never echoing an unparseable string
- the runtime catch-all logs and dedupes on the rendered chain
- the generated stores.mjs reports a store initialisation failure once per
  sanitised target with the store kind, and the pool 'error' warning uses the
  same renderer
- the helpers are exported from @b4run/cli/fetch and listed in the API docs

Closes #689

Co-Authored-By: Claude Fable 5.1 <[email protected]>
@vercel

vercel Bot commented Sep 17, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
b4-run Ready Ready Preview Sep 17, 2026 3:13pm UTC

Request Review

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automated approval: this PR received an intelligent (AI) code review. See the review comments on this PR.

The @b4run/cli/fetch export table gained the error-report helpers, so the
/docs/api/cli record digest moved and the freshness check exited 1.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
@blove
blove merged commit 5a38599 into main Sep 17, 2026
29 of 30 checks passed
@blove
blove deleted the blove/beautiful-payne-a9784a branch September 17, 2026 15:34
blove added a commit that referenced this pull request Sep 17, 2026
…(error)

Rebased onto #692, which landed the edge-safe error-chain serializer. The
readiness probe's own reporting had the exact bug that fixed: the Postgres
drivers reject a failed connect with a DOM ErrorEvent, so `String(error)`
rendered "[object ErrorEvent]" — the one failure /readyz exists to name would
have arrived unnamed.

- describeReadinessFailure renders through formatErrorChain, so the root cause
  and its driver code reach the check body
- redaction now runs over the whole rendered chain, which matters because the
  chain is built from driver messages that quote the connection string, and
  unlike the catch-all's stderr log this one is served in a response body
- docs say plainly that /readyz bodies carry real causes (hosts, ports,
  database names, driver codes) and so must sit behind the outer boundary

Co-Authored-By: Claude Opus 5 <[email protected]>
blove added a commit that referenced this pull request Sep 17, 2026
…(error)

Rebased onto #692, which landed the edge-safe error-chain serializer. The
readiness probe's own reporting had the exact bug that fixed: the Postgres
drivers reject a failed connect with a DOM ErrorEvent, so `String(error)`
rendered "[object ErrorEvent]" — the one failure /readyz exists to name would
have arrived unnamed.

- describeReadinessFailure renders through formatErrorChain, so the root cause
  and its driver code reach the check body
- redaction now runs over the whole rendered chain, which matters because the
  chain is built from driver messages that quote the connection string, and
  unlike the catch-all's stderr log this one is served in a response body
- docs say plainly that /readyz bodies carry real causes (hosts, ports,
  database names, driver codes) and so must sit behind the outer boundary

Co-Authored-By: Claude Opus 5 <[email protected]>
blove added a commit that referenced this pull request Sep 17, 2026
…#694)

* fix(cli): make /healthz pure liveness and add /readyz dependency readiness

On the vercel (and hono) target the per-request store factory ran for every
request, health checks included, so a deployment with DATABASE_URL unset or
its database unreachable answered /healthz with a 500 and looked completely
down instead of "up, not ready".

- GET /healthz no longer calls requestStores; it answers 200 {status:"ready"}
  whenever the process serves HTTP (body kept for harness compatibility).
- New GET /readyz builds the request's stores and probes threads, checkpointer
  and permissions with a real query (running lazy migrations on the way).
  200 {status:"ready",checks} or 503 {status:"not_ready",checks}; a throwing
  factory is reported as `requestStores`, an omitted store carries B4_E5301,
  connection-string credentials are redacted, and each cause is logged once.
- Route matching now happens before store construction so the two probes can
  decide what to do with the factory; every other route is unchanged.
- Tests that relied on /healthz building stores now use /readyz; the
  thread-access coverage exempt list and route count include /readyz.
- Docs: production topology, middleware, embedding, kubernetes, docker
  blueprint, chart README/values and llms.txt describe both probes.

Fixes #688

Co-Authored-By: Claude Fable 5.1 <[email protected]>

* chore(web): regenerate SEO lastmod manifest for the probe docs

Co-Authored-By: Claude Fable 5.1 <[email protected]>

* fix(cli): report /readyz failures through the error chain, not String(error)

Rebased onto #692, which landed the edge-safe error-chain serializer. The
readiness probe's own reporting had the exact bug that fixed: the Postgres
drivers reject a failed connect with a DOM ErrorEvent, so `String(error)`
rendered "[object ErrorEvent]" — the one failure /readyz exists to name would
have arrived unnamed.

- describeReadinessFailure renders through formatErrorChain, so the root cause
  and its driver code reach the check body
- redaction now runs over the whole rendered chain, which matters because the
  chain is built from driver messages that quote the connection string, and
  unlike the catch-all's stderr log this one is served in a response body
- docs say plainly that /readyz bodies carry real causes (hosts, ports,
  database names, driver codes) and so must sit behind the outer boundary

Co-Authored-By: Claude Opus 5 <[email protected]>

---------

Co-authored-by: Claude Fable 5.1 <[email protected]>

This branch was successfully deployed

1 active and 1 inactive deployments
Preview — 6a4c7ffc Deployed Sep 17, 2026 by vercel[bot]
vercel-preview — 6a4c7ffc Deployed Sep 17, 2026 by blove via vercel-native #1943
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.

runtime: store failures are logged as [object ErrorEvent] with no cause

1 participant