Skip to main content

redis_server_wrapper/
error.rs

1//! Error types for redis-server-wrapper.
2
3use std::io;
4
5/// Errors returned by redis-server-wrapper operations.
6#[derive(Debug, thiserror::Error)]
7pub enum Error {
8    /// A `redis-server` process failed to start.
9    #[error("redis-server failed to start on port {port}")]
10    ServerStart {
11        /// The port on which the server failed to start.
12        port: u16,
13    },
14
15    /// A sentinel process failed to start.
16    #[error("sentinel failed to start on port {port}")]
17    SentinelStart {
18        /// The port on which the sentinel failed to start.
19        port: u16,
20    },
21
22    /// `redis-cli --cluster create` failed.
23    #[error("cluster create failed:\nstdout: {stdout}\nstderr: {stderr}")]
24    ClusterCreate {
25        /// Captured stdout from the failed `redis-cli --cluster create` invocation.
26        stdout: String,
27        /// Captured stderr from the failed `redis-cli --cluster create` invocation.
28        stderr: String,
29    },
30
31    /// A `redis-cli` command failed.
32    #[error("redis-cli {host}:{port} failed: {detail}")]
33    Cli {
34        /// The host that was targeted.
35        host: String,
36        /// The port that was targeted.
37        port: u16,
38        /// Stderr output or other detail from the failed invocation.
39        detail: String,
40    },
41
42    /// A wait-for-ready or wait-for-healthy call timed out.
43    #[error("{message}")]
44    Timeout {
45        /// Human-readable description of what timed out.
46        message: String,
47    },
48
49    /// No sentinel was reachable.
50    #[error("no reachable sentinel")]
51    NoReachableSentinel,
52
53    /// A required binary was not found on PATH.
54    #[error("{binary} not found on PATH")]
55    BinaryNotFound {
56        /// The binary name that could not be found.
57        binary: String,
58    },
59
60    /// An underlying I/O error.
61    #[error(transparent)]
62    Io(#[from] io::Error),
63}
64
65/// Convenience alias used throughout the crate.
66pub type Result<T> = std::result::Result<T, Error>;