upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDanConwayDev <DanConwayDev@protonmail.com>2026-03-20 09:25:02 +0000
committerDanConwayDev <DanConwayDev@protonmail.com>2026-03-20 09:25:02 +0000
commitf3a6ae82ccee44dc3b66a66caafe1bb39e7a46a6 (patch)
treecfb5d888747d9909409045e071d8692f84104c3c
parent3daf61e74c8969c91333bc92c4914c8c6077592c (diff)
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.
-rw-r--r--src/lib/client.rs15
1 files changed, 7 insertions, 8 deletions
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(
1793 // When we have a repo coordinate, rely on repo relays and coordinate 1793 // When we have a repo coordinate, rely on repo relays and coordinate
1794 // hint relays instead of always merging in the default set. 1794 // hint relays instead of always merging in the default set.
1795 let mut relays = if trusted_maintainer_coordinate.is_none() { 1795 let mut relays = if trusted_maintainer_coordinate.is_none() {
1796 fallback_relays 1796 fallback_relays.clone()
1797 } else { 1797 } else {
1798 HashSet::new() 1798 HashSet::new()
1799 }; 1799 };
@@ -1807,8 +1807,11 @@ async fn create_relays_request(
1807 relays.insert(r.clone()); 1807 relays.insert(r.clone());
1808 } 1808 }
1809 } 1809 }
1810 // When bootstrapping with no repo context and no coordinate hints, 1810 // Fall back to fallback relays when the coordinate had no relay hints
1811 // we need at least the fallback relays to discover the user profile. 1811 // and nothing is cached yet (e.g. fresh clone with a bare npub URL).
1812 if relays.is_empty() {
1813 relays = fallback_relays;
1814 }
1812 relays 1815 relays
1813 }; 1816 };
1814 1817
@@ -1825,11 +1828,7 @@ async fn create_relays_request(
1825 a 1828 a
1826 } 1829 }
1827 }) 1830 })
1828 .unwrap() 1831 .map_or(0, |r| r.to_string().chars().count() + 2);
1829 .to_string()
1830 .chars()
1831 .count()
1832 + 2;
1833 1832
1834 Ok(FetchRequest { 1833 Ok(FetchRequest {
1835 selected_relay: None, 1834 selected_relay: None,