From 2581fce55303d5382efc091de5073b8b967239a2 Mon Sep 17 00:00:00 2001 From: Joyee Cheung Date: Sun, 10 Dec 2023 09:50:08 +0100 Subject: [PATCH] bootstrap: improve snapshot unsupported builtin warnings MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 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: https://github.com/nodejs/node/pull/50944 Reviewed-By: Vinícius Lourenço Claro Cardoso Reviewed-By: Antoine du Hamel Reviewed-By: Luigi Pinca Reviewed-By: James M Snell --- lib/internal/main/mksnapshot.js | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/lib/internal/main/mksnapshot.js b/lib/internal/main/mksnapshot.js index 34701716839326..f00bf886153e6e 100644 --- a/lib/internal/main/mksnapshot.js +++ b/lib/internal/main/mksnapshot.js @@ -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'); @@ -29,6 +29,7 @@ const { namespace: { addSerializeCallback, addDeserializeCallback, + isBuildingSnapshot, }, } = require('internal/v8/startup_snapshot'); @@ -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); } }