Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

util: fix exception stringification in .format()

Fixes #1634.
  • Loading branch information...
commit 72920231067107780abc7bf03ff6df0bb027821e 1 parent 3efebbe
Ben Noordhuis authored September 03, 2011

Showing 1 changed file with 9 additions and 1 deletion. Show diff stats Hide diff stats

  1. 10  lib/util.js
10  lib/util.js
@@ -164,6 +164,7 @@ function inspect(obj, showHidden, depth, colors) {
164 164
       case 'boolean':
165 165
         return stylize('' + value, 'boolean');
166 166
     }
  167
+
167 168
     // For some reason typeof null is "object", so special case here.
168 169
     if (value === null) {
169 170
       return stylize('null', 'null');
@@ -171,7 +172,8 @@ function inspect(obj, showHidden, depth, colors) {
171 172
 
172 173
     // Look up the keys of the object.
173 174
     var visible_keys = Object.keys(value);
174  
-    var keys = showHidden ? Object.getOwnPropertyNames(value) : visible_keys;
  175
+    var keys = showHidden || isException(value) ?
  176
+        Object.getOwnPropertyNames(value) : visible_keys;
175 177
 
176 178
     // Functions without properties can be shortcutted.
177 179
     if (typeof value === 'function' && keys.length === 0) {
@@ -337,6 +339,12 @@ function isDate(d) {
337 339
 }
338 340
 
339 341
 
  342
+function isException(e) {
  343
+  return e instanceof Error ||
  344
+    (typeof e === 'object' && Object.prototype.toString.call(e) === '[object Error]');
  345
+}
  346
+
  347
+
340 348
 var pWarning;
341 349
 
342 350
 exports.p = function() {

0 notes on commit 7292023

Please sign in to comment.
Something went wrong with that request. Please try again.