From a72c76b8c81077476e56d92632800c0bf69c14cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Duarte?= Date: Mon, 26 Aug 2024 15:21:33 +0100 Subject: [PATCH] fix: don't use WorkerEntrypoint env or ctx in email handlers --- worker-build/src/js/shim.js | 6 ++++-- worker-macros/src/event.rs | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/worker-build/src/js/shim.js b/worker-build/src/js/shim.js index 6efdbdd5..0e62d5e3 100644 --- a/worker-build/src/js/shim.js +++ b/worker-build/src/js/shim.js @@ -21,8 +21,10 @@ class Entrypoint extends WorkerEntrypoint { return await imports.scheduled(event, this.env, this.ctx) } - async email(message) { - return await imports.email(message, this.env, this.ctx) + // For some reason, email events doesn't seem to use WorkerEntrypoint so we get the env and ctx from + // from the function itself. + async email(message, _env, _ctx) { + return await imports.email(message, _env, _ctx) } } diff --git a/worker-macros/src/event.rs b/worker-macros/src/event.rs index 656ee655..9e803d0a 100644 --- a/worker-macros/src/event.rs +++ b/worker-macros/src/event.rs @@ -190,7 +190,7 @@ pub fn expand_macro(attr: TokenStream, item: TokenStream) -> TokenStream { &(input_fn.sig.ident.to_string() + "_email_glue"), input_fn.sig.ident.span(), ); - let wrapper_fn_ident = Ident::new("email", input_fn.sig.ident.span()); + let wrapper_fn_ident = Ident::new("email_handler", input_fn.sig.ident.span()); // rename the original attributed fn input_fn.sig.ident = input_fn_ident.clone();