diff --git a/lib/internal/errors.js b/lib/internal/errors.js index 56cb13f1cbeafc..8fa56e315e6a1a 100644 --- a/lib/internal/errors.js +++ b/lib/internal/errors.js @@ -582,7 +582,7 @@ function isStackOverflowError(err) { } } - return err.name === maxStack_ErrorName && + return err && err.name === maxStack_ErrorName && err.message === maxStack_ErrorMessage; } diff --git a/test/parallel/test-console-log-throw-primitive.js b/test/parallel/test-console-log-throw-primitive.js new file mode 100644 index 00000000000000..a1a9ca25726ab9 --- /dev/null +++ b/test/parallel/test-console-log-throw-primitive.js @@ -0,0 +1,14 @@ +'use strict'; +require('../common'); +const { Writable } = require('stream'); +const { Console } = require('console'); + +const stream = new Writable({ + write() { + throw null; // eslint-disable-line no-throw-literal + } +}); + +const console = new Console({ stdout: stream }); + +console.log('test'); // Should not throw