Skip to content

Commit 24b0d26

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 24b0d26

File tree

19 files changed

+326
-252
lines changed

19 files changed

+326
-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: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,14 @@ 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.session_mut().take_async_item(handle).unwrap();
66+
6067
Ok(())
6168
}
6269
}

src/component/compute/cache.rs

Lines changed: 69 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,66 @@ 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(
192+
&mut self,
193+
_handle: Resource<api::ReplaceEntry>,
194+
) -> Result<(), types::Error> {
195+
Err(Error::Unsupported {
196+
msg: "Cache API primitives not yet supported",
197+
}
198+
.into())
199+
}
200+
}
201+
202+
impl api::HostReplaceEntry for ComponentCtx {
143203
async fn replace(
144204
&mut self,
145205
key: Vec<u8>,
@@ -152,7 +212,7 @@ impl api::Host for ComponentCtx {
152212
.into())
153213
}
154214

155-
async fn replace_get_age_ns(
215+
async fn get_age_ns(
156216
&mut self,
157217
_handle: Resource<api::ReplaceEntry>,
158218
) -> Result<Option<api::DurationNs>, types::Error> {
@@ -162,7 +222,7 @@ impl api::Host for ComponentCtx {
162222
.into())
163223
}
164224

165-
async fn replace_get_body(
225+
async fn get_body(
166226
&mut self,
167227
_handle: Resource<api::ReplaceEntry>,
168228
_options: api::GetBodyOptions,
@@ -173,7 +233,7 @@ impl api::Host for ComponentCtx {
173233
.into())
174234
}
175235

176-
async fn replace_get_hits(
236+
async fn get_hits(
177237
&mut self,
178238
_handle: Resource<api::ReplaceEntry>,
179239
) -> Result<Option<u64>, types::Error> {
@@ -183,7 +243,7 @@ impl api::Host for ComponentCtx {
183243
.into())
184244
}
185245

186-
async fn replace_get_length(
246+
async fn get_length(
187247
&mut self,
188248
_handle: Resource<api::ReplaceEntry>,
189249
) -> Result<Option<u64>, types::Error> {
@@ -193,7 +253,7 @@ impl api::Host for ComponentCtx {
193253
.into())
194254
}
195255

196-
async fn replace_get_max_age_ns(
256+
async fn get_max_age_ns(
197257
&mut self,
198258
_handle: Resource<api::ReplaceEntry>,
199259
) -> Result<Option<api::DurationNs>, types::Error> {
@@ -203,7 +263,7 @@ impl api::Host for ComponentCtx {
203263
.into())
204264
}
205265

206-
async fn replace_get_stale_while_revalidate_ns(
266+
async fn get_stale_while_revalidate_ns(
207267
&mut self,
208268
_handle: Resource<api::ReplaceEntry>,
209269
) -> Result<Option<api::DurationNs>, types::Error> {
@@ -213,7 +273,7 @@ impl api::Host for ComponentCtx {
213273
.into())
214274
}
215275

216-
async fn replace_get_state(
276+
async fn get_state(
217277
&mut self,
218278
_handle: Resource<api::ReplaceEntry>,
219279
) -> Result<Option<api::LookupState>, types::Error> {
@@ -223,7 +283,7 @@ impl api::Host for ComponentCtx {
223283
.into())
224284
}
225285

226-
async fn replace_get_user_metadata(
286+
async fn get_user_metadata(
227287
&mut self,
228288
_handle: Resource<api::ReplaceEntry>,
229289
_max_len: u64,
@@ -234,51 +294,7 @@ impl api::Host for ComponentCtx {
234294
.into())
235295
}
236296

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?;
297+
fn drop(&mut self, _entry: Resource<api::ReplaceEntry>) -> wasmtime::Result<()> {
282298
Ok(())
283299
}
284300
}

src/component/compute/error.rs

Lines changed: 11 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,10 @@ 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(_) => {
186+
panic!("`UnknownSecretStore` should not be used in components")
187+
}
188+
UnknownSecret(_) => panic!("`UnknownSecret` should not be used in components"),
187189
InvalidSecretStoreHandle(_) => types::Error::InvalidArgument,
188190
InvalidSecretHandle(_) => types::Error::InvalidArgument,
189191
}
@@ -194,7 +196,9 @@ impl From<DictionaryError> for types::Error {
194196
fn from(err: DictionaryError) -> Self {
195197
use DictionaryError::*;
196198
match err {
197-
UnknownDictionaryItem(_) => types::Error::OptionalNone,
199+
UnknownDictionaryItem(_) => {
200+
panic!("`UnknownDictionaryItem` should not be used in components")
201+
}
198202
UnknownDictionary(_) => types::Error::InvalidArgument,
199203
}
200204
}
@@ -207,7 +211,7 @@ impl From<error::Error> for types::Error {
207211
Error::BufferLengthError { .. } => types::Error::BufferLen(0),
208212
Error::InvalidArgument => types::Error::InvalidArgument,
209213
Error::Unsupported { .. } => types::Error::Unsupported,
210-
Error::HandleError { .. } => types::Error::BadHandle,
214+
Error::HandleError { .. } => panic!("`HandleError` should not be used in components"),
211215
Error::InvalidStatusCode { .. } => types::Error::InvalidArgument,
212216
// Map specific kinds of `hyper::Error` into their respective error codes.
213217
Error::HyperError(e) if e.is_parse() => types::Error::HttpInvalid,
@@ -222,8 +226,7 @@ impl From<error::Error> for types::Error {
222226
Error::KvStoreError(e) => e.into(),
223227
Error::SecretStoreError(e) => e.into(),
224228
Error::CacheError(e) => e.into(),
225-
Error::NoDownstreamReqsAvailable => types::Error::OptionalNone,
226-
Error::ValueAbsent => types::Error::OptionalNone,
229+
Error::ValueAbsent => panic!("`ValueAbsent` should not be used in components"),
227230
Error::LimitExceeded { .. } => types::Error::LimitExceeded,
228231
// All other hostcall errors map to a generic `ERROR` value.
229232
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+
}

0 commit comments

Comments
 (0)