Skip to main content

Error

Struct Error 

Source
#[non_exhaustive]
pub struct Error { pub code: ErrorCode, pub message: String, pub data: Option<Value>, }
Available on crate feature unstable_protocol_v2 only.
Expand description

JSON-RPC error object.

Represents an error that occurred during method execution, following the JSON-RPC 2.0 error object specification with optional additional data.

See protocol docs: JSON-RPC Error Object

Fields (Non-exhaustive)§

This struct is marked as non-exhaustive
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.
§code: ErrorCode

A number indicating the error type that occurred. This must be an integer as defined in the JSON-RPC specification.

§message: String

A string providing a short description of the error. The message should be limited to a concise single sentence.

§data: Option<Value>

Optional primitive or structured value that contains additional information about the error. This may include debugging information or context-specific details.

Implementations§

Source§

impl Error

Source

pub fn new(code: i32, message: impl Into<String>) -> Self

Creates a new error with the given code and message.

The code parameter can be an ErrorCode constant or a tuple of (code, message).

Source

pub fn data(self, data: impl IntoOption<Value>) -> Self

Adds additional data to the error.

This method is chainable and allows attaching context-specific information to help with debugging or provide more details about the error.

Source

pub fn parse_error() -> Self

Invalid JSON was received by the server. An error occurred on the server while parsing the JSON text.

Source

pub fn invalid_request() -> Self

The JSON sent is not a valid Request object.

Source

pub fn method_not_found() -> Self

The method does not exist / is not available.

Source

pub fn invalid_params() -> Self

Invalid method parameter(s).

Source

pub fn internal_error() -> Self

Internal JSON-RPC error.

Source

pub fn request_cancelled() -> Self

Available on crate feature unstable_cancel_request only.

UNSTABLE

This capability is not part of the spec yet, and may be removed or changed at any point.

Request was cancelled.

Execution of the method was aborted either due to a cancellation request from the caller or because of resource constraints or shutdown.

Source

pub fn auth_required() -> Self

Authentication required.

Source

pub fn url_elicitation_required() -> Self

Available on crate feature unstable_elicitation only.

UNSTABLE

This capability is not part of the spec yet, and may be removed or changed at any point.

The agent requires user input via a URL-based elicitation before it can proceed.

Source

pub fn resource_not_found(uri: Option<String>) -> Self

A given resource, such as a file, was not found.

Source

pub fn into_internal_error(err: impl Error) -> Self

Converts a standard error into an internal JSON-RPC error.

The error’s string representation is included as additional data.

Trait Implementations§

Source§

impl Clone for Error

Source§

fn clone(&self) -> Error

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 Error

Source§

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

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

impl<'de> Deserialize<'de> for Error

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Display for Error

Source§

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

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

impl Eq for Error

Source§

impl Error for Error

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<Error> for Error

Source§

fn from(error: Error) -> Self

Converts to this type from the input type.
Source§

impl From<Error> for Error

Source§

fn from(error: Error) -> Self

Converts to this type from the input type.
Source§

impl From<ErrorCode> for Error

Source§

fn from(error_code: ErrorCode) -> Self

Converts to this type from the input type.
Source§

impl From<ProtocolConversionError> for Error

Mirror of the v1 From impl for the v2 Error type.

Source§

fn from(error: ProtocolConversionError) -> Self

Converts to this type from the input type.
Source§

impl IntoV1 for Error

Source§

type Output = Error

The corresponding v1 type.
Source§

fn into_v1(self) -> Result<Self::Output>

Converts this value into the corresponding v1 type. Read more
Source§

impl JsonSchema for Error

Source§

fn schema_name() -> Cow<'static, str>

The name of the generated JSON Schema. Read more
Source§

fn schema_id() -> Cow<'static, str>

Returns a string that uniquely identifies the schema produced by this type. Read more
Source§

fn json_schema(generator: &mut SchemaGenerator) -> Schema

Generates a JSON Schema for this type. Read more
Source§

fn inline_schema() -> bool

Whether JSON Schemas generated for this type should be included directly in parent schemas, rather than being re-used where possible using the $ref keyword. Read more
Source§

impl PartialEq for Error

Source§

fn eq(&self, other: &Error) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for Error

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for Error

Auto Trait Implementations§

§

impl Freeze for Error

§

impl RefUnwindSafe for Error

§

impl Send for Error

§

impl Sync for Error

§

impl Unpin for Error

§

impl UnsafeUnpin for Error

§

impl UnwindSafe for Error

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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

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

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> IntoMaybeUndefined<T> for T

Source§

impl<T> IntoOption<T> for T

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> 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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