Skip to content
Open
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
2 changes: 1 addition & 1 deletion lib/err-with-cause.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ function errWithCauseSerializer (err) {
_err.cause = errWithCauseSerializer(err.cause)
}

for (const key in err) {
for (const key of Object.keys(err)) {
if (_err[key] === undefined) {
const val = err[key]
if (isErrorLike(val)) {
Expand Down
2 changes: 1 addition & 1 deletion lib/err.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ function errSerializer (err) {
_err.aggregateErrors = err.errors.map(err => errSerializer(err))
}

for (const key in err) {
for (const key of Object.keys(err)) {
if (_err[key] === undefined) {
const val = err[key]
if (isErrorLike(val)) {
Expand Down
12 changes: 12 additions & 0 deletions test/err-with-cause.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,18 @@ test('serializes Error objects with extra properties', () => {
assert.match(serialized.stack, /err-with-cause\.test\.js:/)
})

test('does not serialize inherited enumerable properties', () => {
class ProtoError extends Error {}
ProtoError.prototype.protoValue = 'proto'

const err = new ProtoError('foo')
err.ownValue = 'own'

const serialized = serializer(err)
assert.strictEqual(serialized.ownValue, 'own')
assert.ok(!Object.prototype.hasOwnProperty.call(serialized, 'protoValue'))
})

test('serializes Error objects with subclass "type"', () => {
class MyError extends Error {}

Expand Down
12 changes: 12 additions & 0 deletions test/err.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,18 @@ test('serializes Error objects with extra properties', () => {
assert.match(serialized.stack, /err\.test\.js:/)
})

test('does not serialize inherited enumerable properties', () => {
class ProtoError extends Error {}
ProtoError.prototype.protoValue = 'proto'

const err = new ProtoError('foo')
err.ownValue = 'own'

const serialized = serializer(err)
assert.strictEqual(serialized.ownValue, 'own')
assert.ok(!Object.prototype.hasOwnProperty.call(serialized, 'protoValue'))
})

test('serializes Error objects with subclass "type"', () => {
class MyError extends Error {}
const err = new MyError('foo')
Expand Down
Loading