Skip to content

RFC: Add Deno.exitCode support #23605

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

Closed
lukeed opened this issue Apr 29, 2024 · 5 comments
Closed

RFC: Add Deno.exitCode support #23605

lukeed opened this issue Apr 29, 2024 · 5 comments

Comments

@lukeed
Copy link
Contributor

lukeed commented Apr 29, 2024

Support a new Deno.exitCode API that allows user to define the would-be exitcode of the process w/o necessarily forcing an exit that instant (liek Deno.exit())

This is ideal for tasks that, on error condition, will want to exit as non-healthy but still need to perform some async cleanup tasks before actually exiting.

See process.exitCode from Node

@lukeed
Copy link
Contributor Author

lukeed commented Apr 29, 2024

Not sure, but my first guess would be that the setter would just have to call into https://github.com/denoland/deno/blob/783533d2e354ad73356d7517b26293e48c10fc17/runtime/js/30_os.js#L76C5-L76C21

@lukeed
Copy link
Contributor Author

lukeed commented Apr 29, 2024

Because the runtime/js/30_os.js file is ESM, we can't actually match the same exitCode getter/setter API without converting all the exports into an object & then exporting that object as the default

I don't think that's desired, so instead I'm going to propose that we do this instead:

Deno.exit(); // unchanged
Deno.exit.code; //-> number | undefined
Deno.exit.code = 1; //-> void

@Leokuma
Copy link

Leokuma commented May 1, 2024

At first I found it confusing to have Deno.exit as both a function and a setter bag, but after thinking about alternatives, I actually like it.

I'm just afraid that users will miss that exit can have its options set like that, because I don't think we have precedent for that "API style". Still I'm in favor of this. If we encounter a similar need in the future, we could use the same pattern.

bartlomieju added a commit that referenced this issue May 29, 2024
This commits adds the ability to set a would-be exit code 
for the Deno process without forcing an immediate exit, 
through the new `Deno.exitCode` API.

- **Implements `Deno.exitCode` getter and setter**: Adds support for
setting
and retrieving a would-be exit code via `Deno.exitCode`.
This allows for asynchronous cleanup before process termination 
without immediately exiting.
- **Ensures type safety**: The setter for `Deno.exitCode` validates that
the provided value is a number, throwing a TypeError if not, to ensure
that
only valid exit codes are set.

Closes to #23605

---------

Co-authored-by: Bartek Iwańczuk <[email protected]>
@Leokuma
Copy link

Leokuma commented May 30, 2024

I think this can be closed now.

@lukeed
Copy link
Contributor Author

lukeed commented May 30, 2024

Closed by #23609

@lukeed lukeed closed this as completed May 30, 2024
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

No branches or pull requests

2 participants