Skip to content

Conversation

@dbmikus
Copy link

@dbmikus dbmikus commented Dec 15, 2014

Do not log object properties that are functions and try JSON.stringify before checking for undefined.

Standard Bunyan pretty-printing (with the CLI tool) does not include properties that are functions in its output. Also, JSON.stringify will return undefined if it cannot figure out what to do with its argument, so calling stringify before checking if a value is undefined ensures that we always handle undefined values properly.

As an example (although this is handled by explicitly checking for typeof function):

var fn = function () { return 'foo'; };
var value = JSON.stringify(fn, null, 2);
value.indexOf(value); // this throws an exception because value is undefined

This reordering of if statements guarantees we don't call indexOf on something undefined.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.06%) when pulling 26d6dce on dbmikus:master into 3be44f0 on mrrama:master.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants