Skip to content

Commit 6b89512

Browse files
Shobhit ChittoraBridgeAR
Shobhit Chittora
authored andcommitted
bootstrap: add exception handling for profiler bootstrap
Add exception handling for the case when profile is not bootstrapped when coverage is enabled. Fixes: #29542 PR-URL: #29552 Reviewed-By: Joyee Cheung <[email protected]> Reviewed-By: Anna Henningsen <[email protected]>
1 parent 3878e1e commit 6b89512

File tree

3 files changed

+41
-2
lines changed

3 files changed

+41
-2
lines changed

lib/internal/bootstrap/pre_execution.js

+10-2
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,16 @@ function setupCoverageHooks(dir) {
120120
const { resolve } = require('path');
121121
const coverageDirectory = resolve(cwd, dir);
122122
const { sourceMapCacheToObject } = require('internal/source_map');
123-
internalBinding('profiler').setCoverageDirectory(coverageDirectory);
124-
internalBinding('profiler').setSourceMapCacheGetter(sourceMapCacheToObject);
123+
124+
if (process.features.inspector) {
125+
internalBinding('profiler').setCoverageDirectory(coverageDirectory);
126+
internalBinding('profiler').setSourceMapCacheGetter(sourceMapCacheToObject);
127+
} else {
128+
process.emitWarning('The inspector is disabled, ' +
129+
'coverage could not be collected',
130+
'Warning');
131+
return '';
132+
}
125133
return coverageDirectory;
126134
}
127135

test/common/index.js

+7
Original file line numberDiff line numberDiff line change
@@ -651,6 +651,12 @@ function skipIfInspectorDisabled() {
651651
}
652652
}
653653

654+
function skipIfInspectorEnabled() {
655+
if (process.features.inspector) {
656+
skip('V8 inspector is enabled');
657+
}
658+
}
659+
654660
function skipIfReportDisabled() {
655661
if (!process.config.variables.node_report) {
656662
skip('Diagnostic reporting is disabled');
@@ -783,6 +789,7 @@ module.exports = {
783789
skipIf32Bits,
784790
skipIfEslintMissing,
785791
skipIfInspectorDisabled,
792+
skipIfInspectorEnabled,
786793
skipIfReportDisabled,
787794
skipIfWorker,
788795

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
'use strict';
2+
3+
const common = require('../common');
4+
common.skipIfInspectorEnabled();
5+
6+
const fixtures = require('../common/fixtures');
7+
const assert = require('assert');
8+
const { spawnSync } = require('child_process');
9+
const env = { ...process.env, NODE_V8_COVERAGE: '/foo/bar' };
10+
const childPath = fixtures.path('v8-coverage/subprocess');
11+
const { status, stderr } = spawnSync(
12+
process.execPath,
13+
[childPath],
14+
{ env }
15+
);
16+
17+
const warningMessage = 'The inspector is disabled, ' +
18+
'coverage could not be collected';
19+
20+
assert.strictEqual(status, 0);
21+
assert.strictEqual(
22+
stderr.toString().includes(`Warning: ${warningMessage}`),
23+
true
24+
);

0 commit comments

Comments
 (0)