diff --git a/explorer-api/src/geo_ip/location.rs b/explorer-api/src/geo_ip/location.rs index 272200f6d2..d1c15dac9d 100644 --- a/explorer-api/src/geo_ip/location.rs +++ b/explorer-api/src/geo_ip/location.rs @@ -107,18 +107,24 @@ impl GeoIp { Ok(ip) } else { debug!("Fail to resolve IP address from {}:{}", &address, p); - let mut failed_ips_guard = self.failed_addresses.failed_ips.lock().unwrap(); - if failed_ips_guard.insert(address.to_string()) { - append_ip_to_file(address); + if let Ok(mut failed_ips_guard) = self.failed_addresses.failed_ips.lock() { + if failed_ips_guard.insert(address.to_string()) { + append_ip_to_file(address); + } + } else { + error!("Failed to acquire lock on failed_ips"); } Err(GeoIpError::NoValidIP) } } Err(_) => { debug!("Fail to resolve IP address from {}:{}.", &address, p); - let mut failed_ips_guard = self.failed_addresses.failed_ips.lock().unwrap(); - if failed_ips_guard.insert(address.to_string()) { - append_ip_to_file(address); + if let Ok(mut failed_ips_guard) = self.failed_addresses.failed_ips.lock() { + if failed_ips_guard.insert(address.to_string()) { + append_ip_to_file(address); + } + } else { + error!("Failed to acquire lock on failed_ips"); } Err(GeoIpError::NoValidIP) } diff --git a/explorer-api/src/helpers.rs b/explorer-api/src/helpers.rs index dbe4a219e7..2f65fc3dba 100644 --- a/explorer-api/src/helpers.rs +++ b/explorer-api/src/helpers.rs @@ -18,11 +18,18 @@ pub fn failed_ips_filepath() -> String { } pub fn append_ip_to_file(address: &str) { - if let Ok(mut file) = OpenOptions::new() + match OpenOptions::new() .append(true) .create(true) .open(failed_ips_filepath()) { - writeln!(file, "{}", address).expect("Failed to write to file"); + Ok(mut file) => { + if let Err(e) = writeln!(file, "{}", address) { + error!("Failed to write to file: {}", e); + } + } + Err(e) => { + error!("Failed to open or create the file: {}", e); + } } }