diff --git a/src/bin/cib.rs b/src/bin/cib.rs index cc9be791..78ca13ec 100644 --- a/src/bin/cib.rs +++ b/src/bin/cib.rs @@ -175,11 +175,7 @@ impl QueuedCmd { let mut broker = Broker::new(config.db(), config.max_run_time()).map_err(CibError::new_broker)?; - let spec = config - .default_adapter() - .ok_or(CibError::UnknownDefaultAdapter( - config.default_adapter_name().into(), - ))?; + let spec = config.default_adapter()?; let adapter = Adapter::new(&spec.command) .with_environment(spec.envs()) .with_sensitive_environment(spec.sensitive_envs()); @@ -270,11 +266,7 @@ impl ProcessEventsCmd { let mut broker = Broker::new(config.db(), config.max_run_time()).map_err(CibError::new_broker)?; - let spec = config - .default_adapter() - .ok_or(CibError::UnknownDefaultAdapter( - config.default_adapter_name().into(), - ))?; + let spec = config.default_adapter().map_err(CibError::DefaultAdapter)?; let adapter = Adapter::new(&spec.command) .with_environment(spec.envs()) .with_sensitive_environment(spec.sensitive_envs()); @@ -338,8 +330,8 @@ enum CibError { #[error("failed to add events to queue")] AddEvents(#[source] AdderError), - #[error("default adapter is not in list of adapters")] - UnknownDefaultAdapter(String), + #[error(transparent)] + DefaultAdapter(#[from] ConfigError), #[error("programming error: failed to set up inter-thread notification channel")] Notification(#[source] NotificationError), diff --git a/src/config.rs b/src/config.rs index e20b179d..83e064b2 100644 --- a/src/config.rs +++ b/src/config.rs @@ -60,8 +60,9 @@ impl Config { &self.default_adapter } - pub fn default_adapter(&self) -> Option<&Adapter> { + pub fn default_adapter(&self) -> Result<&Adapter, ConfigError> { self.adapter(&self.default_adapter) + .ok_or(ConfigError::NoDefaultAdapter) } pub fn adapter(&self, name: &str) -> Option<&Adapter> { @@ -137,6 +138,10 @@ pub enum ConfigError { /// Can't convert configuration into JSON. #[error("failed to convert configuration into JSON")] ToJson(#[source] serde_json::Error), + + /// No default adapter. + #[error("the default adapter is not defined in the configuration")] + NoDefaultAdapter, } #[cfg(test)]