fix(host-service): classify a client disconnect during listDirectory as a non-500
Problem
filesystem.listDirectory reports a 500 to Sentry when the desktop closes the connection while a listing is still running. Nothing failed: nobody is left to receive the answer. This family has grown from one event to about 30 since it was first archived (HOST-SERVICE-4H). Each new desktop bundle also changes the fingerprint, so it comes back as a new high-priority alert (HOST-SERVICE-B3).
Root cause
When the client disconnects, @hono/node-server aborts the request's AbortController with a string reason (abortController.abort("Client connection prematurely closed.")). tRPC passes the procedure an AbortSignal.any([req.signal, …]), which carries that reason. listDirectory in @superset/workspace-fs calls signal.throwIfAborted(), which throws the string unchanged. withFsErrorTranslation does not recognise it, so tRPC wraps it via getCauseFromUnknown as INTERNAL_SERVER_ERROR, and sentryMiddleware reports it.
This is a misclassification at the throw site, the same shape as #7329 for worker aborts.
Fix
In the listDirectory procedure, a rejection whose value is the aborted signal's reason (signal.aborted && error === signal.reason) becomes CLIENT_CLOSED_REQUEST. Every other failure keeps its 500, including a real error thrown after the abort and a thrown string when the signal did not fire. No change to the Sentry boundary.
Verification
Negative tests were written first and pass before and after the change. The positive test fails before the change:
$ bun test src/trpc/router/filesystem # without the fix
Expected: "CLIENT_CLOSED_REQUEST"
Received: "INTERNAL_SERVER_ERROR"
(fail) filesystem.listDirectory abort classification > a client disconnect is CLIENT_CLOSED_REQUEST
2 pass
1 fail
$ bun test src/trpc/router/filesystem # with the fix
3 pass
0 fail
3 expect() calls
Ran 3 tests across 1 file.
$ bunx biome check packages/host-service/src/trpc/router/filesystem/filesystem.ts packages/host-service/src/trpc/router/filesystem/filesystem.test.ts
Checked 2 files in 36ms. No fixes applied.
$ cd packages/host-service && bun run typecheck
$ tsc --noEmit --emitDeclarationOnly false
(no errors)
Refs HOST-SERVICE-B3
Summary by cubic
Stops filesystem.listDirectory from reporting a 500 to Sentry when the desktop drops the connection while a listing is in flight. When the HTTP server aborts the request signal with a string reason, that value is now classified as CLIENT_CLOSED_REQUEST; any other failure keeps its 500. Adds tests covering a client disconnect, a real error after the abort, and a thrown string without an abort.
Summary by CodeRabbit
- Bug Fixes
- Directory listing requests canceled by the client are now reported as client-closed errors instead of being classified as internal server errors.
- Genuine filesystem failures and unexpected errors continue to be reported as internal server errors, keeping cancellation distinct from actual failures. This makes directory listing error responses more accurately reflect whether a request was canceled or encountered a problem.