Skip to content

Commit 93a01d6

Browse files
committed
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).
1 parent 2bdeb88 commit 93a01d6

File tree

4 files changed

+39
-2
lines changed

4 files changed

+39
-2
lines changed

lib/internal/modules/cjs/loader.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1091,14 +1091,17 @@ Module.prototype._compile = function(content, filename) {
10911091
if (!resolvedArgv) {
10921092
// We enter the repl if we're not given a filename argument.
10931093
if (process.argv[1]) {
1094-
resolvedArgv = Module._resolveFilename(process.argv[1], null, false);
1094+
// The resolution may fail if it requires a preload script
1095+
try {
1096+
resolvedArgv = Module._resolveFilename(process.argv[1], null, false);
1097+
} catch {}
10951098
} else {
10961099
resolvedArgv = 'repl';
10971100
}
10981101
}
10991102

11001103
// Set breakpoint on module start
1101-
if (!hasPausedEntry && filename === resolvedArgv) {
1104+
if (resolvedArgv && !hasPausedEntry && filename === resolvedArgv) {
11021105
hasPausedEntry = true;
11031106
inspectorWrapper = internalBinding('inspector').callAndPauseOnStart;
11041107
}

test/fixtures/test-resolution-inspect-brk-main.ext

Whitespace-only changes.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
'use strict';
2+
// eslint-disable-next-line no-unused-vars
3+
const common = require('../common');
4+
5+
require.extensions['.ext'] = require.extensions['.js'];
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
'use strict';
2+
const common = require('../common');
3+
common.skipIfInspectorDisabled();
4+
5+
// A test to ensure that preload modules are given a chance to execute before
6+
// resolving the main entry point with --inspect-brk active.
7+
8+
const assert = require('assert');
9+
const cp = require('child_process');
10+
const path = require('path');
11+
12+
function test(execArgv) {
13+
const child = cp.spawn(process.execPath, execArgv);
14+
15+
child.stderr.once('data', common.mustCall(function() {
16+
child.kill('SIGTERM');
17+
}));
18+
19+
child.on('exit', common.mustCall(function(code, signal) {
20+
assert.strictEqual(signal, 'SIGTERM');
21+
}));
22+
}
23+
24+
test([
25+
'--require',
26+
path.join(__dirname, '../fixtures/test-resolution-inspect-brk-resolver.js'),
27+
'--inspect-brk',
28+
'../fixtures/test-resolution-inspect-resolver-main.ext',
29+
]);

0 commit comments

Comments
 (0)