#[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 auth_required() -> Error
pub fn auth_required() -> Error
Authentication required.
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>,
Source§impl Error for Error
impl Error for Error
1.30.0§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
1.0.0§fn description(&self) -> &str
fn description(&self) -> &str
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 Eq for Error
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 UnwindSafe for Error
Blanket Implementations§
§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§unsafe fn clone_to_uninit(&self, dest: *mut u8)
unsafe fn clone_to_uninit(&self, dest: *mut u8)
clone_to_uninit)