diff --git a/ant-bootstrap/src/contacts.rs b/ant-bootstrap/src/contacts.rs index 83262fbc1a..24d9ac9bcf 100644 --- a/ant-bootstrap/src/contacts.rs +++ b/ant-bootstrap/src/contacts.rs @@ -95,7 +95,6 @@ impl ContactsFetcher { self.endpoints ); let mut bootstrap_addresses = Vec::new(); - let mut last_error = None; let mut fetches = stream::iter(self.endpoints.clone()) .map(|endpoint| async move { @@ -131,37 +130,16 @@ impl ContactsFetcher { } Err(e) => { warn!("Failed to fetch bootstrap addrs from {}: {}", endpoint, e); - last_error = Some(e); } } } - if bootstrap_addresses.is_empty() { - last_error.map_or_else( - || { - warn!("No bootstrap addrs found from any endpoint and no errors reported"); - Err(Error::NoBootstrapAddressesFound( - "No valid peers found from any endpoint".to_string(), - )) - }, - |e| { - warn!( - "No bootstrap addrs found from any endpoint. Last error: {}", - e - ); - Err(Error::NoBootstrapAddressesFound(format!( - "No valid bootstrap addrs found from any endpoint: {e}", - ))) - }, - ) - } else { - info!( - "Successfully discovered {} total addresses. First few: {:?}", - bootstrap_addresses.len(), - bootstrap_addresses.iter().take(3).collect::>() - ); - Ok(bootstrap_addresses) - } + info!( + "Successfully discovered {} total addresses. First few: {:?}", + bootstrap_addresses.len(), + bootstrap_addresses.iter().take(3).collect::>() + ); + Ok(bootstrap_addresses) } /// Fetch the list of multiaddrs from a single endpoint @@ -244,20 +222,13 @@ impl ContactsFetcher { }) .collect::>(); - if bootstrap_addresses.is_empty() { - warn!("No valid peers found in JSON response"); - Err(Error::NoBootstrapAddressesFound( - "No valid peers found in JSON response".to_string(), - )) - } else { - info!( - "Successfully parsed {} valid peers from JSON", - bootstrap_addresses.len() - ); - Ok(bootstrap_addresses) - } + info!( + "Successfully parsed {} valid peers from JSON", + bootstrap_addresses.len() + ); + Ok(bootstrap_addresses) } - Err(e) => { + Err(_err) => { info!("Attempting to parse response as plain text"); // Try parsing as plain text with one multiaddr per line // example of contacts file exists in resources/network-contacts-examples @@ -266,20 +237,11 @@ impl ContactsFetcher { .filter_map(|str| craft_valid_multiaddr_from_str(str, ignore_peer_id)) .collect::>(); - if bootstrap_addresses.is_empty() { - warn!( - "No valid bootstrap addrs found in plain text response. Previous Json error: {e:?}" - ); - Err(Error::NoBootstrapAddressesFound( - "No valid bootstrap addrs found in plain text response".to_string(), - )) - } else { - info!( - "Successfully parsed {} valid bootstrap addrs from plain text", - bootstrap_addresses.len() - ); - Ok(bootstrap_addresses) - } + info!( + "Successfully parsed {} valid bootstrap addrs from plain text", + bootstrap_addresses.len() + ); + Ok(bootstrap_addresses) } } } @@ -387,24 +349,6 @@ mod tests { assert_eq!(addrs[0].addr, valid_addr); } - #[tokio::test] - async fn test_empty_response() { - let mock_server = MockServer::start().await; - - Mock::given(method("GET")) - .and(path("/")) - .respond_with(ResponseTemplate::new(200).set_body_string("")) - .mount(&mock_server) - .await; - - let mut fetcher = ContactsFetcher::new().unwrap(); - fetcher.endpoints = vec![mock_server.uri().parse().unwrap()]; - - let result = fetcher.fetch_bootstrap_addresses().await; - - assert!(matches!(result, Err(Error::NoBootstrapAddressesFound(_)))); - } - #[tokio::test] async fn test_whitespace_and_empty_lines() { let mock_server = MockServer::start().await; diff --git a/ant-bootstrap/src/error.rs b/ant-bootstrap/src/error.rs index bc735b753a..a2eedfeee5 100644 --- a/ant-bootstrap/src/error.rs +++ b/ant-bootstrap/src/error.rs @@ -20,8 +20,6 @@ pub enum Error { InvalidBootstrapCacheDir, #[error("Could not obtain bootstrap addresses from {0} after {1} retries")] FailedToObtainAddrsFromUrl(String, usize), - #[error("No Bootstrap Addresses found: {0}")] - NoBootstrapAddressesFound(String), #[error("Failed to parse Url")] FailedToParseUrl, #[error("IO error: {0}")]