From a101cdd4ef02cf6a246b874acebd4eca10cf40d4 Mon Sep 17 00:00:00 2001 From: Vladislav Mamon Date: Wed, 20 Mar 2024 16:55:53 +0300 Subject: [PATCH] fix: short-circuit when no relays loaded/fetched --- src/app.rs | 9 +++++++-- src/cli.rs | 7 +++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/app.rs b/src/app.rs index f5e1c7e..802aa3d 100644 --- a/src/app.rs +++ b/src/app.rs @@ -25,7 +25,7 @@ pub async fn run() -> anyhow::Result<()> { | None => Coord::fetch().await?, }; - thread::sleep(std::time::Duration::from_secs(1)); + thread::sleep(Duration::from_secs(1)); // ----------------------------------------------------------------------------------------------- // 2. Load relays from file and filter them. @@ -43,7 +43,12 @@ pub async fn run() -> anyhow::Result<()> { let relays = loader.load()?; - thread::sleep(std::time::Duration::from_secs(1)); + thread::sleep(Duration::from_secs(1)); + + if relays.is_empty() { + spinner.stop(); + anyhow::bail!("Couldn't find any relays"); + } // ----------------------------------------------------------------------------------------------- // 3. Ping relays. diff --git a/src/cli.rs b/src/cli.rs index bfee026..d3f2ec9 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -101,8 +101,11 @@ impl Spinner { } /// Sets the message of the spinner. - pub fn set_message(&self, message: &'static str) { - self.spinner.set_message(message); + pub fn set_message(&self, message: S) + where + S: Into + AsRef, + { + self.spinner.set_message(message.into()); } /// Stops the spinner and clears the message.