Skip to content

Commit

Permalink
bootstrap: improve snapshot unsupported builtin warnings
Browse files Browse the repository at this point in the history
- Only emit warning when the snapshot is built. In general built-ins
  loaded after the snapshot is built should work as usual.
- Clarify what the warning means

PR-URL: #50944
Reviewed-By: Vinícius Lourenço Claro Cardoso <[email protected]>
Reviewed-By: Antoine du Hamel <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: James M Snell <[email protected]>
  • Loading branch information
joyeecheung authored and RafaelGSS committed Dec 15, 2023
1 parent fc55032 commit 2581fce
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions lib/internal/main/mksnapshot.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const {
const { isExperimentalSeaWarningNeeded } = internalBinding('sea');

const { emitExperimentalWarning } = require('internal/util');

const { emitWarningSync } = require('internal/process/warning');
const {
getOptionValue,
} = require('internal/options');
Expand All @@ -29,6 +29,7 @@ const {
namespace: {
addSerializeCallback,
addDeserializeCallback,
isBuildingSnapshot,
},
} = require('internal/v8/startup_snapshot');

Expand Down Expand Up @@ -119,10 +120,18 @@ function requireForUserSnapshot(id) {
err.code = 'MODULE_NOT_FOUND';
throw err;
}
if (!supportedInUserSnapshot(normalizedId)) {
if (isBuildingSnapshot() && !supportedInUserSnapshot(normalizedId)) {
if (!warnedModules.has(normalizedId)) {
process.emitWarning(
`built-in module ${id} is not yet supported in user snapshots`);
// Emit the warning synchronously in case we don't get to process
// the tick and print it before the unsupported built-in causes a
// crash.
emitWarningSync(
`It's not yet fully verified whether built-in module "${id}" ` +
'works in user snapshot builder scripts.\n' +
'It may still work in some cases, but in other cases certain ' +
'run-time states may be out-of-sync after snapshot deserialization.\n' +
'To request support for the module, use the Node.js issue tracker: ' +
'https://github.com/nodejs/node/issues');
warnedModules.add(normalizedId);
}
}
Expand Down

0 comments on commit 2581fce

Please sign in to comment.