1use std::path::PathBuf;
4
5#[derive(Debug, thiserror::Error)]
11#[non_exhaustive]
12pub enum Error {
13 #[error("reading config file {}", path.display())]
15 ReadConfig {
16 path: PathBuf,
17 #[source]
18 source: std::io::Error,
19 },
20 #[error("parsing config{}", match path { Some(p) => format!(" file {}", p.display()), None => String::new() })]
25 Toml {
26 path: Option<PathBuf>,
27 #[source]
28 source: toml::de::Error,
29 },
30 #[error("{key} {reason}")]
32 InvalidConfig { key: &'static str, reason: String },
33 #[error("route prefix {prefix:?} must start with '/'")]
35 InvalidPrefix { prefix: String },
36 #[error("route prefix {prefix:?} is not normalised; write it as {normal:?}")]
40 NonCanonicalPrefix { prefix: String, normal: String },
41 #[error("duplicate route prefix {prefix:?}")]
43 DuplicatePrefix { prefix: String },
44 #[error("route {route:?}: {reason}")]
46 InvalidUpstream {
47 route: String,
48 upstream: String,
49 reason: String,
50 #[source]
51 source: Option<http::uri::InvalidUri>,
52 },
53 #[error("route {route:?}: cooldown_secs {reason}")]
55 InvalidCooldown { route: String, reason: String },
56 #[error(
58 "route {route:?}: upstream {upstream} is shared with another route but has a \
59 different cooldown ({cooldown_secs}s vs {other_secs}s); routes to one upstream share one breaker"
60 )]
61 ConflictingCooldown {
62 route: String,
63 upstream: String,
64 cooldown_secs: u64,
65 other_secs: u64,
66 },
67 #[error("route {route:?}: health_path {path:?} must start with '/' and contain no '?' or '#'")]
69 InvalidHealthPath { route: String, path: String },
70 #[error(
72 "route {route:?}: upstream {upstream} is shared with another route but has a \
73 different {setting} ({value} vs {other}); routes to one upstream share one health check"
74 )]
75 ConflictingHealth {
76 route: String,
77 upstream: String,
78 setting: &'static str,
80 value: String,
81 other: String,
82 },
83 #[error("trusted_proxies entry {entry:?}: {reason}")]
85 InvalidCidr { entry: String, reason: String },
86 #[error("{reason}{}", upstream.as_ref().map(|u| format!(" (upstream {u})")).unwrap_or_default())]
89 InvalidBreakerConfig {
90 reason: String,
91 upstream: Option<String>,
92 },
93}
94
95const _: fn() = || {
96 fn assert<T: std::error::Error + Send + Sync + 'static>() {}
97 assert::<Error>();
98};