Skip to main content

signet_storage/
config.rs

1//! Storage configuration types and environment parsing.
2//!
3//! This module provides environment variable constants and error types
4//! for storage configuration.
5//!
6//! # Environment Variables
7//!
8//! | Variable | Description | Required When |
9//! |----------|-------------|---------------|
10//! | `SIGNET_HOT_PATH` | Path to hot MDBX database | Always |
11//! | `SIGNET_COLD_PATH` | Path to cold MDBX database | Cold backend is MDBX |
12//! | `SIGNET_COLD_SQL_URL` | SQL connection string | Cold backend is SQL |
13//!
14//! Exactly one of `SIGNET_COLD_PATH` or `SIGNET_COLD_SQL_URL` must be set.
15
16use signet_cold_mdbx::MdbxConnectorError;
17use thiserror::Error;
18
19#[cfg(any(feature = "postgres", feature = "sqlite"))]
20use signet_cold_sql::SqlConnectorError;
21
22/// Environment variable name for hot storage path.
23pub const ENV_HOT_PATH: &str = "SIGNET_HOT_PATH";
24
25/// Environment variable name for cold MDBX storage path.
26pub const ENV_COLD_PATH: &str = "SIGNET_COLD_PATH";
27
28/// Environment variable name for cold SQL connection URL.
29pub const ENV_COLD_SQL_URL: &str = "SIGNET_COLD_SQL_URL";
30
31/// Configuration errors.
32#[derive(Debug, Error)]
33pub enum ConfigError {
34    /// Required environment variable is missing.
35    #[error("missing environment variable: {0}")]
36    MissingEnvVar(&'static str),
37
38    /// Cold backend not specified.
39    #[error("no cold backend specified: set either {ENV_COLD_PATH} or {ENV_COLD_SQL_URL}")]
40    MissingColdBackend,
41
42    /// Multiple cold backends specified.
43    #[error("ambiguous cold backend: both {ENV_COLD_PATH} and {ENV_COLD_SQL_URL} are set")]
44    AmbiguousColdBackend,
45
46    /// Required feature not enabled.
47    #[error("feature '{feature}' required for {env_var} but not enabled")]
48    FeatureNotEnabled {
49        /// The feature name that is required.
50        feature: &'static str,
51        /// The environment variable that requires the feature.
52        env_var: &'static str,
53    },
54
55    /// MDBX connector error.
56    #[error("MDBX connector error: {0}")]
57    MdbxConnector(#[from] MdbxConnectorError),
58
59    /// SQL connector error.
60    #[cfg(any(feature = "postgres", feature = "sqlite"))]
61    #[error("SQL connector error: {0}")]
62    SqlConnector(#[from] SqlConnectorError),
63}