Skip to content
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

feat(core): Show unresolved promise origin in tests #17813

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

jespertheend
Copy link
Contributor

No description provided.

@jespertheend
Copy link
Contributor Author

It builds, but I'm running into a panic when it tries to find the stalled top level await.
It seems like find_stalled_top_level_await is not able to find anything and reaches the end of the function:

unreachable!()

@bartlomieju
Copy link
Member

Hey @jespertheend and sorry for slow response. I made a mistake when I suggested this solution - the hanging promises in the tests are not really top level so the suggested API will not work in this situation. I need to dig through V8 APIs to see if there's any other API we can use to actually get a stack trace for the promise (I believe not). If you wanna play around with it I suggest trying to manually reject the promise when you get into that resolve_value handler.

@jespertheend
Copy link
Contributor Author

@bartlomieju Ah that's clever, that sounds like it could work. Though simply rejecting it seems to cause the promise to reject outside of the test. I'm getting This error was not caught from a test, even though I'm awaiting the promise inside the test. But maybe I'm not rejecting the promise the right way.

Deno.test({
  name: "Unresolved forever",
  async fn() {
    await new Promise(() => {});
  }
})
./my.test.js (uncaught error)
error: (in promise) undefined
This error was not caught from a test and caused the test runner to fail on the referenced module.
It most likely originated from a dangling promise, event/timeout handler or top-level code.

@bartlomieju
Copy link
Member

It looks like there's no API to reject a promise from Rust API - we can only do that if we created the promise from Rust, but that's not the case here. You found a tough nut to crack @jespertheend! I need more time to think about the ways we could try to tackle it.

@jespertheend
Copy link
Contributor Author

@bartlomieju Wait so does the code in my latest commit not reject the promise?
Because the console does print error: (in promise) undefined.

Would it be possible to attach a catch handler from rust and then get the stack from there?

@bartlomieju
Copy link
Member

@jespertheend it's rejecting a "floating promise" that you added - so it still doesn't point which promise did hang and there's this additional message:

This error was not caught from a test and caused the test runner to fail on the referenced module.
It most likely originated from a dangling promise, event/timeout handler or top-level code.

that is not really actionable here.

Would it be possible to attach a catch handler from rust and then get the stack from there?

That's the problem - it looks like we can't do that since we only have access to v8::Promise and not v8::PromiseResolver

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants