Skip to main content

league_link/
error.rs

1use thiserror::Error;
2
3/// The unified error type for all `league-link` operations.
4#[derive(Debug, Error)]
5pub enum LcuError {
6    /// No running League Client process was found.
7    #[error("League Client is not running")]
8    NotRunning,
9
10    /// [`authenticate`] exceeded its timeout without finding the client.
11    ///
12    /// [`authenticate`]: crate::auth::authenticate
13    #[error("authentication timed out")]
14    AuthTimeout,
15
16    /// Underlying `reqwest` transport error (DNS, TLS, body decode, timeout, …).
17    #[error("HTTP error: {0}")]
18    Http(#[from] reqwest::Error),
19
20    /// The LCU returned a non-2xx status code.
21    #[error("HTTP status {code}: {body}")]
22    Status {
23        /// The HTTP status code returned by the LCU.
24        code: u16,
25        /// Response body verbatim — typically a JSON error payload such as
26        /// `{"errorCode":"RESOURCE_NOT_FOUND","message":"..."}`.
27        body: String,
28    },
29
30    /// WebSocket-level error from `tokio-tungstenite`.
31    #[error("WebSocket error: {0}")]
32    WebSocket(#[from] tokio_tungstenite::tungstenite::Error),
33
34    /// TLS handshake or configuration failure.
35    #[error("TLS error: {0}")]
36    Tls(#[from] native_tls::Error),
37
38    /// Could not construct a valid `Authorization` header from the credentials.
39    ///
40    /// The contained string is the source error's display message; the
41    /// concrete dependency type is intentionally not exposed so that
42    /// `tungstenite` upgrades are not breaking changes for this crate.
43    #[error("invalid header value: {0}")]
44    InvalidHeader(String),
45
46    /// JSON (de)serialization failure.
47    #[error("JSON error: {0}")]
48    Json(#[from] serde_json::Error),
49
50    /// Filesystem error while reading a lockfile.
51    #[error("IO error: {0}")]
52    Io(#[from] std::io::Error),
53
54    /// The lockfile contents did not match the expected `name:pid:port:password:protocol` layout.
55    #[error("lockfile parse error: {0}")]
56    LockfileParse(String),
57}