Some of the example code in the AWS Javascript SDK docs log the stack of an error separately to the error itself, for example this is from the AWS.CloudWatch
overview:
var cloudwatch = new AWS.CloudWatch();
cloudwatch.getMetricWidgetImage(params, function (err, data) {
if (err) console.log(err, err.stack); // an error occurred
else console.log(data); // successful response
});
So far as I can tell, this is redundant in Node (I have only tested on v10.16). If I log just the error object, it includes the stack trace:
> console.log(e)
Error: x
at repl:2:8
at Script.runInThisContext (vm.js:122:20)
at REPLServer.defaultEval (repl.js:332:29)
at bound (domain.js:402:14)
at REPLServer.runBound [as eval] (domain.js:415:12)
at REPLServer.onLine (repl.js:642:10)
at REPLServer.emit (events.js:198:13)
at REPLServer.EventEmitter.emit (domain.js:448:20)
at REPLServer.Interface._onLine (readline.js:308:10)
at REPLServer.Interface._normalWrite (readline.js:451:12)
undefined
Whereas if I log both, as Amazon have done above, I get an ugly ouput with duplication:
> console.log(e, e.stack)
Error: x
at repl:2:8
at Script.runInThisContext (vm.js:122:20)
at REPLServer.defaultEval (repl.js:332:29)
at bound (domain.js:402:14)
at REPLServer.runBound [as eval] (domain.js:415:12)
at REPLServer.onLine (repl.js:642:10)
at REPLServer.emit (events.js:198:13)
at REPLServer.EventEmitter.emit (domain.js:448:20)
at REPLServer.Interface._onLine (readline.js:308:10)
at REPLServer.Interface._normalWrite (readline.js:451:12) 'Error: x\n at repl:2:8\n at Script.runInThisContext (vm.js:122:20)\n at REPLServer.defaultEval (repl.js:332:29)\n at bound (domain.js:402:14)\n at REPLServer.runBound [as eval] (domain.js:415:12)\n at REPLServer.onLine (repl.js:642:10)\n at REPLServer.emit (events.js:198:13)\n at REPLServer.EventEmitter.emit (domain.js:448:20)\n at REPLServer.Interface._onLine (readline.js:308:10)\n at REPLServer.Interface._normalWrite (readline.js:451:12)'
undefined
Is there some reason that Amazon are using the console.log(err, err.stack)
pattern that I am missing if I just do console.log(err)
?
(I am primarily using Node in an AWS Lambda, version 10.x)