From 5040f33025d6ba7a68dca5f9e1eb8053888b623b Mon Sep 17 00:00:00 2001 From: Alexis Sellier Date: Sat, 2 Sep 2023 13:11:01 +0200 Subject: [PATCH] cli: Be less confusing when asking for passphrase The previous error didn't really make sense. --- radicle-cli/src/commands/auth.rs | 6 +++--- radicle-cli/src/commands/node/control.rs | 9 ++++----- radicle-term/src/io.rs | 2 +- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/radicle-cli/src/commands/auth.rs b/radicle-cli/src/commands/auth.rs index 0fb9e0df..ed289a90 100644 --- a/radicle-cli/src/commands/auth.rs +++ b/radicle-cli/src/commands/auth.rs @@ -178,10 +178,10 @@ pub fn authenticate(options: Options, profile: &Profile) -> anyhow::Result<()> { ); let passphrase = if options.stdin { - term::passphrase_stdin() + term::passphrase_stdin()? } else { - term::passphrase(RAD_PASSPHRASE) - }?; + term::passphrase(RAD_PASSPHRASE)? + }; register(&mut agent, profile, passphrase)?; term::success!("Radicle key added to {}", term::format::dim("ssh-agent")); diff --git a/radicle-cli/src/commands/node/control.rs b/radicle-cli/src/commands/node/control.rs index e8bd45b4..e4183f5c 100644 --- a/radicle-cli/src/commands/node/control.rs +++ b/radicle-cli/src/commands/node/control.rs @@ -3,7 +3,6 @@ use std::fs::{File, OpenOptions}; use std::io::{BufRead, BufReader, Read, Seek, SeekFrom}; use std::{process, thread, time}; -use anyhow::Context as _; use localtime::LocalTime; use radicle::node; @@ -30,10 +29,10 @@ pub fn start( } let envs = if profile.keystore.is_encrypted()? { // Ask passphrase here, otherwise it'll be a fatal error when running the daemon - // without `RAD_PASSPHRASE`. To keep things consistent, we also use this in foreground mode. - let passphrase = term::io::passphrase(profile::env::RAD_PASSPHRASE) - .context(format!("`{}` must be set", profile::env::RAD_PASSPHRASE))?; - + // without `RAD_PASSPHRASE`. + let Ok(passphrase) = term::io::passphrase(profile::env::RAD_PASSPHRASE) else { + anyhow::bail!("your radicle passphrase is required to start your node"); + }; Some((profile::env::RAD_PASSPHRASE, passphrase)) } else { None diff --git a/radicle-term/src/io.rs b/radicle-term/src/io.rs index 68ebd5d5..5c450656 100644 --- a/radicle-term/src/io.rs +++ b/radicle-term/src/io.rs @@ -199,7 +199,7 @@ where Ok(value) } -pub fn passphrase>(var: K) -> Result { +pub fn passphrase>(var: K) -> Result { if let Ok(p) = env::var(var) { Ok(Passphrase::from(p)) } else {