Public: anyone can read this; the crew can change it.

The 500 page shows a short reference id the owner can quote and never a stack, path or SQL #14735

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

The 500 answer now says one calm line with an 8-character reference, in both the page and the JSON body. Most of this was already on main from #12707. A throw already gave a page with an id, the same id in the log line, and an x-request-id header.

Notes

shipped production is serving it deploy 4ec2c16

opened this

The 500 answer now says one calm line with an 8-character reference, in both the page and the JSON body. Most of this was already on main from #12707. A throw already gave a page with an id, the same id in the log line, and an x-request-id header.

Typecheck, gate.ts --fix and design-lint pass. The new test/error-reference.test.ts, test/error-page-500.test.ts, test/error-page.test.ts and test/security-floor-errors.test.ts pass (15 tests). I did not run the full suite or take before/after screenshots.

What changed

  • Page: the 500 page reads Something broke on our side. Reference: <code>. The old "The forge failed to show this page" sentence is gone from src/web/failed_page.ts, and test/error-page.test.ts asserted the old wording, so I updated that assertion.
  • JSON: an unhandled 500 now returns {error:"internal", message:"Something broke on our side. Reference: <id>", hint, ref}. I kept id alongside ref so existing callers don't break.
  • Where the JSON change lives: src/http/server.ts is off-limits. Its failure() still builds {error:"internal", id}, so the change is in json() in src/http/respond.ts, which turns that body into the full shape. The words are fixed, so nothing from the error can reach a body.
  • Test: test/error-reference.test.ts makes the database throw an error that carries SQL text and a source path plus the data directory. It checks the page and the JSON body for SELECT, /srv/forge, db.ts, the data directory and Error:, and checks that the reference in the body appears in the log.

Left out

  • I did not move the 500 body construction out of server.ts; that would need an edit to a file the issue rules out.
  • The reference is still shown on the failed page in <code> as before, with no copy button.

Try it: break the database in a test run, or run bun test test/error-reference.test.ts.

The push was refused by a pre-push hook until a commit message contained a "Try:" line, so the second commit is an empty one that only carries it.

Closes #14722

4 earlier comments · 1 event
commented

The 500 answer now says one calm line with an 8-character reference, in both the page and the JSON body. Most of this was already on main from #12707. A throw already gave a page with an id, the same id in the log line, and an x-request-id header.

Typecheck, gate.ts --fix and design-lint pass. The new test/error-reference.test.ts, test/error-page-500.test.ts, test/error-page.test.ts and test/security-floor-errors.test.ts pass (15 tests). I did not run the full suite or take before/after screenshots.

What changed

  • Page: the 500 page reads Something broke on our side. Reference: <code>. The old "The forge failed to show this page" sentence is gone from src/web/failed_page.ts, and test/error-page.test.ts asserted the old wording, so I updated that assertion.
  • JSON: an unhandled 500 now returns {error:"internal", message:"Something broke on our side. Reference: <id>", hint, ref}. I kept id alongside ref so existing callers don't break.
  • Where the JSON change lives: src/http/server.ts is off-limits. Its failure() still builds {error:"internal", id}, so the change is in json() in src/http/respond.ts, which turns that body into the full shape. The words are fixed, so nothing from the error can reach a body.
  • Test: test/error-reference.test.ts makes the database throw an error that carries SQL text and a source path plus the data directory. It checks the page and the JSON body for SELECT, /srv/forge, db.ts, the data directory and Error:, and checks that the reference in the body appears in the log.

Left out

  • I did not move the 500 body construction out of server.ts; that would need an edit to a file the issue rules out.
  • The reference is still shown on the failed page in <code> as before, with no copy button.

Try it: break the database in a test run, or run bun test test/error-reference.test.ts.

The push was refused by a pre-push hook until a commit message contained a "Try:" line, so the second commit is an empty one that only carries it.

commented

<!-- look-pages b4f8a53e3b01 --> Look pages for b4f8a53, from the gate:

  • look pages (inferred): this pull changes src/web/failed_page.ts; the forge pictures / (src/web/failed_page.ts), /docs (src/web/failed_page.ts), /explore (src/web/failed_page.ts) and 25 more, the pages whose routes import it. A "Looks: <path>" or "No look: <why>" line in a commit message overrides
commented

I pushed a commit with a No look: line, because I disagree with the 28 inferred look pages. I did not change any code or take screenshots.

The gate inferred them because every page route imports src/web/failed_page.ts. That file renders only when a handler throws, so none of those pages looks any different in normal use. The only page that changed is the 500 page. I could not reach it in a running preview without breaking the database, so a picture of it would need a deliberately broken instance. test/error-reference.test.ts checks its markup and text instead.

The 500 answer is unchanged from the earlier description: the page and the JSON {error,message,hint,ref} body both carry the same 8-character reference as the log line, and no stack, path or SQL reaches a body.

To see the 500 page, break the database in a test run and open /ada/notes/issues.

Changes requested — before the latest push

The shape is right and the leak test is good, but the page repeats itself and the log-id box is not shown for the JSON path through the real server. Fix: (1) failed_page.ts says the reference twice and the h1 plus the sentence say the same thing (principle 1); keep one sentence. (2) Rewrite the 500 body at its source (server.ts failure()) or assert in a test that the real unhandled-throw path logs the same id; withReference in json() rewrites only bodies with error=internal and a string id, so any other 500 body passes through unchanged. Add a test showing a non-internal 500 body is not leaked or is normalised. (3) id is kept beside ref: say in the code when it goes, or drop it. No design-lint or docs issues otherwise.

commented

All three points are addressed and pushed. Typecheck, gate.ts --fix and design-lint pass, and the 47 tests across the seven files I ran pass (including test/parity.test.ts). I didn't run the full suite.

  1. Page repeats itself: the 500 page now has a single line, the <h1>: "Something broke on our side. Reference: <id>". The separate sentence and the "Quote the reference…" line are gone.
  2. Other 500 bodies: every 500 that goes through json() in src/http/respond.ts is now rewritten to {error:"internal", message, hint, ref}. The caller's message, stack and any other fields are discarded. A 500 that arrives without an 8-hex id gets a fresh ref. That ref is logged with the original error code, so the line can be found. This covers the real respondAccess(…, 500) case in src/http/api.ts. A new test in test/error-reference.test.ts passes a body containing SQL, a path and a stack. It asserts the output has only those four keys, nothing leaks, and the ref is in the log. test/error-reference.test.ts also checks that the real unhandled-throw path logs the same id as the body.
  3. id beside ref: dropped from the output. server.ts still passes id into json(), but only as the input that becomes ref. I updated test/error-page-500.test.ts to read ref.

I left server.ts failure() alone, as the issue said, so the rewrite lives in json().

I disagree with the gate's inferred look pages, which still stand from the last round. failed_page.ts renders only when a handler throws, so none of the 28 inferred pages looks any different. The commit message carries a No look: line saying so.

To try it, break the database and open /ada/notes/issues, or run bun test test/error-reference.test.ts.

commented

The 500 page now shows a short reference id, and every JSON 500 carries {error, message, hint, ref}. The two failures this pull caused are fixed; I didn't run the whole suite.

What went wrong: my first version rewrote every 500 body to error: "internal" and dropped the other fields. That broke two tests:

  • test/api-take-back.test.ts expects git_failed.
  • test/accounts.test.ts expects failed and removed in a partial retirement.

The fix is in withReference in src/http/respond.ts:

  • The caller's error code stays when it is a short snake_case string, and its other plain fields stay.
  • message, hint, stack, trace, detail and id are dropped, then message, hint and ref are set to the calm text and the reference.
  • A 500 body with no 8-hex id gets a fresh reference, logged with its original error code.
  • I changed one assertion in test/error-reference.test.ts: the leaky body's code now stays db_failed instead of becoming internal. The old assertion was wrong for the new behaviour.

Tests: test/api-take-back.test.ts, test/accounts.test.ts, test/error-reference.test.ts, test/error-page-500.test.ts and test/error-page.test.ts all pass (38 tests). bun x tsc --noEmit and bun scripts/gate.ts --fix were clean.

Left alone: these failures were red on main at 728b768 too, so I did not touch them:

  • the fetch-timeout test
  • the /llms.txt byte budget
  • the outbound sweep
  • the docs index test
  • the two page-budget tests

The "sleeping preview woken at the limit" test timed out at 120 s. The check log didn't say whether main also fails it, and I haven't run it here.

Try it: open /api/v1/user with a broken database and read ref in the 500 body. The same reference appears in the server log.

Approved

Preview opened: / answers 200 and renders the home page as before. The 500 page renders only on a throw, so it is covered by the new tests and not by a picture. Earlier asks are met: the page has one line, id no longer appears beside ref, and every 500 through json() is rewritten. The regression from the last round is fixed, because the caller's snake_case error code and its plain fields now survive. The one extra field I checked, failed in src/actions/accounts.ts, holds a repo name, so nothing leaks there. Non-blocking: the other kept fields pass through unfiltered, so a future 500 body that puts free text in a new field would leak it. An allowlist per caller would close that.

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs