Socket
Socket
Sign inDemoInstall

make-error-cause

Package Overview
Dependencies
1
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 2.2.0 to 2.2.1

14

dist/index.d.ts

@@ -1,6 +0,12 @@

import * as makeError from 'make-error';
import * as makeError from "make-error";
/**
* Create a new error instance of `cause` property support.
*/
export declare class BaseError extends makeError.BaseError {
cause: Error | undefined;
constructor(message: string, cause?: Error | undefined);
cause?: Error | undefined;
constructor(message?: string, cause?: Error | undefined);
}
export declare function fullStack(error: Error | BaseError): string | undefined;
/**
* Capture the full stack trace of any error instance.
*/
export declare function fullStack(error: Error | BaseError): string;
"use strict";
var __extends = (this && this.__extends) || (function () {
var extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {

@@ -19,2 +22,5 @@ extendStatics(d, b);

exports.SEPARATOR_TEXT = "\n\nThe following exception was the direct cause of the above exception:\n\n";
/**
* Create a new error instance of `cause` property support.
*/
var BaseError = /** @class */ (function (_super) {

@@ -27,3 +33,3 @@ __extends(BaseError, _super);

}
BaseError.prototype[util_1.inspect.custom || 'inspect'] = function () {
BaseError.prototype[util_1.inspect.custom || "inspect"] = function () {
return fullStack(this);

@@ -34,8 +40,11 @@ };

exports.BaseError = BaseError;
/**
* Capture the full stack trace of any error instance.
*/
function fullStack(error) {
var err = error.cause;
var fullStack = error.stack;
var fullStack = error.stack || error.message || "";
while (err) {
fullStack += exports.SEPARATOR_TEXT;
fullStack += err.stack || err.message;
fullStack += err.stack || err.message || "";
err = err.cause;

@@ -42,0 +51,0 @@ }

"use strict";
var __extends = (this && this.__extends) || (function () {
var extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {

@@ -13,6 +16,5 @@ extendStatics(d, b);

Object.defineProperty(exports, "__esModule", { value: true });
var test = require("blue-tape");
var util_1 = require("util");
var index_1 = require("./index");
test('make error cause', function (t) {
describe("make error cause", function () {
var TestError = /** @class */ (function (_super) {

@@ -32,24 +34,23 @@ __extends(TestError, _super);

}(TestError));
t.test('render the cause', function (t) {
var cause = new Error('boom!');
var testError = new TestError('test boom!', cause);
var subTestError = new SubTestError('sub test boom!', testError);
t.equal(index_1.fullStack(cause), cause.stack);
t.ok(cause instanceof Error);
t.equal(testError.cause, cause);
t.equal(index_1.fullStack(testError), "" + testError.stack + index_1.SEPARATOR_TEXT + cause.stack);
t.equal(util_1.inspect(testError), index_1.fullStack(testError));
t.ok(testError instanceof Error);
t.ok(testError instanceof index_1.BaseError);
t.ok(testError instanceof TestError);
t.equal(subTestError.cause, testError);
t.equal(index_1.fullStack(subTestError), "" + subTestError.stack + index_1.SEPARATOR_TEXT + testError.stack + index_1.SEPARATOR_TEXT + cause.stack);
t.equal(util_1.inspect(subTestError), index_1.fullStack(subTestError));
t.ok(subTestError instanceof Error);
t.ok(subTestError instanceof index_1.BaseError);
t.ok(subTestError instanceof TestError);
t.ok(subTestError instanceof SubTestError);
t.end();
it("should render the cause", function () {
var cause = new Error("boom!");
var testError = new TestError("test boom!", cause);
var subTestError = new SubTestError("sub test boom!", testError);
expect(index_1.fullStack(cause)).toEqual(cause.stack);
expect(cause).toBeInstanceOf(Error);
expect(testError.cause).toEqual(cause);
expect(index_1.fullStack(testError)).toEqual("" + testError.stack + index_1.SEPARATOR_TEXT + cause.stack);
expect(util_1.inspect(testError)).toEqual(index_1.fullStack(testError));
expect(testError).toBeInstanceOf(Error);
expect(testError).toBeInstanceOf(index_1.BaseError);
expect(testError).toBeInstanceOf(TestError);
expect(subTestError.cause).toEqual(testError);
expect(index_1.fullStack(subTestError)).toEqual("" + subTestError.stack + index_1.SEPARATOR_TEXT + testError.stack + index_1.SEPARATOR_TEXT + cause.stack);
expect(util_1.inspect(subTestError)).toEqual(index_1.fullStack(subTestError));
expect(subTestError).toBeInstanceOf(Error);
expect(subTestError).toBeInstanceOf(index_1.BaseError);
expect(subTestError).toBeInstanceOf(TestError);
expect(subTestError).toBeInstanceOf(SubTestError);
});
});
//# sourceMappingURL=index.spec.js.map
{
"name": "make-error-cause",
"version": "2.2.0",
"version": "2.2.1",
"description": "Make your own nested error types!",

@@ -11,8 +11,9 @@ "main": "dist/index.js",

"scripts": {
"prettier": "prettier --write",
"lint": "tslint \"src/**/*.ts\" --project tsconfig.json",
"build": "rm -rf dist/ && tsc",
"test-spec": "ts-node --type-check node_modules/blue-tape/bin/blue-tape.js \"src/**/*.spec.ts\" | tap-spec",
"test-cov": "ts-node node_modules/istanbul/lib/cli.js cover -e .ts --print none -x \"*.d.ts\" -x \"*.spec.ts\" blue-tape -- \"src/**/*.spec.ts\" | tap-spec",
"test": "npm run lint && npm run test-cov",
"prepublish": "npm run build"
"format": "npm run prettier -- README.md .travis.yml \"src/**/*.{jsx?,tsx?}\"",
"build": "rimraf dist && tsc",
"specs": "jest --coverage",
"test": "npm run -s lint && npm run -s build && npm run -s specs",
"prepare": "npm run build"
},

@@ -41,16 +42,51 @@ "repository": {

"homepage": "https://github.com/blakeembrey/make-error-cause",
"jest": {
"roots": [
"<rootDir>/src/"
],
"transform": {
"\\.tsx?$": "ts-jest"
},
"testRegex": "(/__tests__/.*|\\.(test|spec))\\.(tsx?|jsx?)$",
"moduleFileExtensions": [
"ts",
"tsx",
"js",
"jsx",
"json",
"node"
]
},
"husky": {
"hooks": {
"pre-commit": "lint-staged"
}
},
"lint-staged": {
"*.{js,json,css,md}": [
"npm run prettier",
"git add"
]
},
"publishConfig": {
"access": "public"
},
"devDependencies": {
"@types/blue-tape": "^0.1.31",
"@types/node": "^9.6.1",
"blue-tape": "^1.0.0",
"istanbul": "1.0.0-alpha.2",
"tap-spec": "^4.1.1",
"ts-node": "^5.0.1",
"@types/jest": "^24.0.15",
"@types/node": "^12.6.2",
"husky": "^3.0.0",
"jest": "^24.8.0",
"lint-staged": "^9.1.0",
"prettier": "^1.18.2",
"rimraf": "^2.6.3",
"ts-jest": "^24.0.2",
"ts-node": "^8.3.0",
"tslint": "^5.9.1",
"tslint-config-standard": "^7.0.0",
"typescript": "^2.7.2"
"tslint-config-prettier": "^1.18.0",
"tslint-config-standard": "^8.0.1",
"typescript": "^3.5.3"
},
"dependencies": {
"make-error": "^1.3.4"
"make-error": "^1.3.5"
}
}

@@ -12,7 +12,7 @@ # Make Error Cause

* Compatible with node.js and browsers
* Works with `instanceof`
* Output full stack trace with `fullStack(err)`
* Automatic full stack traces with node.js (via [`inspect()`](https://nodejs.org/api/util.html#util_util_inspect_object_options))
* Extends [`make-error`](https://github.com/JsCommunity/make-error)
- Compatible with node.js and browsers
- Works with `instanceof`
- Automatic full stack traces in node.js (supports [`inspect()`](https://nodejs.org/api/util.html#util_util_inspect_object_options))
- Output full stack trace with `fullStack(err)`
- Extends [`make-error`](https://github.com/JsCommunity/make-error)

@@ -28,17 +28,17 @@ ## Installation

```js
import { BaseError, fullStack } from 'make-error-cause'
import { BaseError, fullStack } from "make-error-cause";
class CustomError extends BaseError {
constructor (message, cause) {
super(message, cause)
constructor(message, cause) {
super(message, cause);
}
}
const error = new Error('Boom!')
const customError = new CustomError('Another boom!', error)
const error = new Error("Boom!");
const customError = new CustomError("Another boom!", error);
console.log(fullStack(error)) // Works with any error.
console.log(fullStack(customError)) // Extended stack trace contains error causes.
console.log(customError); // Automatically prints full stack trace using `fullStack(this)`.
console.log(customError.cause); // Check causes via the `.cause` property.
console.log(customError instanceof Error) //=> true
console.log(customError instanceof Error); //=> true
```

@@ -52,4 +52,4 @@

* [Java](https://docs.oracle.com/javase/7/docs/api/java/lang/Exception.html)
* [Python](https://www.python.org/dev/peps/pep-3134/)
- [Java](https://docs.oracle.com/javase/7/docs/api/java/lang/Exception.html)
- [Python](https://www.python.org/dev/peps/pep-3134/)

@@ -56,0 +56,0 @@ ## License

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc