From a60afc8350b1ae538cf87450fab20b1813e5af2f Mon Sep 17 00:00:00 2001 From: cloudhead Date: Mon, 22 Jan 2024 11:27:21 +0100 Subject: [PATCH] cli: Improve sync errors In the case where we don't find any seeds, display a better error message. We also don't bail out on error, since the announcement step might still be worth trying. --- radicle-cli/examples/rad-sync.md | 13 +++++++++++++ radicle-cli/src/commands/sync.rs | 12 +++++++++--- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/radicle-cli/examples/rad-sync.md b/radicle-cli/examples/rad-sync.md index e4293a4d..67b01deb 100644 --- a/radicle-cli/examples/rad-sync.md +++ b/radicle-cli/examples/rad-sync.md @@ -96,3 +96,16 @@ with 1 node(s)`. This does not necessarily mean that only `bob` or `eve` were synchronized with, since they both could have received the announcement of the new changes. However, it does mean that we only wait for at least 1 of the nodes to have fetched the changes from us. + + +It's also possible to receive an error if a repository is not found anywhere. + +``` +$ rad seed rad:z39mP9rQAaGmERfUMPULfPUi473tY +✓ Seeding policy updated for rad:z39mP9rQAaGmERfUMPULfPUi473tY with scope 'all' +``` +``` (fail) +$ rad sync rad:z39mP9rQAaGmERfUMPULfPUi473tY +✗ Error: no seeds found for rad:z39mP9rQAaGmERfUMPULfPUi473tY +✗ Error: nothing to announce, repository rad:z39mP9rQAaGmERfUMPULfPUi473tY is not available locally +``` diff --git a/radicle-cli/src/commands/sync.rs b/radicle-cli/src/commands/sync.rs index d49d8f81..b7a5bad9 100644 --- a/radicle-cli/src/commands/sync.rs +++ b/radicle-cli/src/commands/sync.rs @@ -288,8 +288,10 @@ pub fn run(options: Options, ctx: impl term::Context) -> anyhow::Result<()> { let success = results.success().count(); let failed = results.failed().count(); - if success == 0 { - anyhow::bail!("repository fetch from {failed} seed(s) failed"); + if results.is_empty() { + term::error(format!("no seeds found for {rid}")); + } else if success == 0 { + term::error(format!("repository fetch from {failed} seed(s) failed")); } else { term::success!("Fetched repository from {success} seed(s)"); } @@ -381,7 +383,11 @@ fn announce_refs( mut node: Node, profile: &Profile, ) -> anyhow::Result<()> { - let repo = profile.storage.repository(rid)?; + let Ok(repo) = profile.storage.repository(rid) else { + return Err(anyhow!( + "nothing to announce, repository {rid} is not available locally" + )); + }; let doc = repo.identity_doc()?; let unsynced: Vec<_> = if doc.visibility.is_public() { let seeds = node.seeds(rid)?;