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

Unknown Fatal Error if code is not an int #5517

Open
bevand10 opened this issue May 15, 2024 · 0 comments
Open

Unknown Fatal Error if code is not an int #5517

bevand10 opened this issue May 15, 2024 · 0 comments

Comments

@bevand10
Copy link

if (code) process.exit(code);

Given the input value to this function (code) is not always an int, this line fails but does not report a true/underlying error reason to the user.

I had a scenario where my OS ran out of watcher capacity. That caused the input to the exit function to not be a number:

Sending the received value (code) to process.exit causes this error:

TypeError: The "code" argument must be of type number. Received an instance of Error
    at process.set [as exitCode] (node:internal/bootstrap/node:123:9)
    at process.exit (node:internal/process/per_thread:188:24)
    at process.close (.../node_modules/rollup/dist/shared/watch-cli.js:505:23)
    at process.emit (node:events:514:28)
    at process.emit (.../node_modules/source-map-support/source-map-support.js:516:21)
    at processEmit [as emit] (.../node_modules/rollup/dist/shared/watch-cli.js:336:34)
    at process._fatalException (node:internal/process/execution:159:25)
    at processPromiseRejections (node:internal/process/promises:289:13)
    at processTicksAndRejections (node:internal/process/task_queues:96:32)

Here's the full function:

async function close(code: number | null | undefined): Promise<void> {
		process.removeListener('uncaughtException', closeWithError);
		// removing a non-existent listener is a no-op
		process.stdin.removeListener('end', close);

		if (watcher) await watcher.close();
		if (configWatcher) configWatcher.close();
		if (code) process.exit(code);
	}

In my case, the code value passed to the function is an Error object (as alluded to in the error message), not a number, not null and not undefined:

{
  "errno": -28,
  "syscall": "watch",
  "code": "ENOSPC",
  "path": "/home/me/mydir/rollup.config.js",
  "filename": "/home/me/mydir/rollup.config.js"
}

When I added console.error(code) to debug the scenario (I hacked node_modules/rollup/dist/shared/watch-cli.js), the message emitted was converted to a string by Error.toString(), to:

Error: ENOSPC: System limit for number of file watchers reached, watch '/home/me/mydir/rollup.config.js'

That of course revealed the true problem I had/have, but the default error stack/messaging did not, as the Error object was being type-converted to a string before dispatch to process.exit, thus hiding the actual fault.

@bevand10 bevand10 changed the title Fatal Error if code is not an int Unknown Fatal Error if code is not an int May 15, 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

1 participant