fix(workspaces): return 404 for missing workspace files
Draft
PO
3d ago+63+63+01234567890123456789-1-1-0123456789
Problem
- A user who opens a deleted or stale workspace file gets a 500
PREVIEW_LOAD_FAILEDinstead of a not-found state. Each request also captures an exception in error tracking. requireActiveWorkspaceItemRowthrows a plainErrorwhen the row does not exist. The preview and content routes catch onlyWorkspaceForbiddenError, so the not-found case goes toapiFailure.
Origin
- Error tracking: issue
- First signal: 2026-10-13
- Inbox report: open
- Likely cause:
c869ac8 - Task started by: auto-start, after the report was rated P3 and ready to fix
Changes
- A typed
WorkspaceItemNotFoundErrorreplaces the plainErrorinrequireActiveWorkspaceItemRow. The message stays the same, so other callers see no change. - The file preview and file content routes map this error to a 404, next to the 403 branch. A 404 does not go through
apiFailure, so it captures no exception.
| Route | Before | After |
|---|---|---|
GET ā¦/files/$itemId/preview (missing item) | 500 PREVIEW_LOAD_FAILED + exception | 404 PREVIEW_NOT_FOUND |
GET ā¦/files/$itemId/content (missing item) | 500 FILE_LOAD_FAILED + exception | 404 FILE_NOT_FOUND |
The 404 codes are the same codes that these routes already return when the stored object is missing.
Testing
- New
workspace-file-routes.test.ts: both routes return 404 and record no operational failure. Without the route change, both tests fail with a 500. vp check(format, lint, types): pass.vp test --run --project=node src/features/workspaces: 81 files, 365 tests pass.- Skipped: the
workerstest project andvp build. The change does not touch Durable Object code or the build.
Agent context
- The deleted item or stale tab cause is a hypothesis. The event does not show which case it was.
- Other callers of
requireActiveWorkspaceItemRow(server functions, AI tools) still treat the error as a generic failure. I did not change them, to keep this PR focused on the reported routes.
Created with PostHog Desktop from this inbox report.
š¤ Generated with Claude Code
Need help on this PR? Tag @codesmith-bot with what you need.