pub struct ResponseError { /* private fields */ }Expand description
A JSON-RPC error: the failed outcome of a request, sent back to the client in place of a result.
A handler returns one to refuse or fail a request; the server also sends
them itself for protocol violations (a request before initialize, an
unknown method, malformed JSON). The associated constants are the codes
JSON-RPC and the protocol define; pick the one that tells the client what to
do next. For instance CONTENT_MODIFIED
asks it to retry against the newer text, while
REQUEST_FAILED says the request was
understood but could not be served.
§Examples
use lsp_lang::ResponseError;
let err = ResponseError::new(ResponseError::REQUEST_FAILED, "no project loaded");
assert_eq!(err.code(), -32803);
assert_eq!(err.message(), "no project loaded");
assert_eq!(err.to_string(), "no project loaded (code -32803)");Implementations§
Source§impl ResponseError
impl ResponseError
Sourcepub const PARSE_ERROR: i32 = -32700
pub const PARSE_ERROR: i32 = -32700
Invalid JSON was received. Sent by the server; a handler never sees it.
Sourcepub const INVALID_REQUEST: i32 = -32600
pub const INVALID_REQUEST: i32 = -32600
The message is not a valid request object.
Sourcepub const METHOD_NOT_FOUND: i32 = -32601
pub const METHOD_NOT_FOUND: i32 = -32601
The method does not exist or is not supported. The default answer of
the Handler methods a language does not implement.
Sourcepub const INVALID_PARAMS: i32 = -32602
pub const INVALID_PARAMS: i32 = -32602
The parameters are invalid. What the from_json conversions return on
a mismatch.
Sourcepub const INTERNAL_ERROR: i32 = -32603
pub const INTERNAL_ERROR: i32 = -32603
An internal error, such as a result that failed to serialize.
Sourcepub const SERVER_NOT_INITIALIZED: i32 = -32002
pub const SERVER_NOT_INITIALIZED: i32 = -32002
A request arrived before initialize. Sent by the server.
Sourcepub const REQUEST_FAILED: i32 = -32803
pub const REQUEST_FAILED: i32 = -32803
The request was understood but failed; the message says why.
Sourcepub const SERVER_CANCELLED: i32 = -32802
pub const SERVER_CANCELLED: i32 = -32802
The server cancelled the request; the client may retry it.
Sourcepub const CONTENT_MODIFIED: i32 = -32801
pub const CONTENT_MODIFIED: i32 = -32801
The document changed while the request was served, so its result would be stale; the client should retry against the new content.
Sourcepub const REQUEST_CANCELLED: i32 = -32800
pub const REQUEST_CANCELLED: i32 = -32800
The client cancelled the request ($/cancelRequest).
Sourcepub fn new(code: i32, message: impl Into<String>) -> Self
pub fn new(code: i32, message: impl Into<String>) -> Self
Builds an error with code and a human-readable message.
The message is shown to the user by some clients; say what failed and, where it helps, what to do about it.
§Examples
use lsp_lang::ResponseError;
let err = ResponseError::new(ResponseError::INVALID_PARAMS, "position is outside the document");
assert_eq!(err.code(), ResponseError::INVALID_PARAMS);Sourcepub fn with_data(self, data: Value<'static>) -> Self
pub fn with_data(self, data: Value<'static>) -> Self
Attaches structured details (error.data) for clients that act on
them.
§Examples
use lsp_lang::{json, ResponseError};
let err = ResponseError::new(ResponseError::REQUEST_FAILED, "stale")
.with_data(json!({ "expected": 4 }));
assert_eq!(err.data().and_then(|d| d["expected"].as_i64()), Some(4));Sourcepub const fn code(&self) -> i32
pub const fn code(&self) -> i32
Returns the error code.
§Examples
use lsp_lang::ResponseError;
assert_eq!(ResponseError::new(-1, "x").code(), -1);Trait Implementations§
Source§impl Clone for ResponseError
impl Clone for ResponseError
Source§impl Debug for ResponseError
impl Debug for ResponseError
Source§impl Display for ResponseError
impl Display for ResponseError
Source§impl Error for ResponseError
impl Error for ResponseError
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<Error> for ResponseError
impl From<Error> for ResponseError
Source§fn from(error: Error) -> Self
fn from(error: Error) -> Self
Turns a library error met while serving a request, in practice a send
that failed, into an INTERNAL_ERROR
response.
Source§impl From<Error> for ResponseError
impl From<Error> for ResponseError
Source§fn from(error: Error) -> Self
fn from(error: Error) -> Self
A JSON error met while reading a request’s parameters becomes an
INVALID_PARAMS response.
Source§impl From<ErrorObject> for ResponseError
impl From<ErrorObject> for ResponseError
Source§fn from(error: ErrorObject) -> Self
fn from(error: ErrorObject) -> Self
Reads the transport’s error object: a code outside i32 reads as
INTERNAL_ERROR, and data that does not parse is dropped.