Skip to content

Commit

Permalink
fix: topLevelFields should not serialize known VError proto fields (#91)
Browse files Browse the repository at this point in the history
  • Loading branch information
DonutEspresso authored Jun 19, 2018
1 parent 6901132 commit 3060c9c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/serializer.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,9 @@ ErrorSerializer.prototype._findKnownFields = function _findKnownFields() {
var verr = new verror.VError();
var multiErr = new verror.MultiError([ verr ]);
fields.push(_.keys(verr));
fields.push(_.keys(Object.getPrototypeOf(verr)));
fields.push(_.keys(multiErr));
fields.push(_.keys(Object.getPrototypeOf(multiErr)));

return _(fields).flatten().uniq().value();
};
Expand Down
18 changes: 18 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -965,5 +965,23 @@ describe('restify-errors node module.', function() {
var serializedErr = serializer.err(err1, 'oh noes!');
assert.notInclude(serializedErr.stack, 'espresso=normale');
});

it('should not serialize known fields on VError', function() {
var serializer = restifyErrors.bunyanSerializer.create({
topLevelFields: true
});
var err1 = new verror.VError({
name: 'VErrorInfo',
info: {
espresso: 'ristretto'
}
}, 'pull!');
err1.espresso = 'lungo';

logger.child({ serializers: serializer }).error(err1);

var serializedErr = serializer.err(err1, 'oh noes!');
assert.notInclude(serializedErr.stack, 'cause=undefined');
});
});
});

0 comments on commit 3060c9c

Please sign in to comment.