From f3a6ae82ccee44dc3b66a66caafe1bb39e7a46a6 Mon Sep 17 00:00:00 2001 From: DanConwayDev Date: Fri, 20 Mar 2026 09:25:02 +0000 Subject: fix(client): panic cloning bare npub nostr:// URL with no relay hints When cloning a nostr:// URL containing only an npub and identifier (no relay hints), and nothing is cached yet, the relay set was empty because fallback relays were intentionally skipped when a coordinate was present. This caused an unwrap() on a None from reduce() over an empty iterator. Fall back to fallback relays when the coordinate-derived relay set is still empty after processing all hints, and replace unwrap() with map_or() as a defensive guard. --- src/lib/client.rs | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/lib/client.rs b/src/lib/client.rs index d5597fa..01662cd 100644 --- a/src/lib/client.rs +++ b/src/lib/client.rs @@ -1793,7 +1793,7 @@ async fn create_relays_request( // When we have a repo coordinate, rely on repo relays and coordinate // hint relays instead of always merging in the default set. let mut relays = if trusted_maintainer_coordinate.is_none() { - fallback_relays + fallback_relays.clone() } else { HashSet::new() }; @@ -1807,8 +1807,11 @@ async fn create_relays_request( relays.insert(r.clone()); } } - // When bootstrapping with no repo context and no coordinate hints, - // we need at least the fallback relays to discover the user profile. + // Fall back to fallback relays when the coordinate had no relay hints + // and nothing is cached yet (e.g. fresh clone with a bare npub URL). + if relays.is_empty() { + relays = fallback_relays; + } relays }; @@ -1825,11 +1828,7 @@ async fn create_relays_request( a } }) - .unwrap() - .to_string() - .chars() - .count() - + 2; + .map_or(0, |r| r.to_string().chars().count() + 2); Ok(FetchRequest { selected_relay: None, -- cgit v1.2.3