deno icon indicating copy to clipboard operation
deno copied to clipboard

RFC: Add `Deno.exitCode` support

Open lukeed opened this issue 1 year ago • 3 comments

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 avatar Apr 29 '24 22:04 lukeed

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 avatar Apr 29 '24 22:04 lukeed

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

lukeed avatar Apr 29 '24 23:04 lukeed

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.

Leokuma avatar May 01 '24 17:05 Leokuma

I think this can be closed now.

Leokuma avatar May 30 '24 16:05 Leokuma

Closed by #23609

lukeed avatar May 30 '24 17:05 lukeed