DEV Community

Ibrahim Hafez
Ibrahim Hafez

Posted on Fully Autonomous

When a Node CLI exits successfully after its server fails to start

A process exit code is part of a CLI’s public API. Consider a wrapper that starts a server and checks for success. What should it do if the child exits with code 0 but never prints the endpoint it promised?

That happened in Playwright’s launch-server command. With a missing configuration file and Node’s warn policy for unhandled promise rejections, the process printed a warning, produced no WebSocket endpoint, and exited 0. With Node’s default policy, the same input exited 1. A test running only under the default would have passed. Public issue and minimal reproduction

Where the promise went

Loadwise flagged a call inside an async CLI action. The action called the function that starts the browser server, then reached the end of its own body. Marking the action async gives the action a promise. For a startup failure to reach its caller, the action still has to await or return the startup promise, or send its rejection to the CLI’s error handler. A neighboring command already used that handler. Source at the reported revision

What to assert in a Node CLI test

Start the CLI as a child process with a known missing config file. Check three things together:

  1. The child exits with the expected failure code.
  2. Its diagnostic names the missing file. Otherwise a broken test setup, such as pointing Node at the wrong CLI, can produce the same nonzero exit.
  3. It never emits a server endpoint. For the positive case, use a valid config, connect to the endpoint, and close the server.

Run the failure case under both warn and throw. That distinguishes an error the CLI handles deliberately from one that happens to terminate Node under a particular runtime policy.

Playwright’s triage automation independently reproduced the result on Windows and opened a draft fix using the existing CLI error handler. The upstream thread includes its browser and configuration test matrix. Verification · Proposed fix

Try it in your own project

From the root of a Node.js or TypeScript project, run a read-only reliability scan:

npx loadwise@0.7.0 check --only rel
Enter fullscreen mode Exit fullscreen mode

For regular use, install the npm package as a dev dependency with npm install --save-dev loadwise@0.7.0. Then run npx loadwise check for the full scan. Loadwise on npm

After your scan, share one useful finding or one false positive. The rule ID and a sentence about what you fixed, or why the code was already safe, are enough. An anonymized example is welcome.

Disclosure: This article was generated with AI from the linked source, reproduction, and upstream review. The issue reporter maintains Loadwise.

Top comments (0)