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

Return an exit code on "unload" #9201

Closed
oscarotero opened this issue Jan 20, 2021 · 2 comments · Fixed by #9207
Closed

Return an exit code on "unload" #9201

oscarotero opened this issue Jan 20, 2021 · 2 comments · Fixed by #9207
Labels
bug Something isn't working correctly cli related to cli/ dir

Comments

@oscarotero
Copy link
Contributor

oscarotero commented Jan 20, 2021

Hi.
I have a function that execute some stuff. And I want to return different exit codes, depending on the result of this execution. Something like this:

const success = await run();
Deno.exit(success ? 0 : 1);

Sometimes is impossible to know when run() finished (because there may be async functions that don't return a promise), so Deno.exit() can break the execution of some things inside run(). To prevent that, I fixed it with this code:

const success = await run();
window.addEventListener("unload", () => Deno.exit(success ? 0 : 1));

This ensures that only after finish all process, subprocess, etc inside run(), the proper exit code is returned.

After upgrading to Deno 1.7 I'm getting the following error: error: Uncaught RangeError: Maximum call stack size exceeded. I guess this is because #9088, so Deno.exit() dispatches unload event that executed Deno.exit() that dispatches unload and so on.

To prevent this, I think unload should be triggered only once. Or if there's any other way to set an exit code without using Deno.exit(), that would be fine too.

@ghost
Copy link

ghost commented Jan 20, 2021

The unload event should only be fired once, I think that's a bug.

@kitsonk kitsonk added bug Something isn't working correctly cli related to cli/ dir labels Jan 20, 2021
@kitsonk
Copy link
Contributor

kitsonk commented Jan 20, 2021

It should only fire once. We should hold on to a global reference for the event when it is raised and not raise it again if present.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working correctly cli related to cli/ dir
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants