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

pino-std-serializers

Package Overview
Dependencies
Maintainers
3
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 6.1.0 to 6.2.0

lib/err-proto.js

8

index.d.ts

@@ -35,6 +35,12 @@ // Type definitions for pino-std-serializers 2.4

/**
* Serializes an Error object.
* Serializes an Error object. Does not serialize "err.cause" fields (will append the err.cause.message to err.message
* and err.cause.stack to err.stack)
*/
export function err(err: Error): SerializedError;
/**
* Serializes an Error object, including full serialization for any err.cause fields recursively.
*/
export function errWithCause(err: Error): SerializedError;
export interface SerializedRequest {

@@ -41,0 +47,0 @@ /**

'use strict'
const errSerializer = require('./lib/err')
const errWithCauseSerializer = require('./lib/err-with-cause')
const reqSerializers = require('./lib/req')

@@ -9,2 +10,3 @@ const resSerializers = require('./lib/res')

err: errSerializer,
errWithCause: errWithCauseSerializer,
mapHttpRequest: reqSerializers.mapHttpRequest,

@@ -11,0 +13,0 @@ mapHttpResponse: resSerializers.mapHttpResponse,

39

lib/err.js

@@ -6,41 +6,6 @@ 'use strict'

const { messageWithCauses, stackWithCauses, isErrorLike } = require('./err-helpers')
const { pinoErrProto, pinoErrorSymbols } = require('./err-proto')
const { seen } = pinoErrorSymbols
const { toString } = Object.prototype
const seen = Symbol('circular-ref-tag')
const rawSymbol = Symbol('pino-raw-err-ref')
const pinoErrProto = Object.create({}, {
type: {
enumerable: true,
writable: true,
value: undefined
},
message: {
enumerable: true,
writable: true,
value: undefined
},
stack: {
enumerable: true,
writable: true,
value: undefined
},
aggregateErrors: {
enumerable: true,
writable: true,
value: undefined
},
raw: {
enumerable: false,
get: function () {
return this[rawSymbol]
},
set: function (val) {
this[rawSymbol] = val
}
}
})
Object.defineProperty(pinoErrProto, rawSymbol, {
writable: true,
value: {}
})

@@ -47,0 +12,0 @@ function errSerializer (err) {

{
"name": "pino-std-serializers",
"version": "6.1.0",
"version": "6.2.0",
"description": "A collection of standard object serializers for Pino",

@@ -40,4 +40,4 @@ "main": "index.js",

"tap": "^15.0.10",
"tsd": "^0.25.0",
"typescript": "^4.2.4"
"tsd": "^0.28.0",
"typescript": "^5.0.2"
},

@@ -44,0 +44,0 @@ "tsd": {

@@ -19,2 +19,3 @@ # pino-std-serializers  [![CI](https://github.com/pinojs/pino-std-serializers/workflows/CI/badge.svg)](https://github.com/pinojs/pino-std-serializers/actions?query=workflow%3ACI)

// to use.
[...any additional Enumerable property the original Error had]
}

@@ -26,2 +27,73 @@ ```

If the error object has a [`cause`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/cause) property, the `cause`'s `message` and `stack` will be appended to the top-level `message` and `stack`. All other parameters that belong to the `error.cause` object will be omitted.
Example:
```js
const serializer = require('pino-std-serializers').err;
const innerError = new Error("inner error");
innerError.isInner = true;
const outerError = new Error("outer error", { cause: innerError });
outerError.isInner = false;
const serialized = serializer(outerError);
/* Result:
{
"type": "Error",
"message": "outer error: inner error",
"isInner": false,
"stack": "Error: outer error
at <...omitted..>
caused by: Error: inner error
at <...omitted..>
}
*/
### `exports.errWithCause(error)`
Serializes an `Error` like object, including any `error.cause`. Returns an object:
```js
{
type: 'string', // The name of the object's constructor.
message: 'string', // The supplied error message.
stack: 'string', // The stack when the error was generated.
cause?: Error, // If the original error had an error.cause, it will be serialized here
raw: Error // Non-enumerable, i.e. will not be in the output, original
// Error object. This is available for subsequent serializers
// to use.
[...any additional Enumerable property the original Error had]
}
```
Any other extra properties, e.g. `statusCode`, that have been attached to the object will also be present on the serialized object.
Example:
```javascript
const serializer = require('pino-std-serializers').errWithCause;
const innerError = new Error("inner error");
innerError.isInner = true;
const outerError = new Error("outer error", { cause: innerError });
outerError.isInner = false;
const serialized = serializer(outerError);
/* Result:
{
"type": "Error",
"message": "outer error",
"isInner": false,
"stack": "Error: outer error
at <...omitted..>",
"cause": {
"type": "Error",
"message": "inner error",
"isInner": true,
"stack": "Error: inner error
at <...omitted..>"
},
}
*/
```
### `exports.mapHttpResponse(response)`

@@ -54,3 +126,3 @@ Used internally by Pino for general response logging. Returns an object:

{
id: 'string', // Defaults to `undefined`, unless there is an `id` property
id: 'string', // Defaults to `undefined`, unless there is an `id` property
// already attached to the `request` object or to the `request.info`

@@ -70,3 +142,3 @@ // object. Attach a synchronous function

// request object. This is available for subsequent serializers
// to use. In cases where the `request` input already has
// to use. In cases where the `request` input already has
// a `raw` property this will replace the original `request.raw`

@@ -73,0 +145,0 @@ // property

import {IncomingMessage, ServerResponse} from "http";
import {
err,
errWithCause,
req,

@@ -48,2 +49,5 @@ res,

const fakeErrorWithCause = new Error('A fake error for testing with cause', { cause: new Error('An inner fake error') });
const serializedErrorWithCause: SerializedError = errWithCause(fakeError);
const request: IncomingMessage = {} as IncomingMessage

@@ -50,0 +54,0 @@ const serializedRequest: SerializedRequest = req(request);

{
"compilerOptions": {
"target": "es6",
"lib": [ "es2015" ],
"lib": [ "es2022" ],
"module": "commonjs",

@@ -6,0 +6,0 @@ "noEmit": true,

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