pub struct ResponseError {
pub code: i32,
pub message: String,
pub data: Option<Value>,
}Expand description
An error response in JSON-RPC format.
Contains a numeric error code, a human-readable message, and optional additional data.
The code field is stored as i32 rather than ErrorCode to support unknown error codes
from clients or other servers.
§Examples
use lsp_server_tokio::{ResponseError, ErrorCode};
// Create a simple error
let error = ResponseError::new(ErrorCode::MethodNotFound, "Method not found");
// Create an error with additional data
let error_with_data = ResponseError::new(ErrorCode::InvalidParams, "Missing required field")
.with_data(serde_json::json!({"field": "uri"}));Fields§
§code: i32A number indicating the error type.
message: StringA string providing a short description of the error.
data: Option<Value>A primitive or structured value with additional information. This may be omitted.
Implementations§
Source§impl ResponseError
impl ResponseError
Sourcepub fn new(code: ErrorCode, message: impl Into<String>) -> Self
pub fn new(code: ErrorCode, message: impl Into<String>) -> Self
Creates a new ResponseError with the given error code and message.
The data field is set to None.
Sourcepub fn new_raw(code: i32, message: impl Into<String>) -> Self
pub fn new_raw(code: i32, message: impl Into<String>) -> Self
Creates a new ResponseError from a raw error code and message.
Use this when dealing with unknown or custom error codes.
Sourcepub fn with_data(self, data: Value) -> Self
pub fn with_data(self, data: Value) -> Self
Adds additional data to this error.
Consumes self and returns a new ResponseError with the data attached.
Sourcepub fn error_code(&self) -> Option<ErrorCode>
pub fn error_code(&self) -> Option<ErrorCode>
Returns the error code as an ErrorCode enum, if it maps to a known code.
Trait Implementations§
Source§impl Clone for ResponseError
impl Clone for ResponseError
Source§fn clone(&self) -> ResponseError
fn clone(&self) -> ResponseError
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more