Skip to content

Map hardware errors to specific tRPC error codes (TIMEOUT, CONFLICT) #110

@ng

Description

@ng

Summary

All hardware errors in the device router currently map to INTERNAL_SERVER_ERROR via withHardwareClient. As the frontend matures, it would benefit from more specific error codes to enable better UX (e.g., retry prompts for timeouts, conflict resolution for concurrent operations).

Current Behavior (helpers.ts)

withHardwareClient wraps all hardware failures in a generic INTERNAL_SERVER_ERROR:

throw new TRPCError({
  code: 'INTERNAL_SERVER_ERROR',
  message: errorMessage,
})

Proposed Improvement

Map known hardware error types to appropriate tRPC codes:

Hardware Error tRPC Code Frontend UX
Connection timeout TIMEOUT "Device not responding, retry?"
Already priming CONFLICT "Priming already in progress"
Device unreachable PRECONDITION_FAILED "Check device connection"
Command rejected BAD_REQUEST Show specific rejection reason

Implementation Notes

  • Requires understanding the error types/codes that the hardware client throws
  • Could be implemented by catching specific error types in withHardwareClient or per-procedure
  • Should be done when the frontend is ready to handle these codes — no value in adding granularity the client doesn't use yet
  • Non-breaking: frontend currently treats all errors the same, so this is purely additive

Priority

Low — implement when frontend error handling becomes more sophisticated and needs to differentiate between error types.

🤖 Generated with Claude Code

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions