fix(desktop): classify quit-time terminal-host disposal as typed non-500

Merged
SA
3mo ago
+63-20

Summary

Refs DESKTOP-HD: a normal app quit racing an in-flight terminal request was being reported as a 500.

During quit, runQuitCleanup → disposeTerminalHostClient → dispose → disconnect → resetConnectionState rejected every pending terminal-host request with a generic Error("Connection lost"). An in-flight terminal.createOrAttach mutation then surfaced that as INTERNAL_SERVER_ERROR, which the Sentry tRPC middleware captures.

Changes

Per the error-handling contract (#6164 — typed causes at throw sites, never a Sentry filter):

  • TerminalHostClient.disconnect() (the intentional teardown path: dispose/shutdown) now rejects pending requests with a typed TerminalHostClientDisposedError instead of the generic error.
  • The terminal.createOrAttach catch translates that error to PRECONDITION_FAILED with cause: { kind: "TERMINAL_HOST_CLIENT_DISPOSED" }, so it never reaches the Sentry middleware as a 500.
  • Genuine unexpected connection loss (handleDisconnect on socket drop, connect-failure resets) keeps the generic Error("Connection lost") rejection and still reports.

Verification

  • bunx biome check clean on both changed files
  • cd apps/desktop && bun run typecheck passes

https://claude.ai/code/session_017sk3KSZ5NLrpTedKWRX2k8


Summary by cubic

Prevent normal app quit from being reported as a 500 when a terminal request is in flight. Quit-time terminal-host teardown now uses a typed error and maps to a non-500 tRPC code.

  • Bug Fixes
    • Added TerminalHostClientDisposedError; used on explicit disconnect/dispose to reject pending requests.
    • In terminal.createOrAttach, translate this to PRECONDITION_FAILED with cause: { kind: "TERMINAL_HOST_CLIENT_DISPOSED" }; unexpected socket drops keep the generic "Connection lost" and still report.

Summary by CodeRabbit

  • Bug Fixes
    • Improved terminal connection error handling during intentional shutdowns.
    • Standardized error responses when terminal sessions are disposed.
    • Preserved clear “connection lost” messaging for unexpected disconnects.
    • Improved handling of pending terminal requests during connection resets.