Skip to main content

praxis_core/
errors.rs

1// SPDX-License-Identifier: Apache-2.0
2// Copyright (c) 2024 Praxis Contributors
3
4//! Shared error types for the Praxis workspace.
5//!
6//! [`ProxyError`] is the primary error type, re-exported from `praxis_core`.
7
8use thiserror::Error;
9
10// -----------------------------------------------------------------------------
11// Errors
12// -----------------------------------------------------------------------------
13
14/// Errors that can occur during proxy operation.
15///
16/// Runtime routing failures (no route matched, no healthy upstream) are
17/// not `ProxyError` variants: the router and load balancer short-circuit
18/// with filter rejections, and upstream connect failures surface through
19/// the protocol layer's error classification.
20///
21/// ```
22/// use praxis_core::ProxyError;
23///
24/// let e = ProxyError::Config("bad yaml".into());
25/// assert_eq!(e.to_string(), "config: bad yaml");
26/// ```
27#[derive(Debug, Error)]
28pub enum ProxyError {
29    /// Configuration loading or validation error.
30    ///
31    /// Raised during startup or hot-reload when YAML parsing or
32    /// validation fails. Not retriable; fix the configuration.
33    /// The server continues running with the previous config on
34    /// hot-reload failures.
35    #[error("config: {0}")]
36    Config(String),
37}
38
39// -----------------------------------------------------------------------------
40// Tests
41// -----------------------------------------------------------------------------
42
43#[cfg(test)]
44mod tests {
45    use super::*;
46
47    #[test]
48    fn error_display() {
49        let e = ProxyError::Config("bad yaml".into());
50        assert_eq!(e.to_string(), "config: bad yaml", "Config error display mismatch");
51    }
52}