Description
Disclaimer: I could totally be doing something stupid here, but I can't see what.
Code that reproduces the issue for me:
// mod.ts
import { SlackAPI } from "https://deno.land/x/[email protected]/mod.ts";
const getClientAsync = async () => {
// This return style always fails
return SlackAPI("foo");
};
const getClientNestedAsync = async () => {
// Nesting it in an object succeeds
return { c: SlackAPI("foo") };
};
const getClient = () => {
// Returning from a non-async function succeeds
return SlackAPI("foo");
};
const run = async () => {
console.log("Running");
SlackAPI("foo");
console.log("Got inline client");
getClient();
console.log("Got client from func");
await getClientNestedAsync();
console.log("Got client from nested async func");
await getClientAsync();
console.log("Got client from async func");
};
if (import.meta.main) {
await run();
}
Run this with: deno run --allow-all mod.ts
Deno version: deno 1.44.4+86010be
If I run the above code, I get this output:
Running
Got inline client
Got client from func
Got client from nested async func
error: Top-level await promise never resolved
await run();
^
at <anonymous> (file:///Users/tm/Code/scratch/denobug/mod.ts:31:3)
I can swap the order of the getClient calls around - it always fails at the call to the async, non-nested return.
I first saw this behaviour in a worker, where it doesn't even show the error. It just seems to... stop. No error, nothing to show it has crashed - I have a lot going on in my worker though so can't rule out suppression.
I've also tested the returned client in all cases, and in all cases the client is functional/can make calls as expected. I've tried every odd variation I can think of, including assigning the client to a variable, using it first, then returning.
It seems that no matter what, if that specific value is returned from an async function, it crashes Deno and can not be caught.
Activity