Skip to main content

slave_framework/
error.rs

1use std::io;
2
3/// Errors raised by the slave runtime.
4#[derive(Debug, thiserror::Error)]
5pub enum Error {
6    #[error("failed to load .env file: {0}")]
7    Dotenv(#[from] dotenvy::Error),
8
9    #[error("invalid value {value:?} for environment variable {key}: {reason}")]
10    InvalidEnv {
11        key: String,
12        value: String,
13        reason: String,
14    },
15
16    #[error("failed to initialize logging: {0}")]
17    Logging(String),
18
19    #[error("failed to bind to {addr}: {source}")]
20    Bind {
21        addr: String,
22        #[source]
23        source: io::Error,
24    },
25
26    #[error("server error: {0}")]
27    Server(#[source] io::Error),
28
29    /// A sign-in that cannot go ahead, worded for the user (e.g. a wrong
30    /// email address, or too many codes).
31    #[cfg(feature = "auth")]
32    #[error("{0}")]
33    Auth(String),
34
35    #[cfg(feature = "auth")]
36    #[error("sign-in setup: {0}")]
37    AuthSetup(String),
38
39    #[cfg(feature = "database")]
40    #[error("database error: {0}")]
41    Database(#[from] surrealdb::Error),
42
43    #[cfg(feature = "database")]
44    #[error("{0} is not set")]
45    MissingDatabaseSetting(&'static str),
46
47    #[cfg(feature = "database")]
48    #[error("migration failed: {0}")]
49    Migration(String),
50}
51
52/// Shorthand for results returned by the slave runtime.
53pub type Result<T, E = Error> = std::result::Result<T, E>;