pino-std-serializers
Advanced tools
Comparing version 5.4.0 to 5.5.0
@@ -15,19 +15,18 @@ 'use strict' | ||
/** @type {unknown} */ | ||
// @ts-ignore | ||
const cause = err.cause | ||
const cause = evaluateCause(err.cause) | ||
// VError / NError style causes | ||
if (typeof cause === 'function') { | ||
// @ts-ignore | ||
const causeResult = err.cause() | ||
return cause instanceof Error | ||
? cause | ||
: undefined | ||
} | ||
return causeResult instanceof Error | ||
? causeResult | ||
: undefined | ||
} else { | ||
return cause instanceof Error | ||
? cause | ||
: undefined | ||
} | ||
/** | ||
* @param {unknown|(()=>err)} cause | ||
* @returns {Error|undefined} | ||
*/ | ||
const evaluateCause = (cause) => { | ||
// VError / NError style causes are functions | ||
return typeof cause === 'function' | ||
? cause() | ||
: cause | ||
} | ||
@@ -112,4 +111,5 @@ | ||
getErrorCause, | ||
evaluateCause, | ||
stackWithCauses, | ||
messageWithCauses | ||
} |
@@ -5,3 +5,3 @@ 'use strict' | ||
const { messageWithCauses, stackWithCauses } = require('./err-helpers') | ||
const { messageWithCauses, stackWithCauses, evaluateCause } = require('./err-helpers') | ||
@@ -70,3 +70,4 @@ const { toString } = Object.prototype | ||
if (err.cause) { | ||
_err.cause = errSerializer(err.cause) | ||
const cause = evaluateCause(err.cause) | ||
_err.cause = errSerializer(cause) | ||
} | ||
@@ -73,0 +74,0 @@ |
{ | ||
"name": "pino-std-serializers", | ||
"version": "5.4.0", | ||
"version": "5.5.0", | ||
"description": "A collection of standard object serializers for Pino", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -221,1 +221,29 @@ 'use strict' | ||
}) | ||
test('serializes causes with VError support', function (t) { | ||
t.plan(11) | ||
// Fake VError-style setup | ||
const err = Error('foo: bar') | ||
err.cause = () => { | ||
const err = Error('bar') | ||
err.cause = Error('abc') | ||
return err | ||
} | ||
const serialized = serializer(err) | ||
t.equal(serialized.type, 'Error') | ||
t.equal(serialized.message, 'foo: bar: abc') // message serialization already walks cause-chain | ||
t.match(serialized.stack, /err\.test\.js:/) | ||
t.ok(serialized.cause) | ||
t.equal(serialized.cause.type, 'Error') | ||
t.equal(serialized.cause.message, 'bar: abc') | ||
t.match(serialized.cause.stack, /err\.test\.js:/) | ||
t.ok(serialized.cause.cause) | ||
t.equal(serialized.cause.cause.type, 'Error') | ||
t.equal(serialized.cause.cause.message, 'abc') | ||
t.match(serialized.cause.cause.stack, /err\.test\.js:/) | ||
}) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
42051
1157