pub struct ErrorCode(pub i64);Expand description
A JSON-RPC error code.
The constants are the five codes JSON-RPC 2.0 defines, plus three the
crate itself answers with. Any integer is a valid code; protocols define
their own (LSP’s ContentModified is -32801, LexerSketch’s “stale
version” is 1001), and a peer’s code is passed through as it was sent.
§Examples
use rpc_io::ErrorCode;
assert_eq!(ErrorCode::METHOD_NOT_FOUND.0, -32601);
assert_eq!(ErrorCode::METHOD_NOT_FOUND.name(), Some("method not found"));
assert_eq!(ErrorCode(1001).name(), None);
assert_eq!(ErrorCode::INVALID_PARAMS.to_string(), "-32602 (invalid params)");Tuple Fields§
§0: i64Implementations§
Source§impl ErrorCode
impl ErrorCode
Sourcepub const PARSE_ERROR: ErrorCode
pub const PARSE_ERROR: ErrorCode
-32700: the message is not valid JSON.
Sourcepub const INVALID_REQUEST: ErrorCode
pub const INVALID_REQUEST: ErrorCode
-32600: the message is JSON but not a valid request object.
Sourcepub const METHOD_NOT_FOUND: ErrorCode
pub const METHOD_NOT_FOUND: ErrorCode
-32601: no handler is registered for the method.
Sourcepub const INVALID_PARAMS: ErrorCode
pub const INVALID_PARAMS: ErrorCode
-32602: the params are not what the method takes.
Sourcepub const INTERNAL_ERROR: ErrorCode
pub const INTERNAL_ERROR: ErrorCode
-32603: the server failed, for example a handler panicked.
Sourcepub const SERVER_OVERLOADED: ErrorCode
pub const SERVER_OVERLOADED: ErrorCode
-32000: too many requests are already being answered. The first code
of the range JSON-RPC 2.0 reserves for implementation-defined server
errors.
Sourcepub const SERVER_NOT_INITIALIZED: ErrorCode
pub const SERVER_NOT_INITIALIZED: ErrorCode
-32002: a request arrived before the protocol’s opening request
succeeded (LSP’s ServerNotInitialized); see
Gate.
Sourcepub const REQUEST_CANCELLED: ErrorCode
pub const REQUEST_CANCELLED: ErrorCode
-32800: the request was cancelled by its sender (LSP’s
RequestCancelled); see Cancellation.
Sourcepub const fn name(self) -> Option<&'static str>
pub const fn name(self) -> Option<&'static str>
A short name for the codes this crate defines, None for others.
§Examples
assert_eq!(rpc_io::ErrorCode::PARSE_ERROR.name(), Some("parse error"));Sourcepub const fn is_reserved(self) -> bool
pub const fn is_reserved(self) -> bool
Whether the code lies in -32768..=-32000, the range JSON-RPC 2.0
reserves for predefined and implementation-defined errors.
§Examples
use rpc_io::ErrorCode;
assert!(ErrorCode::INTERNAL_ERROR.is_reserved());
assert!(!ErrorCode(1001).is_reserved());