Skip to content
This repository was archived by the owner on Feb 26, 2024. It is now read-only.

Commit b39cffb

Browse files
committed
research: add unhandledRejection warning
This is controversial, but I think our use case, and space requires erring on the side of caution. [See this discusion](nodejs/node#22822) for more perspective.
1 parent 0eb711e commit b39cffb

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

packages/core/lib/command.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,26 @@ class Command {
144144
version: bundled || "(unbundled) " + core
145145
});
146146

147+
const unhandledRejections = new Map();
148+
149+
process.on('unhandledRejection', (reason, promise) => {
150+
unhandledRejections.set(promise, reason);
151+
});
152+
153+
process.on('rejectionHandled', (promise) => {
154+
unhandledRejections.delete(promise);
155+
});
156+
157+
process.on('exit', (_) => {
158+
const log = options.logger ? (options.logger.log || options.logger.debug): console.log;
159+
if (unhandledRejections.size) {
160+
log('UnhandledRejections detected');
161+
unhandledRejections.forEach((reason, promise) => {
162+
log(promise, reason);
163+
});
164+
}
165+
});
166+
147167
return await result.command.run(newOptions);
148168
}
149169

0 commit comments

Comments
 (0)