diff options
-rw-r--r-- | src/bin/rbw/commands.rs | 9 | ||||
-rw-r--r-- | src/config.rs | 12 |
2 files changed, 17 insertions, 4 deletions
diff --git a/src/bin/rbw/commands.rs b/src/bin/rbw/commands.rs index 6d90010..b3caa18 100644 --- a/src/bin/rbw/commands.rs +++ b/src/bin/rbw/commands.rs @@ -317,9 +317,14 @@ pub fn config_set(key: &str, value: &str) -> anyhow::Result<()> { "base_url" => config.base_url = Some(value.to_string()), "identity_url" => config.identity_url = Some(value.to_string()), "lock_timeout" => { - config.lock_timeout = value + let timeout = value .parse() - .context("failed to parse value for lock_timeout")? + .context("failed to parse value for lock_timeout")?; + if timeout == 0 { + log::error!("lock_timeout must be greater than 0"); + } else { + config.lock_timeout = timeout; + } } _ => return Err(anyhow::anyhow!("invalid config key: {}", key)), } diff --git a/src/config.rs b/src/config.rs index caa27a6..39044c0 100644 --- a/src/config.rs +++ b/src/config.rs @@ -27,8 +27,12 @@ impl Config { let mut json = String::new(); fh.read_to_string(&mut json) .context(crate::error::LoadConfig)?; - let slf: Self = serde_json::from_str(&json) + let mut slf: Self = serde_json::from_str(&json) .context(crate::error::LoadConfigJson)?; + if slf.lock_timeout == 0 { + log::warn!("lock_timeout must be greater than 0"); + slf.lock_timeout = default_lock_timeout(); + } Ok(slf) } @@ -40,8 +44,12 @@ impl Config { fh.read_to_string(&mut json) .await .context(crate::error::LoadConfigAsync)?; - let slf: Self = serde_json::from_str(&json) + let mut slf: Self = serde_json::from_str(&json) .context(crate::error::LoadConfigJson)?; + if slf.lock_timeout == 0 { + log::warn!("lock_timeout must be greater than 0"); + slf.lock_timeout = default_lock_timeout(); + } Ok(slf) } |