#[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>) -> Self
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).
Sourcepub fn data(self, data: impl IntoOption<Value>) -> Self
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.
Sourcepub fn parse_error() -> Self
pub fn parse_error() -> Self
Invalid JSON was received by the server. An error occurred on the server while parsing the JSON text.
Sourcepub fn invalid_request() -> Self
pub fn invalid_request() -> Self
The JSON sent is not a valid Request object.
Sourcepub fn method_not_found() -> Self
pub fn method_not_found() -> Self
The method does not exist / is not available.
Sourcepub fn invalid_params() -> Self
pub fn invalid_params() -> Self
Invalid method parameter(s).
Sourcepub fn internal_error() -> Self
pub fn internal_error() -> Self
Internal JSON-RPC error.
Sourcepub fn request_cancelled() -> Self
Available on crate feature unstable_cancel_request only.
pub fn request_cancelled() -> Self
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() -> Self
pub fn auth_required() -> Self
Authentication required.
Sourcepub fn url_elicitation_required() -> Self
Available on crate feature unstable_elicitation only.
pub fn url_elicitation_required() -> Self
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>) -> Self
pub fn resource_not_found(uri: Option<String>) -> Self
A given resource, such as a file, was not found.
Sourcepub fn into_internal_error(err: impl Error) -> Self
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<'de> Deserialize<'de> for Error
impl<'de> Deserialize<'de> for Error
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::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
Available on crate feature unstable_protocol_v2 only.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
unstable_protocol_v2 only.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) -> Self
fn from(error: ProtocolConversionError) -> Self
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 more