mirror of
https://github.com/zebrajr/node.git
synced 2026-01-15 12:15:26 +00:00
console: make error handling engine agnostic
Calling write could throw a maximum call stack size error. To make sure this is not specific to a single engine (version), lazily populate the correct error message by producing such a error on demand. PR-URL: https://github.com/nodejs/node/pull/17707 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
@@ -28,6 +28,8 @@ const kCounts = Symbol('counts');
|
||||
// Track amount of indentation required via `console.group()`.
|
||||
const kGroupIndent = Symbol('groupIndent');
|
||||
|
||||
let MAX_STACK_MESSAGE;
|
||||
|
||||
function Console(stdout, stderr, ignoreErrors = true) {
|
||||
if (!(this instanceof Console)) {
|
||||
return new Console(stdout, stderr, ignoreErrors);
|
||||
@@ -111,9 +113,17 @@ function write(ignoreErrors, stream, string, errorhandler, groupIndent) {
|
||||
|
||||
stream.write(string, errorhandler);
|
||||
} catch (e) {
|
||||
if (MAX_STACK_MESSAGE === undefined) {
|
||||
try {
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
function a() { a(); }
|
||||
} catch (err) {
|
||||
MAX_STACK_MESSAGE = err.message;
|
||||
}
|
||||
}
|
||||
// console is a debugging utility, so it swallowing errors is not desirable
|
||||
// even in edge cases such as low stack space.
|
||||
if (e.message === 'Maximum call stack size exceeded')
|
||||
if (e.message === MAX_STACK_MESSAGE && e.name === 'RangeError')
|
||||
throw e;
|
||||
// Sorry, there’s no proper way to pass along the error here.
|
||||
} finally {
|
||||
|
||||
Reference in New Issue
Block a user