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_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 not_found(message: impl Into<String>) -> Self
pub fn not_found(message: impl Into<String>) -> Self
Build a -32002 not_found error (vision spec §13.2).
Why: the spec’s general “the thing you named does not exist” code,
distinct from the session-specific -32007 session_not_found — used by
methods whose subject is not a session (e.g. fs.list_dir on a path
that isn’t there).
What: data.error_type = "not_found".
Test: rpc_error_not_found_sets_code_and_type.
Sourcepub fn permission_denied(message: impl Into<String>) -> Self
pub fn permission_denied(message: impl Into<String>) -> Self
Build a -32001 permission_denied error (vision spec §13.2).
Why: the spec’s “caller lacks permission” code. tcode adds no permission
layer of its own — it runs as the user with the user’s entitlements — so
this reports an OS-level refusal (e.g. an unreadable directory) rather
than a policy decision tcode made.
What: data.error_type = "permission_denied".
Test: rpc_error_permission_denied_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.
Sourcepub fn active_conflict(active_id: impl Display) -> Self
pub fn active_conflict(active_id: impl Display) -> Self
Build a -32008 active_conflict error (DOC-48 §5.2/§6.1, issue #3294).
Why: workstream.activate{id, force: false} must fail when a
DIFFERENT workstream is already active, and the caller needs the
currently-active id to decide whether to retry with force: true
(§6.1: “the error includes the ID of the currently-active
workstream”). -32008 is the next free slot after -32007 session_not_found in this crate’s domain-error range — DOC-48
predates no reservation for it in the vision spec’s §13.2 table, so
it is allocated here rather than colliding with the reserved-but-
unimplemented -32004/-32005/-32006 (timeout/cancelled/
provider_failure).
What: data = {"error_type": "active_conflict", "active_id": <uuid string>} — active_id rides alongside the standard error_type tag
so a client can read the conflicting id without re-parsing message.
Test: rpc_error_active_conflict_sets_code_and_active_id.
Sourcepub fn already_exists(message: impl Into<String>) -> Self
pub fn already_exists(message: impl Into<String>) -> Self
Build a -32009 already_exists error (issue #3449).
Why: agents.create/skills.create must refuse to overwrite an
existing disk entry, and that conflict needs its OWN code — an early
cut reused the literal -32008, but that slot is
Self::active_conflict’s (DOC-48 §5.2, constructor-backed, and
asserted on numerically by the workstreams tests), so sharing it
would make the two semantically different conflicts
indistinguishable to a client matching on code (code-critic PR #3465
review, LOW). -32009 is the next free slot after it.
What: data.error_type = "already_exists". The REST layer maps this
to 409 Conflict (serve::rest::rpc_error_to_status), same HTTP
status as active_conflict — the distinction lives in the JSON-RPC
code/error_type, where protocol clients look.
Test: rpc_error_already_exists_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 moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<T> ToCompactString for Twhere
T: Display,
impl<T> ToCompactString for Twhere
T: Display,
Source§fn try_to_compact_string(&self) -> Result<CompactString, ToCompactStringError>
fn try_to_compact_string(&self) -> Result<CompactString, ToCompactStringError>
ToCompactString::to_compact_string() Read moreSource§fn to_compact_string(&self) -> CompactString
fn to_compact_string(&self) -> CompactString
CompactString. Read more