Skip to main content

RpcError

Struct RpcError 

Source
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

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn cancel_unconfirmed(message: impl Into<String>) -> Self

Build a -32010 cancel_unconfirmed error (#8207).

Why: session.cancel blocks until the signalled run has actually stopped, and the run that does not stop in time is NOT an internal fault — it is “still cancelling”, the one answer a client can act on by staying in a cancelling state instead of reporting a daemon bug. The -32603 internal this replaces made the two indistinguishable. The numeric code carries the distinction on its own, and the error_type tag also reaches socket clients: the From conversion onto trusty_common::uds::server::RpcError carries data across. What: data.error_type = "cancel_unconfirmed". -32010 is the next free slot after Self::already_exists’s -32009.

The three consumers in this repo: crate::serve::rest::rpc_error_to_status and trusty_code_gui::bridge::BridgeError::status map it to HTTP 503 — “not yet, retry”, distinct from the 500 both used to send — and crate::tui_client::CodeEngine::cancel_session_outcome returns it as CancelOutcome::StillCancelling. The TUI’s own “still cancelling…” render on top of that outcome is trusty-code-tui’s, and is not in this crate. Test: rpc_error_cancel_unconfirmed_sets_code_and_type.

Trait Implementations§

Source§

impl Clone for RpcError

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for RpcError

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for RpcError

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Error for RpcError

1.30.0 · Source§

fn source(&self) -> Option<&(dyn Error + 'static)>

Returns the lower-level source of this error, if any. Read more
1.0.0 · Source§

fn description(&self) -> &str

👎Deprecated since 1.42.0:

use the Display impl or to_string()

1.0.0 · Source§

fn cause(&self) -> Option<&dyn Error>

👎Deprecated since 1.33.0:

replaced by Error::source, which can support downcasting

Source§

fn provide<'a>(&'a self, request: &mut Request<'a>)

🔬This is a nightly-only experimental API. (error_generic_member_access)
Provides type-based access to context intended for error reports. Read more
Source§

impl From<RpcError> for RpcError

Carry this crate’s error onto the UDS transport’s error type (#6637).

Why: crate::serve::uds answers over trusty_common::uds::server, whose frames carry that crate’s RpcError. Converting here — once, beside the codes it converts — keeps the socket transport from inventing a second mapping, and keeps the code the caller reads identical to the one the same method reports over STDIO or HTTP. What: widens code to i64 and keeps message verbatim. data is carried through with with_data when present (#6285). Test: rpc_error_converts_onto_the_uds_transport_error.

Source§

fn from(err: RpcError) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FromRef<T> for T
where T: Clone,

Source§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<Unshared, Shared> IntoShared<Shared> for Unshared
where Shared: FromUnshared<Unshared>,

Source§

fn into_shared(self) -> Shared

Creates a shared type from an unshared type.
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToCompactString for T
where T: Display,

Source§

impl<T> ToLine for T
where T: Display,

Source§

fn to_line(&self) -> Line<'_>

Converts the value to a Line.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToSpan for T
where T: Display,

Source§

fn to_span(&self) -> Span<'_>

Converts the value to a Span.
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T> ToText for T
where T: Display,

Source§

fn to_text(&self) -> Text<'_>

Converts the value to a Text.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more