module: ignore resolution failures for inspect-brk

The resolution for the main entry point may fail when the resolution
requires a preloaded module to be executed first (for example when
adding new extensions to the resolution process). Silently skipping
such failures allow us to defer the resolution as long as needed
without having any adverse change (since the main entry point won't
resolve anyway if it really can't be resolved at all).

PR-URL: https://github.com/nodejs/node/pull/30336
Reviewed-By: Guy Bedford <guybedford@gmail.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
pull/30775/head
Maël Nison 2019-11-08 18:38:26 +01:00 committed by Guy Bedford
parent 81ac3023b3
commit 1549c8e077
4 changed files with 42 additions and 2 deletions

View File

@ -1164,14 +1164,20 @@ Module.prototype._compile = function(content, filename) {
if (!resolvedArgv) {
// We enter the repl if we're not given a filename argument.
if (process.argv[1]) {
resolvedArgv = Module._resolveFilename(process.argv[1], null, false);
try {
resolvedArgv = Module._resolveFilename(process.argv[1], null, false);
} catch {
// We only expect this codepath to be reached in the case of a
// preloaded module (it will fail earlier with the main entry)
assert(Array.isArray(getOptionValue('--require')));
}
} else {
resolvedArgv = 'repl';
}
}
// Set breakpoint on module start
if (!hasPausedEntry && filename === resolvedArgv) {
if (resolvedArgv && !hasPausedEntry && filename === resolvedArgv) {
hasPausedEntry = true;
inspectorWrapper = internalBinding('inspector').callAndPauseOnStart;
}

View File

@ -0,0 +1,5 @@
'use strict';
// eslint-disable-next-line no-unused-vars
const common = require('../common');
require.extensions['.ext'] = require.extensions['.js'];

View File

@ -0,0 +1,29 @@
'use strict';
const common = require('../common');
common.skipIfInspectorDisabled();
// A test to ensure that preload modules are given a chance to execute before
// resolving the main entry point with --inspect-brk active.
const assert = require('assert');
const cp = require('child_process');
const path = require('path');
function test(execArgv) {
const child = cp.spawn(process.execPath, execArgv);
child.stderr.once('data', common.mustCall(function() {
child.kill('SIGTERM');
}));
child.on('exit', common.mustCall(function(code, signal) {
assert.strictEqual(signal, 'SIGTERM');
}));
}
test([
'--require',
path.join(__dirname, '../fixtures/test-resolution-inspect-brk-resolver.js'),
'--inspect-brk',
'../fixtures/test-resolution-inspect-resolver-main.ext',
]);