mirror of
https://seed.radicle.dev/rad:zwTxygwuz5LDGBq255RA2CbNGrz8.git
synced 2026-11-29 06:40:31 +08:00
refactor: Config::default_adapter returns an error if no default set
Signed-off-by: Lars Wirzenius <liw@liw.fi>
This commit is contained in:
+4
-12
@@ -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),
|
||||
|
||||
+6
-1
@@ -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)]
|
||||
|
||||
Reference in New Issue
Block a user