-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[BUG] Returning SlackAPIClient from an async function crashes Deno #107
Comments
It looks to be due to how the nested proxy logic works here, returning a function for any prop via the getter: deno-slack-api/src/api-proxy.ts Lines 46 to 57 in 26fcdd6
Deno calls |
As a workaround for anyone else having this issue: const c = SlackAPI("foo");
Object.assign(c, { then: undefined });
return c; This stops it from blowing up |
Hey @manterfield, thanks for filing this.
Can you link me to code showing this? Maybe the proxy getter in this module is a bit too sweeping / far-reaching? Perhaps there should be a list of methods/properties it doesn't try to direct to My two questions above are trying to tease out an answer to the question "where should a fix for this problem land?" |
I agree that the proxy getter is a bit too greedy in this case. So if you add a deno-slack-api/src/api-proxy.ts Line 48 in 26fcdd6
You'll see it output then for the prop being accessed (as long as the client is returned from an async function as in my example above).
I researched after bumping into this and it isn't Deno specific. The spec actually describes this behaviour: https://promisesaplus.com/
and the promise resolution behaviour:
Which makes perfect sense now I've been forced to think about it, though I had been quite enjoying my ignorance. If I directly return the result of an async function from an async function, I wouldn't want to have to resolve twice. |
Thanks for the discussion <3 I agree. I'll work on a patch to reduce the scope of proxy greed :D |
Fixed in deno_slack_api 2.7.1: https://github.com/slackapi/deno-slack-api/releases/tag/2.7.1 |
The
deno-slack
versionsI don't have an import map, but
deno_slack_api
is2.7.0
- also tested at2.1.1
Deno runtime version
deno 1.44.4+86010be
OS info
(also tried on Alpine-1.43.2)
Describe the bug
Attempting to return SlackAPIClient from an async function causes Deno to fail with a
top-level await promise never resolved
. I've also ran this within a worker (my original production code) and in that scenario execution seems to simply... stop. No errors thrown.Steps to reproduce
Run with:
deno run --allow-all mod.ts
Expected result
Should see all logs, including
Got client from async func
. More generally, I should be able to return the SlackClientAPI object without error from an async function.Actual result
Running the above outputs:
If I move the call to
getClientAsync
anywhere else, it still immediately fails at the point it makes that call.Note:
I've also raised an issue on Deno here: denoland/deno_core#828
It seems to me that Deno shouldn't behave this way, but also it might be something this project can workaround (since the SlackAPIClient is the first value I've seen exhibit this behaviour).
The text was updated successfully, but these errors were encountered: