New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@dotcom-reliability-kit/serialize-error

Package Overview
Dependencies
Maintainers
5
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@dotcom-reliability-kit/serialize-error - npm Package Compare versions

Comparing version 2.1.0 to 2.2.0

5

lib/index.d.ts

@@ -7,2 +7,3 @@ export = serializeError;

type SerializedError = {
fingerprint: string | null;
name: string;

@@ -12,3 +13,3 @@ code: string;

isOperational: boolean;
relatesToSystems: Array<string>;
relatesToSystems: string[];
cause: (Error | null);

@@ -18,3 +19,3 @@ stack: (string | null);

data: {
[x: string]: any;
[key: string]: any;
};

@@ -21,0 +22,0 @@ };

19

lib/index.js

@@ -0,3 +1,9 @@

const crypto = require('node:crypto');
/**
* @typedef {object} SerializedError
* @property {string | null} fingerprint
* A hash of the first part of the error stack, used to help group errors that occurred in
* the same part of the codebase. The fingerprint is null if the error does not include a
* stack trace.
* @property {string} name

@@ -11,3 +17,3 @@ * The name of the class that the error is an instance of.

* Whether the error is operational, as in it's an error we expect sometimes as part of running the application.
* @property {Array<string>} relatesToSystems
* @property {string[]} relatesToSystems
* An array of FT system codes which are related to this error.

@@ -20,3 +26,3 @@ * @property {(Error | null)} cause

* An HTTP status code to represent the error.
* @property {Object<string, any>} data
* @property {{[key: string]: any}} data
* Any additional error information.

@@ -74,2 +80,10 @@ */

errorProperties.stack = error.stack;
// Calculate the error fingerprint
const errorStackLines = error.stack.split(/[\r\n]+/);
const errorStackHeader = errorStackLines.slice(0, 2).join('\n');
errorProperties.fingerprint = crypto
.createHash('md5')
.update(errorStackHeader)
.digest('hex');
}

@@ -107,2 +121,3 @@

{
fingerprint: null,
name: 'Error',

@@ -109,0 +124,0 @@ code: 'UNKNOWN',

{
"name": "@dotcom-reliability-kit/serialize-error",
"version": "2.1.0",
"version": "2.2.0",
"description": "A utility function to serialize an error object in a way that's friendly to loggers, view engines, and converting to JSON",

@@ -5,0 +5,0 @@ "repository": {

@@ -9,2 +9,3 @@

* [`SerializedError` type](#serializederror-type)
* [`SerializedError.fingerprint`](#serializederrorfingerprint)
* [`SerializedError.name`](#serializederrorname)

@@ -46,2 +47,3 @@ * [`SerializedError.code`](#serializederrorcode)

// {
// fingerprint: '...',
// name: 'Error',

@@ -71,2 +73,9 @@ // code: 'UNKNOWN',

#### `SerializedError.fingerprint`
This is a hash of the first part of the error stack, used to help group errors that occurred in the same part of the codebase. The fingerprint is `null` if the error does not include a stack trace.
> **Warning**
> Do not rely on the format or length of the error fingerprint as the underlying hash may change without warning. You _can_ rely on the fingerprint being unique to the type of error being thrown.
#### `SerializedError.name`

@@ -73,0 +82,0 @@

Sorry, the diff of this file is not supported yet

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