nodejs / nodejs/userland-migrations

process.exit(code) and process.exitCode coercion to integer

Open
#405 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

good first issue human help wanted let's do it
Dominant language
TypeScript
Stars
85
Forks
55
Avg merge
3d 11h
Merged PRs (30d)
9

Description

Description

Since passing non-integer values to process.exit(code) and process.exitCode is deprecated (DEP0164) and has reached End-of-Life status in Node.js v20.0.0, we should provide a codemod to replace them.

  • The codemod should convert non-integer values passed to process.exit() to proper integers or remove them.
  • The codemod should convert non-integer values assigned to process.exitCode to proper integers or undefined.
  • The codemod should preserve undefined, null, integer numbers, and integer strings (e.g., '1').
  • The codemod should add explicit integer conversion for floating-point numbers or other numeric values.

Additional Information

Note that in Node.js v20.0.0, passing values other than undefined, null, integer numbers, and integer strings to process.exit() or assigning them to process.exitCode now throws an ERR_INVALID_ARG_TYPE error.

Exit codes should always be integers between 0-255, where 0 indicates success and non-zero indicates an error. The automatic coercion of non-integer values was removed because it could lead to unexpected behavior.

Examples

Example 1: Boolean value in process.exit()

Before:

process.exit(true);

After:

process.exit(1); // true coerced to 1
Example 2: Boolean false in process.exit()

Before:

process.exit(false);

After:

process.exit(0); // false coerced to 0
Example 3: Floating-point number in process.exit()

Before:

process.exit(1.5);

After:

process.exit(Math.floor(1.5)); // Explicitly convert to integer: 1
Example 4: Object assigned to process.exitCode

Before:

process.exitCode = { code: 1 };

After:

process.exitCode = 1; // Extract the integer value
Example 5: String (non-integer) in process.exit()

Before:

process.exit("error");

After:

process.exit(1); // Use appropriate error code
Example 6: Conditional with boolean

Before:

const hasError = true;
process.exit(hasError);

After:

const hasError = true;
process.exit(hasError ? 1 : 0);
Example 7: process.exitCode with boolean

Before:

const success = false;
process.exitCode = success;

After:

const success = false;
process.exitCode = success ? 0 : 1;
Example 8: Valid integer string (no change needed)

Before:

process.exit("1");

After:

process.exit("1"); // Integer strings are still valid
Example 9: Valid values (no change needed)

Before:

process.exit(0);
process.exit(1);
process.exit(undefined);
process.exit(null);
process.exitCode = 0;
process.exitCode = undefined;

After:

process.exit(0);
process.exit(1);
process.exit(undefined);
process.exit(null);
process.exitCode = 0;
process.exitCode = undefined;
Example 10: Arithmetic expression

Before:

process.exit(0.5 + 0.7); // Results in 1.2

After:

process.exit(Math.floor(0.5 + 0.7)); // Explicitly convert to integer: 1

Refs

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the issue examples and read the linked DEP0164 documentation and Node.js pull request to confirm which values remain valid and how coercion should behave. Implement the codemod for process.exit() arguments and process.exitCode assignments, then verify that invalid values are converted or removed while the listed valid values remain unchanged.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, typescript
Domain
tooling
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.