diff --git a/lib/util.js b/lib/util.js index f47e39fddda..3161f7e3be2 100644 --- a/lib/util.js +++ b/lib/util.js @@ -144,7 +144,7 @@ function inspect(obj, showHidden, depth, colors) { value !== exports && // Also filter out any prototype objects using the circular check. !(value.constructor && value.constructor.prototype === value)) { - return value.inspect(recurseTimes); + return '' + value.inspect(recurseTimes); } // Primitive types cannot have properties diff --git a/test/simple/test-util-inspect.js b/test/simple/test-util-inspect.js index 717182f88de..b929caec5f2 100644 --- a/test/simple/test-util-inspect.js +++ b/test/simple/test-util-inspect.js @@ -33,3 +33,11 @@ var orig = util.inspect(d); Date2.prototype.foo = 'bar'; var after = util.inspect(d); assert.equal(orig, after); + +// .inspect() function that returns a non-string +// should not trigger an exception +// https://github.com/joyent/node/issues/410 +var o = { + inspect: function() {} +}; +assert.equal(util.inspect(o), 'undefined'); \ No newline at end of file