From f82345336c1edad86420b3b61ebb8578eb495a3e Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Sat, 23 May 2020 22:30:43 -0400 Subject: give a more useful error if rbw is misconfigured --- src/bin/rbw/commands.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'src/bin/rbw/commands.rs') diff --git a/src/bin/rbw/commands.rs b/src/bin/rbw/commands.rs index b3caa18..99522d1 100644 --- a/src/bin/rbw/commands.rs +++ b/src/bin/rbw/commands.rs @@ -1,5 +1,15 @@ use anyhow::Context as _; +const MISSING_CONFIG_HELP: &str = + "Before using rbw, you must configure the email address you would like to \ + use to log in to the server by running:\n\n \ + rbw config set email \n\n\ + Additionally, if you are using a self-hosted installation, you should \ + run:\n\n \ + rbw config set base_url \n\n\ + and, if your server has a non-default identity url:\n\n \ + rbw config set identity_url \n"; + #[derive(Debug, Clone)] #[cfg_attr(test, derive(Eq, PartialEq))] struct DecryptedCipher { @@ -795,6 +805,8 @@ pub fn stop_agent() -> anyhow::Result<()> { } fn ensure_agent() -> anyhow::Result<()> { + check_config()?; + ensure_agent_once()?; let client_version = rbw::protocol::version(); let agent_version = version_or_quit()?; @@ -842,6 +854,13 @@ fn ensure_agent_once() -> anyhow::Result<()> { Ok(()) } +fn check_config() -> anyhow::Result<()> { + rbw::config::Config::validate().map_err(|e| { + log::error!("{}", MISSING_CONFIG_HELP); + anyhow::Error::new(e) + }) +} + fn version_or_quit() -> anyhow::Result { crate::actions::version().or_else(|e| { let _ = crate::actions::quit(); -- cgit v1.2.3-54-g00ecf