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

module: do not use process.exit() #25769

Closed
wants to merge 3 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
squash! module: do not use process.exit()
  • Loading branch information
addaleax committed Jan 28, 2019
commit e941f85b8baf87756ed3f0aba7c26e17eac5f322
10 changes: 1 addition & 9 deletions lib/internal/modules/cjs/loader.js
Original file line number Diff line number Diff line change
@@ -60,14 +60,12 @@ module.exports = Module;
let asyncESM;
let ModuleJob;
let createDynamicModule;
let decorateErrorStack;

function lazyLoadESM() {
asyncESM = require('internal/process/esm_loader');
ModuleJob = require('internal/modules/esm/module_job');
createDynamicModule = require(
'internal/modules/esm/create_dynamic_module');
decorateErrorStack = require('internal/util').decorateErrorStack;
}

const {
@@ -794,13 +792,7 @@ Module.runMain = function() {
return loader.import(pathToFileURL(process.argv[1]).pathname);
})
.catch((e) => {
// TODO(addaleax): This should, ideally, trigger a fatal exception
// instead. That should alread be doable for code in core now, but it's
// probably easier to wait until something like
// https://github.com/nodejs/node/pull/25715 lands?
decorateErrorStack(e);
console.error(e);
process.exitCode = 1;
internalBinding('util').triggerFatalException(e);
});
} else {
Module._load(process.argv[1], null, true);
8 changes: 2 additions & 6 deletions test/parallel/test-worker-esm-missing-main.js
Original file line number Diff line number Diff line change
@@ -5,13 +5,9 @@ const { Worker } = require('worker_threads');

const worker = new Worker('./does-not-exist.js', {
execArgv: ['--experimental-modules'],
stderr: true
});

let stderr = '';
worker.stderr.setEncoding('utf8');
worker.stderr.on('data', (chunk) => stderr += chunk);
worker.stderr.on('end', common.mustCall(() => {
worker.on('error', common.mustCall((err) => {
// eslint-disable-next-line node-core/no-unescaped-regexp-dot
assert(/Cannot find module .+does-not-exist.js/.test(stderr), stderr);
assert(/Cannot find module .+does-not-exist.js/.test(err.message), err);
}));