From 0357704489b715dfa0a239160b1df3984dba826b Mon Sep 17 00:00:00 2001 From: Joe Shaw Date: Tue, 19 Dec 2023 16:42:58 -0500 Subject: [PATCH] return an empty result when geolocation data is not found This matches the Fastly Compute behavior. As a result, we don't need the `GeolocationError` type anymore and this commit also removes it. Fixes #339. --- lib/src/error.rs | 4 ---- lib/src/wiggle_abi.rs | 1 - lib/src/wiggle_abi/geo_impl.rs | 27 ++------------------------- 3 files changed, 2 insertions(+), 30 deletions(-) diff --git a/lib/src/error.rs b/lib/src/error.rs index ad9862d5..a7ed0f62 100644 --- a/lib/src/error.rs +++ b/lib/src/error.rs @@ -92,9 +92,6 @@ pub enum Error { #[error(transparent)] DeviceDetectionError(#[from] crate::wiggle_abi::DeviceDetectionError), - #[error(transparent)] - GeolocationError(#[from] crate::wiggle_abi::GeolocationError), - #[error(transparent)] ObjectStoreError(#[from] crate::object_store::ObjectStoreError), @@ -184,7 +181,6 @@ impl Error { // We delegate to some error types' own implementation of `to_fastly_status`. Error::DictionaryError(e) => e.to_fastly_status(), Error::DeviceDetectionError(e) => e.to_fastly_status(), - Error::GeolocationError(e) => e.to_fastly_status(), Error::ObjectStoreError(e) => e.into(), Error::SecretStoreError(e) => e.into(), Error::Again => FastlyStatus::Again, diff --git a/lib/src/wiggle_abi.rs b/lib/src/wiggle_abi.rs index 9c7fdc51..c42cd7cd 100644 --- a/lib/src/wiggle_abi.rs +++ b/lib/src/wiggle_abi.rs @@ -14,7 +14,6 @@ pub use self::dictionary_impl::DictionaryError; pub use self::secret_store_impl::SecretStoreError; pub use self::device_detection_impl::DeviceDetectionError; -pub use self::geo_impl::GeolocationError; use { self::{ diff --git a/lib/src/wiggle_abi/geo_impl.rs b/lib/src/wiggle_abi/geo_impl.rs index 0b2ca131..a02cca70 100644 --- a/lib/src/wiggle_abi/geo_impl.rs +++ b/lib/src/wiggle_abi/geo_impl.rs @@ -6,32 +6,11 @@ use std::{ }; use { - crate::{ - error::Error, - session::Session, - wiggle_abi::{fastly_geo::FastlyGeo, types::FastlyStatus}, - }, + crate::{error::Error, session::Session, wiggle_abi::fastly_geo::FastlyGeo}, std::convert::TryFrom, wiggle::GuestPtr, }; -#[derive(Debug, thiserror::Error)] -pub enum GeolocationError { - /// Geolocation data for given address not found. - #[error("No geolocation data: {0}")] - NoGeolocationData(String), -} - -impl GeolocationError { - /// Convert to an error code representation suitable for passing across the ABI boundary. - pub fn to_fastly_status(&self) -> FastlyStatus { - use GeolocationError::*; - match self { - NoGeolocationData(_) => FastlyStatus::None, - } - } -} - impl FastlyGeo for Session { fn lookup( &mut self, @@ -57,9 +36,7 @@ impl FastlyGeo for Session { _ => return Err(Error::InvalidArgument), }; - let result = self - .geolocation_lookup(&ip_addr) - .ok_or_else(|| GeolocationError::NoGeolocationData(ip_addr.to_string()))?; + let result = self.geolocation_lookup(&ip_addr).unwrap_or_default(); if result.len() > buf_len as usize { return Err(Error::BufferLengthError {