arthur cosendey
arthur cosendey
CDCloudflare Developers
Created by arthur cosendey on 5/15/2024 in #workers-help
Error on the `wrangler/templates/middleware` directory
sorry! hahaha i'm new here
8 replies
CDCloudflare Developers
Created by arthur cosendey on 5/15/2024 in #workers-help
Error on the `wrangler/templates/middleware` directory
@Community Champion @Cloudflare (Server Owner)
8 replies
CDCloudflare Developers
Created by arthur cosendey on 5/15/2024 in #workers-help
Error on the `wrangler/templates/middleware` directory
Here's a potential fix considering the above points:
// Inside the "__facade__originalAddEventListener__('scheduled', (event) => {...})" function

const facadeEvent = new __Facade_ScheduledEvent__("scheduled", {
scheduledTime: event.scheduledTime,
cron: event.cron,
noRetry: event.noRetry.bind(event),
});

__FACADE_EVENT_TARGET__.dispatchEvent(facadeEvent);

// Check if there are any promises to wait until completion
if (Array.isArray(facadeEvent[__facade_waitUntil__]) && facadeEvent[__facade_waitUntil__].length > 0) {
event.waitUntil(Promise.all(facadeEvent[__facade_waitUntil__]));
}
// Inside the "__facade__originalAddEventListener__('scheduled', (event) => {...})" function

const facadeEvent = new __Facade_ScheduledEvent__("scheduled", {
scheduledTime: event.scheduledTime,
cron: event.cron,
noRetry: event.noRetry.bind(event),
});

__FACADE_EVENT_TARGET__.dispatchEvent(facadeEvent);

// Check if there are any promises to wait until completion
if (Array.isArray(facadeEvent[__facade_waitUntil__]) && facadeEvent[__facade_waitUntil__].length > 0) {
event.waitUntil(Promise.all(facadeEvent[__facade_waitUntil__]));
}
This adjustment ensures that Promise.all is only called if there are actually promises to wait upon, addressing the TypeScript error about Promise being used as a value.
8 replies
CDCloudflare Developers
Created by arthur cosendey on 5/15/2024 in #workers-help
Error on the `wrangler/templates/middleware` directory
After interacting with phind in my codebase appears to be a problem with the
facadeEvent
facadeEvent
, here's the response from phind: The error you're encountering in the wrangler file, specifically at line 228, is due to the incorrect usage of Promise.all with facadeEvent[facade_waitUntil]. The error message suggests that Promise is being treated as a value rather than a type, which is a common issue when dealing with TypeScript's strict typing system. Given the context and the error message, it seems like the problem arises because facadeEvent[facade_waitUntil] is expected to be an array of promises (Awaitable<unknown>[]), but TypeScript is interpreting it differently. This could be due to how the facade_waitUntil symbol is defined or used within the Facade_ExtendableEvent class. To resolve this issue, ensure that facadeEvent[facade_waitUntil] is correctly initialized as an array of promises before attempting to use Promise.all on it. Here's a revised approach to ensure that facadeEvent[facade_waitUntil] is properly handled: Ensure Proper Initialization: Make sure that facadeEvent[facade_waitUntil] is initialized as an empty array if no promises have been added yet. This ensures that Promise.all receives an array even if it's empty. Correct Usage of Promise.all: Ensure that Promise.all is used correctly. It expects an iterable of promises. If facadeEvent[facade_waitUntil] is not guaranteed to always contain promises, you should check its length before calling Promise.all.
8 replies