fix: server error paths that still answered an empty 500 or lost the message
Ā
RA
1d ago+153+153+012345678901234567890123456789-15-15-01234567890123456789
Issue for this PR
Closes #1846
Type of change
- Bug fix
What does this PR do?
Covers the server error paths #1788 didn't reach.
- Unknown /api paths. A path no route serves, such as
GET /api/config, falls through to the web UI proxy. The proxy's failed request reached the /api error middleware as a typed failure, and the middleware passed it on as an empty 500. The middleware now answers any undeclared failure the way it answers a defect: 500 with the fixed message and a ref, and the error recorded in opencode.log under that ref instead of printed. A declared error (an unknown session's 404) keeps its status and body. - Remote config down. A forwarded route (
/experimental/workspace) answers 502 when the remote config answers 500, with the same bodyGET /agentgives. /api routes themselves answer normally while it's down. - prompt_async errors. The Hono prompt_async route, the one the server serves, builds its
session.errorevent like the typed handler: the NamedError's text (Agent not found: "no-such-agent". ā¦), not just its name, and no stack frames.
Limits:
- An unknown /api path still goes through the web UI proxy to the hosted app, which doesn't resolve today, before it fails. The unknown-path test relies on that.
- The other places that publish a session error inside the session loop are unchanged.
- The print check watches every console method and both standard streams'
write. A write throughBun.stdout/Bun.stderror straight to the file descriptors isn't seen.
How did you verify your code works?
- Fail on main: the three new full-server tests fail without the fix; the declared-404 test passes on both. The print check fails against the old logger, and when the middleware prints the error without its ref.
- Local (Linux): the two error test files pass (22). In
test/server/, 406 pass; one MCP status test fails here because it reads this machine's MCP config. Typecheck clean.
Cost side effects
None.
Checklist
- I have tested my changes locally
- I have not included unrelated changes in this PR
- I checked for cost side effects (model calls, queries or cloud resources that grow with user data) and described them, or wrote "none"
š¤ Generated with Claude Code
https://claude.ai/code/session_01BXxzvt5gnJKUdaiAK5SupM
Summary by CodeRabbit
- Bug Fixes
- HTTP errors now return clearer, sanitized messages while preserving relevant status codes and details from upstream services.
- Unexpected server errors display a consistent message without exposing technical details.
- Asynchronous prompt error notifications now show a readable error message without stack traces or internal error names.