Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

pino-std-serializers

Package Overview
Dependencies
Maintainers
4
Versions
32
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pino-std-serializers - npm Package Compare versions

Comparing version 5.4.0 to 5.5.0

30

lib/err-helpers.js

@@ -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:/)
})
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc