From 7d105460228f8bdc6f0345cc5c44868bc3d9f963 Mon Sep 17 00:00:00 2001 From: darckfast <21337578+Darckfast@users.noreply.github.com> Date: Tue, 7 Jul 2026 10:36:56 -0300 Subject: [PATCH] fix(durable-object): fix wrong return type on durable object `alarm` fn The `alarm` fn, according to Cloudflare docs https://developers.cloudflare.com/durable-objects/api/alarms/#alarm, returns `void`, but the `workers-rs` was returning a `Result`, this fixes by changing the return type to `Result<()>` Fixes https://github.com/cloudflare/workers-rs/issues/712 --- test/src/alarm.rs | 4 ++-- worker-macros/src/durable_object.rs | 3 +-- worker/src/durable.rs | 2 +- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/test/src/alarm.rs b/test/src/alarm.rs index 76e188bfb..e8e7975a0 100644 --- a/test/src/alarm.rs +++ b/test/src/alarm.rs @@ -29,10 +29,10 @@ impl DurableObject for AlarmObject { Response::ok(alarmed.to_string()) } - async fn alarm(&self) -> Result { + async fn alarm(&self) -> Result<()> { self.state.storage().put("alarmed", true).await?; console_log!("Alarm has been triggered!"); - Response::ok("ALARMED") + Ok(()) } } diff --git a/worker-macros/src/durable_object.rs b/worker-macros/src/durable_object.rs index 39a2a7d33..5fea7f90e 100644 --- a/worker-macros/src/durable_object.rs +++ b/worker-macros/src/durable_object.rs @@ -69,8 +69,7 @@ mod bindgen_methods { ::worker::js_sys::futures::future_to_promise(::std::panic::AssertUnwindSafe(async move { ::alarm(static_self).await - .map(::worker::worker_sys::web_sys::Response::from) - .map(::worker::wasm_bindgen::JsValue::from) + .map(|_| ::worker::wasm_bindgen::JsValue::NULL) .map_err(::worker::wasm_bindgen::JsValue::from) })) } diff --git a/worker/src/durable.rs b/worker/src/durable.rs index 1983f556f..46c335886 100644 --- a/worker/src/durable.rs +++ b/worker/src/durable.rs @@ -885,7 +885,7 @@ pub trait DurableObject: has_durable_object_attribute { async fn fetch(&self, req: Request) -> Result; #[allow(clippy::diverging_sub_expression)] - async fn alarm(&self) -> Result { + async fn alarm(&self) -> Result<()> { worker_sys::console_error!("alarm() handler not implemented"); unimplemented!("alarm() handler") }