Typed error codes and structured error data #5

Closed
mik-tf wants to merge 0 commits from development_typed_error_codes into development
Owner

Add named error code constants and structured data field to the JSON-RPC error types.

Changes

  • error_codes module in jsonrpc.rs — named constants for all JSON-RPC 2.0 codes and APPLICATION_ERROR
  • JsonRpcError.data changed from Option<String> to Option<Value>
  • is_application_error() and is_method_not_found() helpers on JsonRpcError
  • All constructors use named constants instead of bare literals
  • Matching pub mod error_codes in client lib.rs for consumer-side error discrimination
  • data: Option<Value> added to internal client RpcError deserialization struct

Testing

  • cargo check passes clean (one pre-existing dead_code warning in generators)

Closes #4

Add named error code constants and structured data field to the JSON-RPC error types. ## Changes - `error_codes` module in `jsonrpc.rs` — named constants for all JSON-RPC 2.0 codes and `APPLICATION_ERROR` - `JsonRpcError.data` changed from `Option<String>` to `Option<Value>` - `is_application_error()` and `is_method_not_found()` helpers on `JsonRpcError` - All constructors use named constants instead of bare literals - Matching `pub mod error_codes` in client `lib.rs` for consumer-side error discrimination - `data: Option<Value>` added to internal client `RpcError` deserialization struct ## Testing - `cargo check` passes clean (one pre-existing dead_code warning in generators) Closes #4
Server (jsonrpc.rs):
- Add error_codes module with standard JSON-RPC 2.0 constants
  (PARSE_ERROR, INVALID_REQUEST, METHOD_NOT_FOUND, INVALID_PARAMS,
  INTERNAL_ERROR, APPLICATION_ERROR)
- Change JsonRpcError.data from Option<String> to Option<Value>
  so structured data can be attached to any error response
- Add is_application_error() and is_method_not_found() helpers
  for cleaner error dispatch on the server side
- Use named constants in all constructors instead of bare literals

Client (lib.rs):
- Add pub mod error_codes with the same constants so consumers
  can distinguish error types without magic-number comparisons
- Add data: Option<Value> to internal RpcError deserialization
  struct so the full server payload is captured (no data loss)
- Document ClientError::Rpc to point at error_codes module

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
mik-tf changed title from WIP: Typed error codes and structured error data to Typed error codes and structured error data 2026-03-02 19:30:55 +00:00
mik-tf closed this pull request 2026-03-09 18:53:15 +00:00

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
lhumina_code/hero_rpc!5
No description provided.