Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Standard err serializer: better support for caused errors #200

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions lib/bunyan.js
Original file line number Diff line number Diff line change
Expand Up @@ -985,7 +985,7 @@ Logger.stdSerializers.res = function res(res) {

/*
* This function dumps long stack traces for exceptions having a cause()
* method. The error classes from
* method or a cause property. The error classes from
* [verror](https://github.com/davepacheco/node-verror) and
* [restify v2.0](https://github.com/mcavage/node-restify) are examples.
*
Expand All @@ -995,10 +995,16 @@ Logger.stdSerializers.res = function res(res) {
function getFullErrorStack(ex)
{
var ret = ex.stack || ex.toString();
if (ex.cause && typeof (ex.cause) === 'function') {
var cex = ex.cause();
if (ex.cause) {
var cex;
if (typeof (ex.cause) === 'function') {
cex = ex.cause();
}
if (typeof (ex.cause) === 'object') {
cex = ex.cause;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

perhaps else if here

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No problem, it could even be a switch statement.

}
if (cex) {
ret += '\nCaused by: ' + getFullErrorStack(cex);
ret += '\ncaused by ' + getFullErrorStack(cex);
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this change? How does this "integrate better with the default stack trace formatter"? I'm not familiar with the "default" stack trace formatting you are referring to.

Also, if we decide to keep this "caused by" change, there is at least one test case that will need to be updated.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The default V8 stack trace formatter, that's what I'm talking about.
The error name usually starts with a capital and is followed by :, thus my small change on the connector string (which should have a low profile).

}
return (ret);
Expand Down