rust_meth_lib/error.rs
1use thiserror::Error;
2
3/// The primary error tracking type for operations within the library.
4///
5/// Encapsulates platform errors (I/O, parsing) along with specific failure modes
6/// encountered during synchronization or communication with the underlying Language Server Protocol (LSP).
7#[derive(Debug, Error)]
8pub enum RustMethError {
9 /// Errors originating from direct operating system interaction or file system operations.
10 #[error("I/O error: {0}")]
11 Io(#[from] std::io::Error),
12
13 /// Errors resulting from failed JSON serialization or deserialization routines.
14 #[error("JSON error: {0}")]
15 Json(#[from] serde_json::Error),
16
17 /// Errors resulting from failed string-to-integer conversions.
18 #[error("Integer parse error: {0}")]
19 ParseInt(#[from] std::num::ParseIntError),
20
21 /// Indication that an unexpected byte payload was read from the language server stream
22 /// due to a missing or improperly formed `Content-Length` header field.
23 #[error("No Content-Length header in LSP response")]
24 NoContentLength,
25
26 /// Raised when looking for a specific LSP message payload, but the message loop bounds
27 /// were reached before a match was resolved.
28 #[error("recv_until: exhausted {limit} messages without a match")]
29 RecvExhausted {
30 /// The maximum number of distinct messages evaluated before halting the loop.
31 limit: usize,
32 },
33
34 /// Raised when `rust-analyzer` returns a payload structurally valid as JSON, but lacking
35 /// the fields or nested objects required by the expected API model contract.
36 #[error("Unexpected completion response shape: {0}")]
37 UnexpectedResponseShape(String),
38
39 /// Indicates that the `rust-analyzer` executable engine could not be discovered
40 /// via the host path environment or native component directory.
41 #[error(
42 "rust-analyzer not found.\nInstall it with: rustup component add rust-analyzer\nor ensure it is on your PATH."
43 )]
44 RustAnalyzerNotFound,
45}
46
47/// A specialized type alias for results returning [`RustMethError`].
48pub type Result<T> = std::result::Result<T, RustMethError>;