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

@wixc3/common

Package Overview
Dependencies
Maintainers
64
Versions
56
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@wixc3/common - npm Package Compare versions

Comparing version 15.1.0 to 15.1.1

7

dist/cjs/errors.d.ts

@@ -62,9 +62,2 @@ /**

export declare function isErrorLikeObject(error: unknown): error is Error;
export declare const TRACE_DEFAULTS: {
noTraceMessage: string;
skipLines: number;
filterPattern: RegExp | null;
};
export declare function getStackTrace(options?: Partial<typeof TRACE_DEFAULTS>): string;
export declare function errorWithTrace(message: string, trace: string, options?: ErrorOptions): Error;
//# sourceMappingURL=errors.d.ts.map

21

dist/cjs/errors.js
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.errorWithTrace = exports.getStackTrace = exports.TRACE_DEFAULTS = exports.isErrorLikeObject = exports.errorToPlainObject = exports.stringifyErrorStack = exports.UnreachableCaseError = exports.ErrorWithCode = exports.getErrorCode = exports.toError = void 0;
exports.isErrorLikeObject = exports.errorToPlainObject = exports.stringifyErrorStack = exports.UnreachableCaseError = exports.ErrorWithCode = exports.getErrorCode = exports.toError = void 0;
const objects_1 = require("./objects");

@@ -91,21 +91,2 @@ /**

exports.isErrorLikeObject = isErrorLikeObject;
exports.TRACE_DEFAULTS = {
noTraceMessage: 'no stack trace',
skipLines: 2,
filterPattern: null,
};
function getStackTrace(options = exports.TRACE_DEFAULTS) {
var _a;
const { filterPattern, noTraceMessage, skipLines } = { ...exports.TRACE_DEFAULTS, ...options };
const { stack } = new Error();
return ((_a = stack === null || stack === void 0 ? void 0 : stack.split('\n').slice(skipLines).filter((l) => (filterPattern ? filterPattern.test(l) : true)).join('\n')) !== null && _a !== void 0 ? _a : noTraceMessage);
}
exports.getStackTrace = getStackTrace;
function errorWithTrace(message, trace, options) {
var _a, _b;
const err = new Error(message, options);
err.stack = ((_b = (_a = err.stack) === null || _a === void 0 ? void 0 : _a.split('\n')[0]) !== null && _b !== void 0 ? _b : `Error: ${message}`) + '\n' + trace;
return err;
}
exports.errorWithTrace = errorWithTrace;
//# sourceMappingURL=errors.js.map

@@ -62,9 +62,2 @@ /**

export declare function isErrorLikeObject(error: unknown): error is Error;
export declare const TRACE_DEFAULTS: {
noTraceMessage: string;
skipLines: number;
filterPattern: RegExp | null;
};
export declare function getStackTrace(options?: Partial<typeof TRACE_DEFAULTS>): string;
export declare function errorWithTrace(message: string, trace: string, options?: ErrorOptions): Error;
//# sourceMappingURL=errors.d.ts.map

@@ -81,19 +81,2 @@ import { isObject } from './objects';

}
export const TRACE_DEFAULTS = {
noTraceMessage: 'no stack trace',
skipLines: 2,
filterPattern: null,
};
export function getStackTrace(options = TRACE_DEFAULTS) {
var _a;
const { filterPattern, noTraceMessage, skipLines } = { ...TRACE_DEFAULTS, ...options };
const { stack } = new Error();
return ((_a = stack === null || stack === void 0 ? void 0 : stack.split('\n').slice(skipLines).filter((l) => (filterPattern ? filterPattern.test(l) : true)).join('\n')) !== null && _a !== void 0 ? _a : noTraceMessage);
}
export function errorWithTrace(message, trace, options) {
var _a, _b;
const err = new Error(message, options);
err.stack = ((_b = (_a = err.stack) === null || _a === void 0 ? void 0 : _a.split('\n')[0]) !== null && _b !== void 0 ? _b : `Error: ${message}`) + '\n' + trace;
return err;
}
//# sourceMappingURL=errors.js.map

2

package.json
{
"name": "@wixc3/common",
"version": "15.1.0",
"version": "15.1.1",
"description": "Common utils, usable in all environments",

@@ -5,0 +5,0 @@ "main": "dist/cjs/index.js",

@@ -90,25 +90,1 @@ import { isObject } from './objects';

}
export const TRACE_DEFAULTS = {
noTraceMessage: 'no stack trace',
skipLines: 2,
filterPattern: null as RegExp | null,
};
export function getStackTrace(options: Partial<typeof TRACE_DEFAULTS> = TRACE_DEFAULTS) {
const { filterPattern, noTraceMessage, skipLines } = { ...TRACE_DEFAULTS, ...options };
const { stack } = new Error();
return (
stack
?.split('\n')
.slice(skipLines)
.filter((l) => (filterPattern ? filterPattern.test(l) : true))
.join('\n') ?? noTraceMessage
);
}
export function errorWithTrace(message: string, trace: string, options?: ErrorOptions) {
const err = new Error(message, options);
err.stack = (err.stack?.split('\n')[0] ?? `Error: ${message}`) + '\n' + trace;
return err;
}
import chai, { expect } from 'chai';
import sinonChai from 'sinon-chai';
import { isErrorLikeObject, getStackTrace, errorWithTrace } from '../errors';
import { deferred } from 'promise-assist';
import { isErrorLikeObject } from '../errors';

@@ -24,37 +23,1 @@ chai.use(sinonChai);

});
describe('getStackTrace', () => {
it('default', () => {
const stack = getStackTrace();
expect(stack.split('\n')[0]).to.match(/.*errors\.unit\.ts/);
});
it('removes this package internals from stacktrace', () => {
const stack = getStackTrace({ skipLines: 1 });
expect(stack.split('\n')[0]).to.match(/.*errors\.ts/);
});
it(`removes lines that don't match filterPattern`, () => {
const stack = getStackTrace({ filterPattern: /.*errors\.unit\.ts/ });
expect(stack.split('\n')).to.have.lengthOf(1);
expect(stack).to.match(/.*errors\.unit\.ts/);
});
});
describe('errorWithTrace', () => {
it('returns an error has the given stack trace', async () => {
const trace = getStackTrace();
const err = deferred<Error>();
setTimeout(() => {
try {
throw errorWithTrace('err', trace, { cause: 'test' });
} catch (e) {
err.resolve(e as Error);
}
}, 1);
const { stack, message, cause } = await err.promise;
expect(stack).to.match(/Error: err\n\s+at Context\.<anonymous>.*errors\.unit\.ts.*\n/);
expect(message).to.equal('err');
expect(cause).to.equal('test');
});
});

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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