Skip to content
This repository was archived by the owner on Apr 22, 2023. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,8 @@ function isDate(d) {
exports.isDate = isDate;

function isError(e) {
return isObject(e) && objectToString(e) === '[object Error]';
return isObject(e) &&
(objectToString(e) === '[object Error]' || e instanceof Error);
}
exports.isError = isError;

Expand Down
10 changes: 10 additions & 0 deletions test/simple/test-util-format.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,13 @@ assert.equal(util.format('%%%s%%%%', 'hi'), '%hi%%');
o.o = o;
assert.equal(util.format('%j', o), '[Circular]');
})();

// Errors
assert.equal(util.format(new Error('foo')), '[Error: foo]');
function CustomError(msg) {
Error.call(this);
Object.defineProperty(this, 'message', { value: msg, enumerable: false });
Object.defineProperty(this, 'name', { value: 'CustomError', enumerable: false });
}
util.inherits(CustomError, Error);
assert.equal(util.format(new CustomError('bar')), '[CustomError: bar]');
2 changes: 1 addition & 1 deletion test/simple/test-util.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ assert.equal(true, util.isError(new (context('SyntaxError'))));
assert.equal(false, util.isError({}));
assert.equal(false, util.isError({ name: 'Error', message: '' }));
assert.equal(false, util.isError([]));
assert.equal(false, util.isError(Object.create(Error.prototype)));
assert.equal(true, util.isError(Object.create(Error.prototype)));

// isObject
assert.ok(util.isObject({}) === true);
Expand Down