Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Never serialize .cause Errors, rely on message + stack summary instead #110

Merged
merged 5 commits into from
Jun 13, 2022
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Add tests
voxpelli committed Jun 13, 2022
commit d848f45c82c7c858a13bf064ba313d2b799d5478
18 changes: 15 additions & 3 deletions test/err.test.js
Original file line number Diff line number Diff line change
@@ -47,7 +47,7 @@ test('serializes nested errors', function (t) {
})

test('serializes error causes', function (t) {
t.plan(6)
t.plan(7)
const err = Error('foo')
err.cause = Error('bar')
err.cause.cause = Error('abc')
@@ -58,15 +58,17 @@ test('serializes error causes', function (t) {
t.match(serialized.stack, /Error: foo/)
t.match(serialized.stack, /Error: bar/)
t.match(serialized.stack, /Error: abc/)
t.notOk(serialized.cause)
})

test('serializes error causes with VError support', function (t) {
t.plan(6)
// Fake VError-style setup
const err = Error('foo: bar')
err.cause = () => {
err.foo = 'abc'
err.cause = function () {
const err = Error('bar')
err.cause = Error('abc')
err.cause = Error(this.foo)
return err
}
const serialized = serializer(err)
@@ -78,6 +80,16 @@ test('serializes error causes with VError support', function (t) {
t.match(serialized.stack, /Error: abc/)
})

test('keeps non-error cause', function (t) {
t.plan(3)
const err = Error('foo')
err.cause = 'abc'
const serialized = serializer(err)
t.equal(serialized.type, 'Error')
t.equal(serialized.message, 'foo')
t.equal(serialized.cause, 'abc')
})

test('prevents infinite recursion', function (t) {
t.plan(4)
const err = Error('foo')