Skip to content

Commit

Permalink
switch most uses of Error::Unsupported to Error::NotAvailable
Browse files Browse the repository at this point in the history
`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.
  • Loading branch information
joeshaw committed Mar 12, 2024
1 parent 8dca57d commit 491b54c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 63 deletions.
20 changes: 5 additions & 15 deletions lib/src/wiggle_abi/backend_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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(
Expand All @@ -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(
Expand All @@ -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(
Expand All @@ -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<str>) -> Result<super::types::IsSsl, Error> {
Expand Down
64 changes: 16 additions & 48 deletions lib/src/wiggle_abi/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ impl FastlyCache for Session {
options_mask: types::CacheLookupOptionsMask,
options: &wiggle::GuestPtr<'a, types::CacheLookupOptions>,
) -> Result<types::CacheHandle, Error> {
Err(Error::Unsupported {
msg: "Cache API primitives not yet supported",
})
Err(Error::NotAvailable("Cache API primitives"))
}

fn insert<'a>(
Expand All @@ -22,9 +20,7 @@ impl FastlyCache for Session {
options_mask: types::CacheWriteOptionsMask,
options: &wiggle::GuestPtr<'a, types::CacheWriteOptions<'a>>,
) -> Result<types::BodyHandle, Error> {
Err(Error::Unsupported {
msg: "Cache API primitives not yet supported",
})
Err(Error::NotAvailable("Cache API primitives"))
}

fn transaction_lookup<'a>(
Expand All @@ -33,9 +29,7 @@ impl FastlyCache for Session {
options_mask: types::CacheLookupOptionsMask,
options: &wiggle::GuestPtr<'a, types::CacheLookupOptions>,
) -> Result<types::CacheHandle, Error> {
Err(Error::Unsupported {
msg: "Cache API primitives not yet supported",
})
Err(Error::NotAvailable("Cache API primitives"))
}

fn transaction_insert<'a>(
Expand All @@ -44,9 +38,7 @@ impl FastlyCache for Session {
options_mask: types::CacheWriteOptionsMask,
options: &wiggle::GuestPtr<'a, types::CacheWriteOptions<'a>>,
) -> Result<types::BodyHandle, Error> {
Err(Error::Unsupported {
msg: "Cache API primitives not yet supported",
})
Err(Error::NotAvailable("Cache API primitives"))
}

fn transaction_insert_and_stream_back<'a>(
Expand All @@ -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>(
Expand All @@ -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<types::CacheLookupState, Error> {
Err(Error::Unsupported {
msg: "Cache API primitives not yet supported",
})
Err(Error::NotAvailable("Cache API primitives"))
}

fn get_user_metadata<'a>(
Expand All @@ -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(
Expand All @@ -107,47 +87,35 @@ impl FastlyCache for Session {
options_mask: types::CacheGetBodyOptionsMask,
options: &types::CacheGetBodyOptions,
) -> Result<types::BodyHandle, Error> {
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<types::CacheObjectLength, Error> {
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<types::CacheDurationNs, Error> {
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<types::CacheDurationNs, Error> {
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<types::CacheDurationNs, Error> {
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<types::CacheHitCount, Error> {
Err(Error::Unsupported {
msg: "Cache API primitives not yet supported",
})
Err(Error::NotAvailable("Cache API primitives"))
}
}

0 comments on commit 491b54c

Please sign in to comment.