Skip to content

Commit 4528908

Browse files
Update to the latest WITs and adapter.
Changes: - `inspect-options` moved from `http-req` to `security`. - Some error types are renamed: - `bad-handle` is now `auxiliary-error` - `optional-none` is now `cannot-read` - `log.write` is now infallible. - `cache.replace-entry` is now a separate resource rather than a type alias.
1 parent 24f796f commit 4528908

File tree

19 files changed

+322
-252
lines changed

19 files changed

+322
-252
lines changed

src/cache.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,10 @@ impl From<Error> for ComponentError {
6969
// platform uses. Check!
7070
Error::InvalidKey => ComponentError::InvalidArgument,
7171
Error::InvalidArgument(_) => ComponentError::InvalidArgument,
72-
Error::CannotWrite => ComponentError::BadHandle,
73-
Error::Missing => ComponentError::OptionalNone,
74-
Error::HandleBodyUsed => ComponentError::BadHandle,
75-
Error::NotRevalidatable => ComponentError::BadHandle,
72+
Error::CannotWrite => ComponentError::AuxiliaryError,
73+
Error::Missing => ComponentError::CannotRead,
74+
Error::HandleBodyUsed => ComponentError::AuxiliaryError,
75+
Error::NotRevalidatable => ComponentError::AuxiliaryError,
7676
}
7777
}
7878
}

src/component.rs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,17 @@ pub(crate) mod bindings {
2929
"fastly:compute/http-downstream/await-request": async | tracing,
3030
"fastly:compute/http-req/await-response": async | tracing,
3131
"fastly:compute/cache/close-entry": async | tracing,
32+
"fastly:compute/cache/close-replace-entry": async | tracing,
3233
"fastly:compute/cache/insert": async | tracing,
33-
"fastly:compute/cache/replace": async | tracing,
34-
"fastly:compute/cache/replace-get-age-ns": async | tracing,
35-
"fastly:compute/cache/replace-get-body": async | tracing,
36-
"fastly:compute/cache/replace-get-hits": async | tracing,
37-
"fastly:compute/cache/replace-get-length": async | tracing,
38-
"fastly:compute/cache/replace-get-max-age-ns": async | tracing,
39-
"fastly:compute/cache/replace-get-stale-while-revalidate-ns": async | tracing,
40-
"fastly:compute/cache/replace-get-state": async | tracing,
41-
"fastly:compute/cache/replace-get-user-metadata": async | tracing,
34+
"fastly:compute/cache/[static]replace-entry.replace": async | tracing,
35+
"fastly:compute/cache/[method]replace-entry.get-age-ns": async | tracing,
36+
"fastly:compute/cache/[method]replace-entry.get-body": async | tracing,
37+
"fastly:compute/cache/[method]replace-entry.get-hits": async | tracing,
38+
"fastly:compute/cache/[method]replace-entry.get-length": async | tracing,
39+
"fastly:compute/cache/[method]replace-entry.get-max-age-ns": async | tracing,
40+
"fastly:compute/cache/[method]replace-entry.get-stale-while-revalidate-ns": async | tracing,
41+
"fastly:compute/cache/[method]replace-entry.get-state": async | tracing,
42+
"fastly:compute/cache/[method]replace-entry.get-user-metadata": async | tracing,
4243
"fastly:compute/cache/replace-insert": async | tracing,
4344
"fastly:compute/cache/[method]entry.get-age-ns": async | tracing,
4445
"fastly:compute/cache/[method]entry.get-body": async | tracing,

src/component/compute/async_io.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,17 @@ impl async_io::HostPollable for ComponentCtx {
5656
.is_some()
5757
}
5858

59-
fn drop(&mut self, _pollable: Resource<async_io::Pollable>) -> wasmtime::Result<()> {
59+
fn drop(&mut self, handle: Resource<async_io::Pollable>) -> wasmtime::Result<()> {
60+
let handle = wiggle_abi::types::AsyncItemHandle::from(handle).into();
61+
62+
// Use `.take_async_item` instead of manipulating
63+
// `self.session_mut().async_items` directly, so that any extra state
64+
// associated with the item is also cleared.
65+
let _ = self
66+
.session_mut()
67+
.take_async_item(handle)
68+
.unwrap();
69+
6070
Ok(())
6171
}
6272
}

src/component/compute/cache.rs

Lines changed: 66 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,63 @@ impl api::Host for ComponentCtx {
140140
Ok(handle.into())
141141
}
142142

143+
async fn replace_insert(
144+
&mut self,
145+
_handle: Resource<api::ReplaceEntry>,
146+
_options: api::WriteOptions,
147+
) -> Result<Resource<api::Body>, types::Error> {
148+
Err(Error::Unsupported {
149+
msg: "Cache API primitives not yet supported",
150+
}
151+
.into())
152+
}
153+
154+
async fn await_entry(
155+
&mut self,
156+
handle: Resource<api::PendingEntry>,
157+
) -> Result<Resource<api::Entry>, types::Error> {
158+
let handle = CacheBusyHandle::from(handle).into();
159+
// Swap out for a distinct handle, so we don't hit a repeated `close`+`close_busy`:
160+
let entry = self.session_mut().cache_entry_mut(handle).await?;
161+
let mut other_entry = entry.stub();
162+
std::mem::swap(entry, &mut other_entry);
163+
let task = PeekableTask::spawn(Box::pin(async move { Ok(other_entry) })).await;
164+
let h: CacheHandle = self
165+
.session_mut()
166+
.insert_cache_op(PendingCacheTask::new(task))
167+
.into();
168+
Ok(h.into())
169+
}
170+
171+
fn close_pending_entry(
172+
&mut self,
173+
handle: Resource<api::PendingEntry>,
174+
) -> Result<(), types::Error> {
175+
let handle = CacheBusyHandle::from(handle).into();
176+
// Don't wait for the transaction to complete; drop the future to cancel.
177+
let _ = self.session_mut().take_cache_entry(handle)?;
178+
Ok(())
179+
}
180+
181+
async fn close_entry(&mut self, handle: Resource<api::Entry>) -> Result<(), types::Error> {
182+
let _ = self
183+
.session_mut()
184+
.take_cache_entry(handle.into())?
185+
.task()
186+
.recv()
187+
.await?;
188+
Ok(())
189+
}
190+
191+
async fn close_replace_entry(&mut self, _handle: Resource<api::ReplaceEntry>) -> Result<(), types::Error> {
192+
Err(Error::Unsupported {
193+
msg: "Cache API primitives not yet supported",
194+
}
195+
.into())
196+
}
197+
}
198+
199+
impl api::HostReplaceEntry for ComponentCtx {
143200
async fn replace(
144201
&mut self,
145202
key: Vec<u8>,
@@ -152,7 +209,7 @@ impl api::Host for ComponentCtx {
152209
.into())
153210
}
154211

155-
async fn replace_get_age_ns(
212+
async fn get_age_ns(
156213
&mut self,
157214
_handle: Resource<api::ReplaceEntry>,
158215
) -> Result<Option<api::DurationNs>, types::Error> {
@@ -162,7 +219,7 @@ impl api::Host for ComponentCtx {
162219
.into())
163220
}
164221

165-
async fn replace_get_body(
222+
async fn get_body(
166223
&mut self,
167224
_handle: Resource<api::ReplaceEntry>,
168225
_options: api::GetBodyOptions,
@@ -173,7 +230,7 @@ impl api::Host for ComponentCtx {
173230
.into())
174231
}
175232

176-
async fn replace_get_hits(
233+
async fn get_hits(
177234
&mut self,
178235
_handle: Resource<api::ReplaceEntry>,
179236
) -> Result<Option<u64>, types::Error> {
@@ -183,7 +240,7 @@ impl api::Host for ComponentCtx {
183240
.into())
184241
}
185242

186-
async fn replace_get_length(
243+
async fn get_length(
187244
&mut self,
188245
_handle: Resource<api::ReplaceEntry>,
189246
) -> Result<Option<u64>, types::Error> {
@@ -193,7 +250,7 @@ impl api::Host for ComponentCtx {
193250
.into())
194251
}
195252

196-
async fn replace_get_max_age_ns(
253+
async fn get_max_age_ns(
197254
&mut self,
198255
_handle: Resource<api::ReplaceEntry>,
199256
) -> Result<Option<api::DurationNs>, types::Error> {
@@ -203,7 +260,7 @@ impl api::Host for ComponentCtx {
203260
.into())
204261
}
205262

206-
async fn replace_get_stale_while_revalidate_ns(
263+
async fn get_stale_while_revalidate_ns(
207264
&mut self,
208265
_handle: Resource<api::ReplaceEntry>,
209266
) -> Result<Option<api::DurationNs>, types::Error> {
@@ -213,7 +270,7 @@ impl api::Host for ComponentCtx {
213270
.into())
214271
}
215272

216-
async fn replace_get_state(
273+
async fn get_state(
217274
&mut self,
218275
_handle: Resource<api::ReplaceEntry>,
219276
) -> Result<Option<api::LookupState>, types::Error> {
@@ -223,7 +280,7 @@ impl api::Host for ComponentCtx {
223280
.into())
224281
}
225282

226-
async fn replace_get_user_metadata(
283+
async fn get_user_metadata(
227284
&mut self,
228285
_handle: Resource<api::ReplaceEntry>,
229286
_max_len: u64,
@@ -234,51 +291,7 @@ impl api::Host for ComponentCtx {
234291
.into())
235292
}
236293

237-
async fn replace_insert(
238-
&mut self,
239-
_handle: Resource<api::ReplaceEntry>,
240-
_options: api::WriteOptions,
241-
) -> Result<Resource<api::Body>, types::Error> {
242-
Err(Error::Unsupported {
243-
msg: "Cache API primitives not yet supported",
244-
}
245-
.into())
246-
}
247-
248-
async fn await_entry(
249-
&mut self,
250-
handle: Resource<api::PendingEntry>,
251-
) -> Result<Resource<api::Entry>, types::Error> {
252-
let handle = CacheBusyHandle::from(handle).into();
253-
// Swap out for a distinct handle, so we don't hit a repeated `close`+`close_busy`:
254-
let entry = self.session_mut().cache_entry_mut(handle).await?;
255-
let mut other_entry = entry.stub();
256-
std::mem::swap(entry, &mut other_entry);
257-
let task = PeekableTask::spawn(Box::pin(async move { Ok(other_entry) })).await;
258-
let h: CacheHandle = self
259-
.session_mut()
260-
.insert_cache_op(PendingCacheTask::new(task))
261-
.into();
262-
Ok(h.into())
263-
}
264-
265-
fn close_pending_entry(
266-
&mut self,
267-
handle: Resource<api::PendingEntry>,
268-
) -> Result<(), types::Error> {
269-
let handle = CacheBusyHandle::from(handle).into();
270-
// Don't wait for the transaction to complete; drop the future to cancel.
271-
let _ = self.session_mut().take_cache_entry(handle)?;
272-
Ok(())
273-
}
274-
275-
async fn close_entry(&mut self, handle: Resource<api::Entry>) -> Result<(), types::Error> {
276-
let _ = self
277-
.session_mut()
278-
.take_cache_entry(handle.into())?
279-
.task()
280-
.recv()
281-
.await?;
294+
fn drop(&mut self, _entry: Resource<api::ReplaceEntry>) -> wasmtime::Result<()> {
282295
Ok(())
283296
}
284297
}

src/component/compute/error.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ impl From<std::convert::Infallible> for types::Error {
3232

3333
impl From<HandleError> for types::Error {
3434
fn from(_: HandleError) -> Self {
35-
types::Error::BadHandle
35+
panic!("`HandleError` should not be used in components")
3636
}
3737
}
3838

@@ -129,7 +129,7 @@ impl From<ObjectStoreError> for types::Error {
129129
fn from(err: ObjectStoreError) -> Self {
130130
use ObjectStoreError::*;
131131
match err {
132-
MissingObject => types::Error::OptionalNone,
132+
MissingObject => panic!("`MissingObject` should not be used in components"),
133133
PoisonedLock => panic!("{}", err),
134134
UnknownObjectStore(_) => types::Error::InvalidArgument,
135135
}
@@ -182,8 +182,8 @@ impl From<SecretStoreError> for types::Error {
182182
fn from(err: SecretStoreError) -> Self {
183183
use SecretStoreError::*;
184184
match err {
185-
UnknownSecretStore(_) => types::Error::OptionalNone,
186-
UnknownSecret(_) => types::Error::OptionalNone,
185+
UnknownSecretStore(_) => panic!("`UnknownSecretStore` should not be used in components"),
186+
UnknownSecret(_) => panic!("`UnknownSecret` should not be used in components"),
187187
InvalidSecretStoreHandle(_) => types::Error::InvalidArgument,
188188
InvalidSecretHandle(_) => types::Error::InvalidArgument,
189189
}
@@ -194,7 +194,7 @@ impl From<DictionaryError> for types::Error {
194194
fn from(err: DictionaryError) -> Self {
195195
use DictionaryError::*;
196196
match err {
197-
UnknownDictionaryItem(_) => types::Error::OptionalNone,
197+
UnknownDictionaryItem(_) => panic!("`UnknownDictionaryItem` should not be used in components"),
198198
UnknownDictionary(_) => types::Error::InvalidArgument,
199199
}
200200
}
@@ -207,7 +207,7 @@ impl From<error::Error> for types::Error {
207207
Error::BufferLengthError { .. } => types::Error::BufferLen(0),
208208
Error::InvalidArgument => types::Error::InvalidArgument,
209209
Error::Unsupported { .. } => types::Error::Unsupported,
210-
Error::HandleError { .. } => types::Error::BadHandle,
210+
Error::HandleError { .. } => panic!("`HandleError` should not be used in components"),
211211
Error::InvalidStatusCode { .. } => types::Error::InvalidArgument,
212212
// Map specific kinds of `hyper::Error` into their respective error codes.
213213
Error::HyperError(e) if e.is_parse() => types::Error::HttpInvalid,
@@ -222,8 +222,7 @@ impl From<error::Error> for types::Error {
222222
Error::KvStoreError(e) => e.into(),
223223
Error::SecretStoreError(e) => e.into(),
224224
Error::CacheError(e) => e.into(),
225-
Error::NoDownstreamReqsAvailable => types::Error::OptionalNone,
226-
Error::ValueAbsent => types::Error::OptionalNone,
225+
Error::ValueAbsent => panic!("`ValueAbsent` should not be used in components"),
227226
Error::LimitExceeded { .. } => types::Error::LimitExceeded,
228227
// All other hostcall errors map to a generic `ERROR` value.
229228
Error::AbiVersionMismatch

src/component/compute/http_downstream.rs

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,22 +24,15 @@ impl http_downstream::Host for ComponentCtx {
2424
Ok(handle.into())
2525
}
2626

27-
fn next_request_abandon(
28-
&mut self,
29-
handle: Resource<http_downstream::PendingRequest>,
30-
) -> Result<(), types::Error> {
31-
let handle = RequestPromiseHandle::from(handle).into();
32-
self.session_mut().abandon_pending_downstream_req(handle)?;
33-
Ok(())
34-
}
35-
3627
async fn await_request(
3728
&mut self,
3829
handle: Resource<http_downstream::PendingRequest>,
3930
) -> Result<Option<(Resource<http_req::Request>, Resource<http_body::Body>)>, types::Error>
4031
{
4132
let handle = RequestPromiseHandle::from(handle).into();
42-
let (req, body) = self.session_mut().await_downstream_req(handle).await?;
33+
let Some((req, body)) = self.session_mut().await_downstream_req(handle).await? else {
34+
return Ok(None);
35+
};
4336

4437
Ok(Some((req.into(), body.into())))
4538
}

src/component/compute/http_req.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -487,9 +487,3 @@ impl http_req::HostExtraCacheOverrideDetails for ComponentCtx {
487487
Ok(())
488488
}
489489
}
490-
491-
impl http_req::HostExtraInspectOptions for ComponentCtx {
492-
fn drop(&mut self, _options: Resource<http_req::ExtraInspectOptions>) -> wasmtime::Result<()> {
493-
Ok(())
494-
}
495-
}

src/component/compute/log.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,15 @@ impl log::HostEndpoint for ComponentCtx {
3030
Ok(self.session_mut().log_endpoint_handle(name).into())
3131
}
3232

33-
fn write(&mut self, h: Resource<log::Endpoint>, msg: Vec<u8>) -> Result<u32, types::Error> {
34-
let endpoint = self.session().log_endpoint(h.into())?;
35-
endpoint.write_entry(&msg)?;
36-
Ok(u32::try_from(msg.len()).unwrap())
33+
fn write(&mut self, h: Resource<log::Endpoint>, msg: Vec<u8>) {
34+
let endpoint = self.session().log_endpoint(h.into()).unwrap();
35+
36+
// The log API is infallible, so if we get an error, warn about it
37+
// rather than bubbling it up through the log API.
38+
match endpoint.write_entry(&msg) {
39+
Ok(()) => {}
40+
Err(err) => tracing::error!("Error writing log message: {:?}", err),
41+
}
3742
}
3843

3944
fn drop(&mut self, _endpoint: Resource<log::Endpoint>) -> wasmtime::Result<()> {

src/component/compute/security.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ impl security::Host for ComponentCtx {
99
&mut self,
1010
ds_req: Resource<http_req::Request>,
1111
ds_body: Resource<http_body::Body>,
12-
info: http_req::InspectOptions,
12+
info: security::InspectOptions,
1313
buf_max_len: u64,
1414
) -> Result<String, types::Error> {
1515
// Make sure we're given valid handles, even though we won't use them.
@@ -37,3 +37,9 @@ impl security::Host for ComponentCtx {
3737
}
3838
}
3939
}
40+
41+
impl security::HostExtraInspectOptions for ComponentCtx {
42+
fn drop(&mut self, _options: Resource<security::ExtraInspectOptions>) -> wasmtime::Result<()> {
43+
Ok(())
44+
}
45+
}

src/error.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -159,9 +159,6 @@ pub enum Error {
159159

160160
#[error("cache error: {0}")]
161161
CacheError(crate::cache::Error),
162-
163-
#[error("no downstream requests are available")]
164-
NoDownstreamReqsAvailable,
165162
}
166163

167164
impl Error {
@@ -193,7 +190,6 @@ impl Error {
193190
FastlyStatus::Httpincomplete
194191
}
195192
Error::HyperError(_) => FastlyStatus::Error,
196-
Error::NoDownstreamReqsAvailable => FastlyStatus::None,
197193
// Destructuring a GuestError is recursive, so we use a helper function:
198194
Error::GuestError(e) => Self::guest_error_fastly_status(e),
199195
// We delegate to some error types' own implementation of `to_fastly_status`.

0 commit comments

Comments
 (0)