#[non_exhaustive]pub struct Error {
pub code: ErrorCode,
pub message: String,
pub data: Option<Value>,
}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
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.code: ErrorCodeA number indicating the error type that occurred. This must be an integer as defined in the JSON-RPC specification.
message: StringA 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
impl Error
Sourcepub fn new(code: i32, message: impl Into<String>) -> Error
pub fn new(code: i32, message: impl Into<String>) -> Error
Creates a new error with the given code and message.
The code parameter can be an ErrorCode constant or a tuple of (code, message).
Sourcepub fn data(self, data: impl IntoOption<Value>) -> Error
pub fn data(self, data: impl IntoOption<Value>) -> Error
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.
Sourcepub fn parse_error() -> Error
pub fn parse_error() -> Error
Invalid JSON was received by the server. An error occurred on the server while parsing the JSON text.
Sourcepub fn invalid_request() -> Error
pub fn invalid_request() -> Error
The JSON sent is not a valid Request object.
Sourcepub fn method_not_found() -> Error
pub fn method_not_found() -> Error
The method does not exist / is not available.
Sourcepub fn invalid_params() -> Error
pub fn invalid_params() -> Error
Invalid method parameter(s).
Sourcepub fn internal_error() -> Error
pub fn internal_error() -> Error
Internal JSON-RPC error.
Sourcepub fn request_cancelled() -> Error
Available on crate feature unstable_cancel_request only.
pub fn request_cancelled() -> Error
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.
Sourcepub fn auth_required() -> Error
pub fn auth_required() -> Error
Authentication required.
Sourcepub fn url_elicitation_required() -> Error
Available on crate feature unstable_elicitation only.
pub fn url_elicitation_required() -> Error
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.
Sourcepub fn resource_not_found(uri: Option<String>) -> Error
pub fn resource_not_found(uri: Option<String>) -> Error
A given resource, such as a file, was not found.
Sourcepub fn into_internal_error(err: impl Error) -> Error
pub fn into_internal_error(err: impl Error) -> Error
Converts a standard error into an internal JSON-RPC error.
The error’s string representation is included as additional data.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Error
impl<'de> Deserialize<'de> for Error
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<Error, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<Error, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
impl Eq for Error
Source§impl Error for Error
impl Error for Error
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()
Source§impl From<ProtocolConversionError> for Error
Converts a ProtocolConversionError into a v1 Error
so callers can use ? to bubble conversion failures through APIs that
already speak the v1 error type.
impl From<ProtocolConversionError> for Error
Converts a ProtocolConversionError into a v1 Error
so callers can use ? to bubble conversion failures through APIs that
already speak the v1 error type.
The conversion is mapped onto Error::internal_error
because a failed cross-version conversion always indicates a protocol
mismatch on this side of the wire rather than a client mistake.
Source§fn from(error: ProtocolConversionError) -> Error
fn from(error: ProtocolConversionError) -> Error
Source§impl JsonSchema for Error
impl JsonSchema for Error
Source§fn schema_id() -> Cow<'static, str>
fn schema_id() -> Cow<'static, str>
Source§fn json_schema(generator: &mut SchemaGenerator) -> Schema
fn json_schema(generator: &mut SchemaGenerator) -> Schema
Source§fn inline_schema() -> bool
fn inline_schema() -> bool
$ref keyword. Read moreSource§impl Serialize for Error
impl Serialize for Error
Source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
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> 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,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.