pub struct RpcError {
pub code: i32,
pub message: String,
pub data: Option<Value>,
}Expand description
A JSON-RPC 2.0 error, as returned by a method handler.
Why: mirrors trusty_common::mcp::JsonRpcError’s shape so the router can
convert one into the other with a straight field copy, but stays a
separate type so handler code never has to construct the wire envelope
directly.
What: code is a JSON-RPC error code (spec-defined or application
range); message is human-readable; data is optional structured detail
attached to the wire error.
Test: rpc_error_invalid_params_sets_code, rpc_error_internal_sets_code.
Fields§
§code: i32§message: String§data: Option<Value>Implementations§
Source§impl RpcError
impl RpcError
Sourcepub fn new(code: i32, message: impl Into<String>) -> Self
pub fn new(code: i32, message: impl Into<String>) -> Self
Construct an RpcError with an arbitrary code.
Why: escape hatch for application-defined codes outside the standard
JSON-RPC range (e.g. a future domain-specific error).
What: sets code/message, leaves data unset.
Test: rpc_error_new_has_no_data_by_default.
Sourcepub fn with_data(self, data: Value) -> Self
pub fn with_data(self, data: Value) -> Self
Attach structured data to an existing error.
Why: some failures carry machine-readable detail (e.g. which field
failed validation) beyond the human-readable message.
What: builder-style setter; returns self for chaining.
Test: rpc_error_with_data_attaches_payload.
Sourcepub fn invalid_params(message: impl Into<String>) -> Self
pub fn invalid_params(message: impl Into<String>) -> Self
Build a -32602 Invalid params error.
Why: the standard code a handler returns when it cannot parse or
validate its params argument.
What: code = error_codes::INVALID_PARAMS.
Test: rpc_error_invalid_params_sets_code.
Sourcepub fn internal(message: impl Into<String>) -> Self
pub fn internal(message: impl Into<String>) -> Self
Build a -32603 Internal error error.
Why: the standard code for a handler-side failure that isn’t the
caller’s fault (I/O failure, downstream panic-free error, etc.).
What: code = error_codes::INTERNAL_ERROR.
Test: rpc_error_internal_sets_code.
Sourcepub fn session_not_found(session_id: &str) -> Self
pub fn session_not_found(session_id: &str) -> Self
Build a -32007 session_not_found error (vision spec §13.2).
Why: the specific, spec-named code for “the session id in params
does not exist in the registry” — used by every session.* method
that takes a session_id.
What: message embeds session_id for operator-visible logs;
data.error_type = "session_not_found".
Test: rpc_error_session_not_found_sets_code_and_type.
Sourcepub fn invalid_argument(message: impl Into<String>) -> Self
pub fn invalid_argument(message: impl Into<String>) -> Self
Build a -32003 invalid_argument error (vision spec §13.2).
Why: the spec’s domain-level “malformed request” code, distinct from
the JSON-RPC protocol-level -32602 Invalid params — used when a
method’s arguments parse as JSON but fail a semantic check (e.g. an
empty task description).
What: data.error_type = "invalid_argument".
Test: rpc_error_invalid_argument_sets_code_and_type.
Trait Implementations§
Source§impl Error for RpcError
impl Error for RpcError
1.30.0 · Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
use the Display impl or to_string()
Auto Trait Implementations§
impl Freeze for RpcError
impl RefUnwindSafe for RpcError
impl Send for RpcError
impl Sync for RpcError
impl Unpin for RpcError
impl UnsafeUnpin for RpcError
impl UnwindSafe for RpcError
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more