Special handling for printing out Error object #9

Merged
merged 1 commit into from Nov 7, 2012

Conversation

Projects
None yet
2 participants
Contributor

tikonen commented Oct 28, 2012

Node.js Error objects have their own special toString output. Use that instead of trying to process it as objects.

Owner

maritz commented Nov 4, 2012

Hm, can you give me a usecase for this? I'm not actually using this myself anymore, so I'm not really invested in it. But if you can show me some example output of previous/after, I'll probably merge it.

P.S.: Sorry for the late reply.

Contributor

tikonen commented Nov 6, 2012

This is needed to prevent accidentally hiding of Error objects and always print them out following Node error convention.

> util.inspect(new Error("This is a test"))
'[Error: This is a test]'

> sprintf.sprintf("Something went wrong %s", new Error("This is a test"))
'Something went wrong Error: This is a test'
> s.sprintf("Something went wrong %O", new Error("This is a test"))
'Something went wrong [Error: This is a test]'

Without this change the result would be following

> sprintf.sprintf("Something went wrong %s", new Error("This is a test"))
'Something went wrong Error: This is a test'
> sprintf.sprintf("Something went wrong %O", new Error("This is a test"))
'Something went wrong {}'

Error is reduced to empty object in that case. This is bigger problem if error is value of property of some more complicated object.

> var result = { result: 0, wrappedError: new Error("DB connection failed") }
> sprintf.sprintf("Something went wrong %O", result)
'Something went wrong {result: 0, wrappedError: {}}'

maritz added a commit that referenced this pull request Nov 7, 2012

Merge pull request #9 from tikonen/master
Special handling for printing out Error object

@maritz maritz merged commit 53cdb21 into maritz:master Nov 7, 2012

Owner

maritz commented Nov 7, 2012

Thanks. :)

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