From 8dca57df82493a706a5d5677ae4c815bdd3b8aab Mon Sep 17 00:00:00 2001 From: Joe Shaw Date: Tue, 12 Mar 2024 13:47:18 -0400 Subject: [PATCH 1/2] Error::NotAvailable should yield FastlyStatus::Unsupported --- lib/src/error.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/src/error.rs b/lib/src/error.rs index a7ed0f62..6cc882a6 100644 --- a/lib/src/error.rs +++ b/lib/src/error.rs @@ -159,7 +159,7 @@ impl Error { Error::BufferLengthError { .. } => FastlyStatus::Buflen, Error::InvalidArgument => FastlyStatus::Inval, Error::ValueAbsent => FastlyStatus::None, - Error::Unsupported { .. } => FastlyStatus::Unsupported, + Error::Unsupported { .. } | Error::NotAvailable(_) => FastlyStatus::Unsupported, Error::HandleError { .. } => FastlyStatus::Badf, Error::InvalidStatusCode { .. } => FastlyStatus::Inval, Error::UnknownBackend(_) | Error::InvalidClientCert(_) => FastlyStatus::Inval, @@ -199,7 +199,6 @@ impl Error { | Error::InvalidMethod(_) | Error::InvalidUri(_) | Error::IoError(_) - | Error::NotAvailable(_) | Error::Other(_) | Error::ProfilingStrategy | Error::StreamingChunkSend From 491b54c4d8c46c9129e4a6889e5da5ec7e6e4c6b Mon Sep 17 00:00:00 2001 From: Joe Shaw Date: Tue, 12 Mar 2024 13:53:08 -0400 Subject: [PATCH 2/2] switch most uses of Error::Unsupported to Error::NotAvailable `Unsupported` is meant to express things that are not supported by the platform, for example trying to make a request with "HTTP/4". `NotAvailable` is meant to express things that are not available or unimplemented in Viceroy. Previously, `Unsupported` would return `FastlyStatus::Unsupported` and `NotAvailable` would return the generic `FastlyStatus::Error`. This led to a bad user experience for the `NotAvailable` case, as the user would see an opaque and generic "Error" message rather than "Unsupported". The previous commit fixes this by having both `Unsupported` and `NotAvailable` return `FastlyStatus::Unsupported`. This commit makes our use of `NotAvailable` consistent. --- lib/src/wiggle_abi/backend_impl.rs | 20 +++------- lib/src/wiggle_abi/cache.rs | 64 ++++++++---------------------- 2 files changed, 21 insertions(+), 63 deletions(-) diff --git a/lib/src/wiggle_abi/backend_impl.rs b/lib/src/wiggle_abi/backend_impl.rs index 4176c8e8..8a2c2657 100644 --- a/lib/src/wiggle_abi/backend_impl.rs +++ b/lib/src/wiggle_abi/backend_impl.rs @@ -143,9 +143,7 @@ impl FastlyBackend for Session { // just doing this to get a different error if the backend doesn't exist let _ = lookup_backend_definition(self, backend)?; // health checks are not enabled in Viceroy :( - Err(Error::Unsupported { - msg: "connection timing is not actually supported in Viceroy", - }) + Err(Error::NotAvailable("Connection timing")) } fn get_first_byte_timeout_ms( @@ -155,9 +153,7 @@ impl FastlyBackend for Session { // just doing this to get a different error if the backend doesn't exist let _ = lookup_backend_definition(self, backend)?; // health checks are not enabled in Viceroy :( - Err(Error::Unsupported { - msg: "connection timing is not actually supported in Viceroy", - }) + Err(Error::NotAvailable("Connection timing")) } fn get_between_bytes_timeout_ms( @@ -167,9 +163,7 @@ impl FastlyBackend for Session { // just doing this to get a different error if the backend doesn't exist let _ = lookup_backend_definition(self, backend)?; // health checks are not enabled in Viceroy :( - Err(Error::Unsupported { - msg: "connection timing is not actually supported in Viceroy", - }) + Err(Error::NotAvailable("Connection timing")) } fn get_ssl_min_version( @@ -179,9 +173,7 @@ impl FastlyBackend for Session { // just doing this to get a different error if the backend doesn't exist let _ = lookup_backend_definition(self, backend)?; // health checks are not enabled in Viceroy :( - Err(Error::Unsupported { - msg: "ssl version flags are not supported in Viceroy", - }) + Err(Error::NotAvailable("SSL version information")) } fn get_ssl_max_version( @@ -191,9 +183,7 @@ impl FastlyBackend for Session { // just doing this to get a different error if the backend doesn't exist let _ = lookup_backend_definition(self, backend)?; // health checks are not enabled in Viceroy :( - Err(Error::Unsupported { - msg: "ssl version flags are not supported in Viceroy", - }) + Err(Error::NotAvailable("SSL version information")) } fn is_ssl(&mut self, backend: &wiggle::GuestPtr) -> Result { diff --git a/lib/src/wiggle_abi/cache.rs b/lib/src/wiggle_abi/cache.rs index f2972c13..74161c89 100644 --- a/lib/src/wiggle_abi/cache.rs +++ b/lib/src/wiggle_abi/cache.rs @@ -11,9 +11,7 @@ impl FastlyCache for Session { options_mask: types::CacheLookupOptionsMask, options: &wiggle::GuestPtr<'a, types::CacheLookupOptions>, ) -> Result { - Err(Error::Unsupported { - msg: "Cache API primitives not yet supported", - }) + Err(Error::NotAvailable("Cache API primitives")) } fn insert<'a>( @@ -22,9 +20,7 @@ impl FastlyCache for Session { options_mask: types::CacheWriteOptionsMask, options: &wiggle::GuestPtr<'a, types::CacheWriteOptions<'a>>, ) -> Result { - Err(Error::Unsupported { - msg: "Cache API primitives not yet supported", - }) + Err(Error::NotAvailable("Cache API primitives")) } fn transaction_lookup<'a>( @@ -33,9 +29,7 @@ impl FastlyCache for Session { options_mask: types::CacheLookupOptionsMask, options: &wiggle::GuestPtr<'a, types::CacheLookupOptions>, ) -> Result { - Err(Error::Unsupported { - msg: "Cache API primitives not yet supported", - }) + Err(Error::NotAvailable("Cache API primitives")) } fn transaction_insert<'a>( @@ -44,9 +38,7 @@ impl FastlyCache for Session { options_mask: types::CacheWriteOptionsMask, options: &wiggle::GuestPtr<'a, types::CacheWriteOptions<'a>>, ) -> Result { - Err(Error::Unsupported { - msg: "Cache API primitives not yet supported", - }) + Err(Error::NotAvailable("Cache API primitives")) } fn transaction_insert_and_stream_back<'a>( @@ -55,9 +47,7 @@ impl FastlyCache for Session { options_mask: types::CacheWriteOptionsMask, options: &wiggle::GuestPtr<'a, types::CacheWriteOptions<'a>>, ) -> Result<(types::BodyHandle, types::CacheHandle), Error> { - Err(Error::Unsupported { - msg: "Cache API primitives not yet supported", - }) + Err(Error::NotAvailable("Cache API primitives")) } fn transaction_update<'a>( @@ -66,27 +56,19 @@ impl FastlyCache for Session { options_mask: types::CacheWriteOptionsMask, options: &wiggle::GuestPtr<'a, types::CacheWriteOptions<'a>>, ) -> Result<(), Error> { - Err(Error::Unsupported { - msg: "Cache API primitives not yet supported", - }) + Err(Error::NotAvailable("Cache API primitives")) } fn transaction_cancel(&mut self, handle: types::CacheHandle) -> Result<(), Error> { - Err(Error::Unsupported { - msg: "Cache API primitives not yet supported", - }) + Err(Error::NotAvailable("Cache API primitives")) } fn close(&mut self, handle: types::CacheHandle) -> Result<(), Error> { - Err(Error::Unsupported { - msg: "Cache API primitives not yet supported", - }) + Err(Error::NotAvailable("Cache API primitives")) } fn get_state(&mut self, handle: types::CacheHandle) -> Result { - Err(Error::Unsupported { - msg: "Cache API primitives not yet supported", - }) + Err(Error::NotAvailable("Cache API primitives")) } fn get_user_metadata<'a>( @@ -96,9 +78,7 @@ impl FastlyCache for Session { user_metadata_out_len: u32, nwritten_out: &wiggle::GuestPtr<'a, u32>, ) -> Result<(), Error> { - Err(Error::Unsupported { - msg: "Cache API primitives not yet supported", - }) + Err(Error::NotAvailable("Cache API primitives")) } fn get_body( @@ -107,47 +87,35 @@ impl FastlyCache for Session { options_mask: types::CacheGetBodyOptionsMask, options: &types::CacheGetBodyOptions, ) -> Result { - Err(Error::Unsupported { - msg: "Cache API primitives not yet supported", - }) + Err(Error::NotAvailable("Cache API primitives")) } fn get_length( &mut self, handle: types::CacheHandle, ) -> Result { - Err(Error::Unsupported { - msg: "Cache API primitives not yet supported", - }) + Err(Error::NotAvailable("Cache API primitives")) } fn get_max_age_ns( &mut self, handle: types::CacheHandle, ) -> Result { - Err(Error::Unsupported { - msg: "Cache API primitives not yet supported", - }) + Err(Error::NotAvailable("Cache API primitives")) } fn get_stale_while_revalidate_ns( &mut self, handle: types::CacheHandle, ) -> Result { - Err(Error::Unsupported { - msg: "Cache API primitives not yet supported", - }) + Err(Error::NotAvailable("Cache API primitives")) } fn get_age_ns(&mut self, handle: types::CacheHandle) -> Result { - Err(Error::Unsupported { - msg: "Cache API primitives not yet supported", - }) + Err(Error::NotAvailable("Cache API primitives")) } fn get_hits(&mut self, handle: types::CacheHandle) -> Result { - Err(Error::Unsupported { - msg: "Cache API primitives not yet supported", - }) + Err(Error::NotAvailable("Cache API primitives")) } }