#[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 auth_required() -> Self
pub fn auth_required() -> Self
Authentication required.
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>,
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 moreimpl 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)