Skip to content

Commit

Permalink
Remove the trappable_error_type
Browse files Browse the repository at this point in the history
  • Loading branch information
elliottt committed May 20, 2024
1 parent 67b9e8b commit 48312d2
Show file tree
Hide file tree
Showing 17 changed files with 242 additions and 323 deletions.
5 changes: 2 additions & 3 deletions lib/src/component/async_io.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use {
super::fastly::api::{async_io, types},
super::FastlyError,
crate::{session::Session, wiggle_abi},
futures::FutureExt,
std::time::Duration,
Expand All @@ -12,7 +11,7 @@ impl async_io::Host for Session {
&mut self,
hs: Vec<async_io::Handle>,
timeout_ms: u32,
) -> Result<Option<u32>, FastlyError> {
) -> Result<Option<u32>, types::Error> {
if hs.is_empty() && timeout_ms == 0 {
return Err(types::Error::InvalidArgument.into());
}
Expand Down Expand Up @@ -42,7 +41,7 @@ impl async_io::Host for Session {
}
}

async fn is_ready(&mut self, handle: async_io::Handle) -> Result<bool, FastlyError> {
async fn is_ready(&mut self, handle: async_io::Handle) -> Result<bool, types::Error> {
let handle = wiggle_abi::types::AsyncItemHandle::from(handle);
Ok(self
.async_item_mut(handle.into())?
Expand Down
30 changes: 16 additions & 14 deletions lib/src/component/backend.rs
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
use {
super::fastly::api::{backend, http_types},
super::FastlyError,
super::fastly::api::{backend, http_types, types},
crate::{error::Error, session::Session},
};

#[async_trait::async_trait]
impl backend::Host for Session {
async fn exists(&mut self, backend: String) -> Result<bool, FastlyError> {
async fn exists(&mut self, backend: String) -> Result<bool, types::Error> {
Ok(self.backend(&backend).is_some())
}

async fn is_healthy(&mut self, backend: String) -> Result<backend::BackendHealth, FastlyError> {
async fn is_healthy(
&mut self,
backend: String,
) -> Result<backend::BackendHealth, types::Error> {
// just doing this to get a different error if the backend doesn't exist
let _ = self.backend(&backend).ok_or(Error::InvalidArgument)?;
Ok(backend::BackendHealth::Unknown)
}

async fn is_dynamic(&mut self, backend: String) -> Result<bool, FastlyError> {
async fn is_dynamic(&mut self, backend: String) -> Result<bool, types::Error> {
if self.dynamic_backend(&backend).is_some() {
Ok(true)
} else if self.backend(&backend).is_some() {
Expand All @@ -26,7 +28,7 @@ impl backend::Host for Session {
}
}

async fn get_host(&mut self, backend: String, max_len: u64) -> Result<String, FastlyError> {
async fn get_host(&mut self, backend: String, max_len: u64) -> Result<String, types::Error> {
let backend = self.backend(&backend).ok_or(Error::InvalidArgument)?;

let host = backend.uri.host().expect("backend uri has host");
Expand All @@ -46,7 +48,7 @@ impl backend::Host for Session {
&mut self,
backend: String,
max_len: u64,
) -> Result<Option<String>, FastlyError> {
) -> Result<Option<String>, types::Error> {
let backend = self.backend(&backend).ok_or(Error::InvalidArgument)?;
if let Some(host) = backend.override_host.as_ref() {
let host = host.to_str()?;
Expand All @@ -65,7 +67,7 @@ impl backend::Host for Session {
}
}

async fn get_port(&mut self, backend: String) -> Result<u16, FastlyError> {
async fn get_port(&mut self, backend: String) -> Result<u16, types::Error> {
let backend = self.backend(&backend).ok_or(Error::InvalidArgument)?;
match backend.uri.port_u16() {
Some(port) => Ok(port),
Expand All @@ -79,7 +81,7 @@ impl backend::Host for Session {
}
}

async fn get_connect_timeout_ms(&mut self, backend: String) -> Result<u32, FastlyError> {
async fn get_connect_timeout_ms(&mut self, backend: String) -> Result<u32, types::Error> {
// just doing this to get a different error if the backend doesn't exist
let _ = self.backend(&backend).ok_or(Error::InvalidArgument)?;
Err(Error::Unsupported {
Expand All @@ -88,7 +90,7 @@ impl backend::Host for Session {
.into())
}

async fn get_first_byte_timeout_ms(&mut self, backend: String) -> Result<u32, FastlyError> {
async fn get_first_byte_timeout_ms(&mut self, backend: String) -> Result<u32, types::Error> {
// just doing this to get a different error if the backend doesn't exist
let _ = self.backend(&backend).ok_or(Error::InvalidArgument)?;
Err(Error::Unsupported {
Expand All @@ -97,7 +99,7 @@ impl backend::Host for Session {
.into())
}

async fn get_between_bytes_timeout_ms(&mut self, backend: String) -> Result<u32, FastlyError> {
async fn get_between_bytes_timeout_ms(&mut self, backend: String) -> Result<u32, types::Error> {
// just doing this to get a different error if the backend doesn't exist
let _ = self.backend(&backend).ok_or(Error::InvalidArgument)?;
Err(Error::Unsupported {
Expand All @@ -106,15 +108,15 @@ impl backend::Host for Session {
.into())
}

async fn is_ssl(&mut self, backend: String) -> Result<bool, FastlyError> {
async fn is_ssl(&mut self, backend: String) -> Result<bool, types::Error> {
let backend = self.backend(&backend).ok_or(Error::InvalidArgument)?;
Ok(backend.uri.scheme() == Some(&http::uri::Scheme::HTTPS))
}

async fn get_ssl_min_version(
&mut self,
backend: String,
) -> Result<http_types::TlsVersion, FastlyError> {
) -> Result<http_types::TlsVersion, types::Error> {
// just doing this to get a different error if the backend doesn't exist
let _ = self.backend(&backend).ok_or(Error::InvalidArgument)?;
// health checks are not enabled in Viceroy :(
Expand All @@ -127,7 +129,7 @@ impl backend::Host for Session {
async fn get_ssl_max_version(
&mut self,
backend: String,
) -> Result<http_types::TlsVersion, FastlyError> {
) -> Result<http_types::TlsVersion, types::Error> {
// just doing this to get a different error if the backend doesn't exist
let _ = self.backend(&backend).ok_or(Error::InvalidArgument)?;
// health checks are not enabled in Viceroy :(
Expand Down
35 changes: 17 additions & 18 deletions lib/src/component/cache.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use {
super::fastly::api::{cache, http_types},
super::FastlyError,
super::fastly::api::{cache, http_types, types},
crate::{error::Error, session::Session},
};

Expand All @@ -11,7 +10,7 @@ impl cache::Host for Session {
_key: String,
_options_mask: cache::LookupOptionsMask,
_options: cache::LookupOptions,
) -> Result<cache::Handle, FastlyError> {
) -> Result<cache::Handle, types::Error> {
Err(Error::Unsupported {
msg: "Cache API primitives not yet supported",
}
Expand All @@ -23,7 +22,7 @@ impl cache::Host for Session {
_key: String,
_options_mask: cache::WriteOptionsMask,
_options: cache::WriteOptions,
) -> Result<cache::BodyHandle, FastlyError> {
) -> Result<cache::BodyHandle, types::Error> {
Err(Error::Unsupported {
msg: "Cache API primitives not yet supported",
}
Expand All @@ -35,7 +34,7 @@ impl cache::Host for Session {
_handle: cache::Handle,
_options_mask: cache::GetBodyOptionsMask,
_options: cache::GetBodyOptions,
) -> Result<http_types::BodyHandle, FastlyError> {
) -> Result<http_types::BodyHandle, types::Error> {
Err(Error::Unsupported {
msg: "Cache API primitives not yet supported",
}
Expand All @@ -47,7 +46,7 @@ impl cache::Host for Session {
_key: String,
_options_mask: cache::LookupOptionsMask,
_options: cache::LookupOptions,
) -> Result<cache::Handle, FastlyError> {
) -> Result<cache::Handle, types::Error> {
Err(Error::Unsupported {
msg: "Cache API primitives not yet supported",
}
Expand All @@ -59,7 +58,7 @@ impl cache::Host for Session {
_handle: cache::Handle,
_options_mask: cache::WriteOptionsMask,
_options: cache::WriteOptions,
) -> Result<http_types::BodyHandle, FastlyError> {
) -> Result<http_types::BodyHandle, types::Error> {
Err(Error::Unsupported {
msg: "Cache API primitives not yet supported",
}
Expand All @@ -71,7 +70,7 @@ impl cache::Host for Session {
_handle: cache::Handle,
_options_mask: cache::WriteOptionsMask,
_options: cache::WriteOptions,
) -> Result<(http_types::BodyHandle, cache::Handle), FastlyError> {
) -> Result<(http_types::BodyHandle, cache::Handle), types::Error> {
Err(Error::Unsupported {
msg: "Cache API primitives not yet supported",
}
Expand All @@ -83,21 +82,21 @@ impl cache::Host for Session {
_handle: cache::Handle,
_options_mask: cache::WriteOptionsMask,
_options: cache::WriteOptions,
) -> Result<(), FastlyError> {
) -> Result<(), types::Error> {
Err(Error::Unsupported {
msg: "Cache API primitives not yet supported",
}
.into())
}

async fn transaction_cancel(&mut self, _handle: cache::Handle) -> Result<(), FastlyError> {
async fn transaction_cancel(&mut self, _handle: cache::Handle) -> Result<(), types::Error> {
Err(Error::Unsupported {
msg: "Cache API primitives not yet supported",
}
.into())
}

async fn close(&mut self, _handle: cache::Handle) -> Result<(), FastlyError> {
async fn close(&mut self, _handle: cache::Handle) -> Result<(), types::Error> {
Err(Error::Unsupported {
msg: "Cache API primitives not yet supported",
}
Expand All @@ -107,28 +106,28 @@ impl cache::Host for Session {
async fn get_state(
&mut self,
_handle: cache::Handle,
) -> Result<cache::LookupState, FastlyError> {
) -> Result<cache::LookupState, types::Error> {
Err(Error::Unsupported {
msg: "Cache API primitives not yet supported",
}
.into())
}

async fn get_user_metadata(&mut self, _handle: cache::Handle) -> Result<String, FastlyError> {
async fn get_user_metadata(&mut self, _handle: cache::Handle) -> Result<String, types::Error> {
Err(Error::Unsupported {
msg: "Cache API primitives not yet supported",
}
.into())
}

async fn get_length(&mut self, _handle: cache::Handle) -> Result<u64, FastlyError> {
async fn get_length(&mut self, _handle: cache::Handle) -> Result<u64, types::Error> {
Err(Error::Unsupported {
msg: "Cache API primitives not yet supported",
}
.into())
}

async fn get_max_age_ns(&mut self, _handle: cache::Handle) -> Result<u64, FastlyError> {
async fn get_max_age_ns(&mut self, _handle: cache::Handle) -> Result<u64, types::Error> {
Err(Error::Unsupported {
msg: "Cache API primitives not yet supported",
}
Expand All @@ -138,21 +137,21 @@ impl cache::Host for Session {
async fn get_stale_while_revalidate_ns(
&mut self,
_handle: cache::Handle,
) -> Result<u64, FastlyError> {
) -> Result<u64, types::Error> {
Err(Error::Unsupported {
msg: "Cache API primitives not yet supported",
}
.into())
}

async fn get_age_ns(&mut self, _handle: cache::Handle) -> Result<u64, FastlyError> {
async fn get_age_ns(&mut self, _handle: cache::Handle) -> Result<u64, types::Error> {
Err(Error::Unsupported {
msg: "Cache API primitives not yet supported",
}
.into())
}

async fn get_hits(&mut self, _handle: cache::Handle) -> Result<u64, FastlyError> {
async fn get_hits(&mut self, _handle: cache::Handle) -> Result<u64, types::Error> {
Err(Error::Unsupported {
msg: "Cache API primitives not yet supported",
}
Expand Down
7 changes: 3 additions & 4 deletions lib/src/component/dictionary.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
use {
super::fastly::api::{dictionary, types},
super::FastlyError,
crate::{error, session::Session},
};

#[async_trait::async_trait]
impl dictionary::Host for Session {
async fn open(&mut self, name: String) -> Result<dictionary::Handle, FastlyError> {
async fn open(&mut self, name: String) -> Result<dictionary::Handle, types::Error> {
let handle = self.dictionary_handle(name.as_str())?;
Ok(handle.into())
}
Expand All @@ -16,7 +15,7 @@ impl dictionary::Host for Session {
h: dictionary::Handle,
key: String,
max_len: u64,
) -> Result<Option<String>, FastlyError> {
) -> Result<Option<String>, types::Error> {
let dict = self
.dictionary(h.into())?
.contents()
Expand All @@ -25,7 +24,7 @@ impl dictionary::Host for Session {
let key = key.as_str();
let item = dict
.get(key)
.ok_or_else(|| FastlyError::from(types::Error::OptionalNone))?;
.ok_or_else(|| types::Error::from(types::Error::OptionalNone))?;

if item.len() > usize::try_from(max_len).unwrap() {
return Err(error::Error::BufferLengthError {
Expand Down
Loading

0 comments on commit 48312d2

Please sign in to comment.