Skip to main content

cs2_gsi/
error.rs

1//! Error types for cs2-gsi.
2
3use std::path::PathBuf;
4use thiserror::Error;
5
6/// Result alias used throughout the library.
7pub type Result<T, E = Error> = std::result::Result<T, E>;
8
9/// Errors that can be returned by the public API.
10#[derive(Debug, Error)]
11#[non_exhaustive]
12pub enum Error {
13    /// Failed to bind the HTTP listener.
14    #[error("failed to bind HTTP listener on {addr}: {source}")]
15    Bind {
16        /// Socket address we tried to bind.
17        addr: String,
18        /// Underlying I/O error.
19        #[source]
20        source: std::io::Error,
21    },
22
23    /// Generic I/O error (file system, sockets, …).
24    #[error("io error: {0}")]
25    Io(#[from] std::io::Error),
26
27    /// Failed to parse JSON received from CS2.
28    #[error("failed to parse GSI payload: {0}")]
29    Parse(#[from] serde_json::Error),
30
31    /// CS2 install directory could not be located.
32    #[error("could not locate Counter-Strike 2 installation: {0}")]
33    SteamDiscovery(String),
34
35    /// `gamestate_integration_*.cfg` could not be written.
36    #[error("failed to write GSI cfg file at {path}: {source}")]
37    CfgWrite {
38        /// Target path we tried to write.
39        path: PathBuf,
40        /// Underlying I/O error.
41        #[source]
42        source: std::io::Error,
43    },
44
45    /// Listener was already started.
46    #[error("listener has already been started")]
47    AlreadyStarted,
48
49    /// Listener was not started yet.
50    #[error("listener is not running")]
51    NotRunning,
52}