Permalink
Browse files

util: fix exception stringification in .format()

Fixes #1634.
  • Loading branch information...
1 parent 3efebbe commit 72920231067107780abc7bf03ff6df0bb027821e @bnoordhuis committed Sep 3, 2011
Showing with 9 additions and 1 deletion.
  1. +9 −1 lib/util.js
View
@@ -164,14 +164,16 @@ function inspect(obj, showHidden, depth, colors) {
case 'boolean':
return stylize('' + value, 'boolean');
}
+
// For some reason typeof null is "object", so special case here.
if (value === null) {
return stylize('null', 'null');
}
// Look up the keys of the object.
var visible_keys = Object.keys(value);
- var keys = showHidden ? Object.getOwnPropertyNames(value) : visible_keys;
+ var keys = showHidden || isException(value) ?
+ Object.getOwnPropertyNames(value) : visible_keys;
// Functions without properties can be shortcutted.
if (typeof value === 'function' && keys.length === 0) {
@@ -337,6 +339,12 @@ function isDate(d) {
}
+function isException(e) {
+ return e instanceof Error ||
+ (typeof e === 'object' && Object.prototype.toString.call(e) === '[object Error]');
+}
+
+
var pWarning;
exports.p = function() {

0 comments on commit 7292023

Please sign in to comment.