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
Check · Review · Land · Live done — Landed and live in production.
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.
shipped production is serving it deploy 4ec2c16
4 earlier comments · 1 event
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 fromsrc/web/failed_page.ts, andtest/error-page.test.tsasserted 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 keptidalongsiderefso existing callers don't break. - Where the JSON change lives:
src/http/server.tsis off-limits. Itsfailure()still builds{error:"internal", id}, so the change is injson()insrc/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.tsmakes 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 forSELECT,/srv/forge,db.ts, the data directory andError:, 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.
<!-- 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
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.
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.
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.
- 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. - Other 500 bodies: every 500 that goes through
json()insrc/http/respond.tsis now rewritten to{error:"internal", message, hint, ref}. The caller'smessage,stackand any other fields are discarded. A 500 that arrives without an 8-hexidgets a freshref. Thatrefis logged with the originalerrorcode, so the line can be found. This covers the realrespondAccess(…, 500)case insrc/http/api.ts. A new test intest/error-reference.test.tspasses a body containing SQL, a path and a stack. It asserts the output has only those four keys, nothing leaks, and therefis in the log.test/error-reference.test.tsalso checks that the real unhandled-throw path logs the same id as the body. idbesideref: dropped from the output.server.tsstill passesidintojson(), but only as the input that becomesref. I updatedtest/error-page-500.test.tsto readref.
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.
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.tsexpectsgit_failed.test/accounts.test.tsexpectsfailedandremovedin a partial retirement.
The fix is in withReference in src/http/respond.ts:
- The caller's
errorcode stays when it is a short snake_case string, and its other plain fields stay. message,hint,stack,trace,detailandidare dropped, thenmessage,hintandrefare set to the calm text and the reference.- A 500 body with no 8-hex
idgets a fresh reference, logged with its originalerrorcode. - I changed one assertion in
test/error-reference.test.ts: the leaky body's code now staysdb_failedinstead of becominginternal. 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.txtbyte 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.
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.
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-idheader.Typecheck,
gate.ts --fixand design-lint pass. The newtest/error-reference.test.ts,test/error-page-500.test.ts,test/error-page.test.tsandtest/security-floor-errors.test.tspass (15 tests). I did not run the full suite or take before/after screenshots.What changed
Something broke on our side. Reference: <code>. The old "The forge failed to show this page" sentence is gone fromsrc/web/failed_page.ts, andtest/error-page.test.tsasserted the old wording, so I updated that assertion.{error:"internal", message:"Something broke on our side. Reference: <id>", hint, ref}. I keptidalongsiderefso existing callers don't break.src/http/server.tsis off-limits. Itsfailure()still builds{error:"internal", id}, so the change is injson()insrc/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/error-reference.test.tsmakes 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 forSELECT,/srv/forge,db.ts, the data directory andError:, and checks that the reference in the body appears in the log.Left out
server.ts; that would need an edit to a file the issue rules out.<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