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

@perfective/error

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@perfective/error - npm Package Compare versions

Comparing version 0.1.1 to 0.2.0-alpha

dist/error/trace/trace.d.ts

4

dist/error/error.d.ts

@@ -1,4 +0,6 @@

export declare function error(message?: string): Error;
export declare function error(message: string): Error;
export declare function isError<T>(value: Error | T): value is Error;
export declare function isNotError<T>(value: Error | T): value is T;
export declare function errorOutput(error: Error): string;
export declare function stack(error: Error): string;
//# sourceMappingURL=error.d.ts.map

@@ -1,16 +0,19 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.isNotError = exports.isError = exports.error = void 0;
function error(message) {
export function error(message) {
return new Error(message);
}
exports.error = error;
function isError(value) {
export function isError(value) {
return value instanceof Error;
}
exports.isError = isError;
function isNotError(value) {
export function isNotError(value) {
return !(value instanceof Error);
}
exports.isNotError = isNotError;
export function errorOutput(error) {
return `${error.name}: ${error.message}`;
}
export function stack(error) {
if (error.stack !== void 0) {
return error.stack;
}
return [error.message, 'at <unknown>'].join('\n ');
}
//# sourceMappingURL=error.js.map

@@ -1,34 +0,49 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var error_1 = require("./error");
describe('error', function () {
it('creates a new Error with a message', function () {
expect(error_1.error('Exception'))
import { error, errorOutput, isError, isNotError, stack } from './error';
describe('error', () => {
it('creates a new Error with a message', () => {
expect(error('Exception'))
.toStrictEqual(new Error('Exception'));
});
it('creates a new Error without a message', function () {
expect(error_1.error())
.toStrictEqual(new Error());
});
});
describe('isError', function () {
it('returns true when value is an Error', function () {
expect(error_1.isError(new Error()))
describe('isError', () => {
it('returns true when value is an Error', () => {
expect(isError(new Error()))
.toBe(true);
});
it('returns false when value is not an Error', function () {
expect(error_1.isError('Error'))
it('returns false when value is not an Error', () => {
expect(isError('Error'))
.toBe(false);
});
});
describe('isNotError', function () {
it('returns false when value is an Error', function () {
expect(error_1.isNotError(new Error()))
describe('isNotError', () => {
it('returns false when value is an Error', () => {
expect(isNotError(new Error()))
.toBe(false);
});
it('returns true when value is not an Error', function () {
expect(error_1.isNotError('Error'))
it('returns true when value is not an Error', () => {
expect(isNotError('Error'))
.toBe(true);
});
});
describe('errorOutput', () => {
it('returns human-readable string matching Error.toString() on Node.js', () => {
expect(errorOutput(new Error('Failure!')))
.toStrictEqual('Error: Failure!');
expect(errorOutput(new TypeError('Invalid type')))
.toStrictEqual('TypeError: Invalid type');
});
});
describe('errorStack', () => {
it('returns stack when Error.stack property present', () => {
const error = new Error('Stack');
expect(stack(error))
.toMatch('Error: Stack\n at Object.<anonymous>');
});
it('returns message with "at <unknown>" stack, when Error.stack property is undefined', () => {
const error = new Error('No Stack');
error.stack = undefined;
expect(stack(error))
.toStrictEqual('No Stack\n at <unknown>');
});
});
//# sourceMappingURL=error.spec.js.map

@@ -1,4 +0,4 @@

export declare function evalError(message?: string): EvalError;
export declare function evalError(message: string): EvalError;
export declare function isEvalError<T>(value: EvalError | T): value is EvalError;
export declare function isNotEvalError<T>(value: EvalError | T): value is T;
//# sourceMappingURL=eval-error.d.ts.map

@@ -1,16 +0,10 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.isNotEvalError = exports.isEvalError = exports.evalError = void 0;
function evalError(message) {
export function evalError(message) {
return new EvalError(message);
}
exports.evalError = evalError;
function isEvalError(value) {
export function isEvalError(value) {
return value instanceof EvalError;
}
exports.isEvalError = isEvalError;
function isNotEvalError(value) {
export function isNotEvalError(value) {
return !(value instanceof EvalError);
}
exports.isNotEvalError = isNotEvalError;
//# sourceMappingURL=eval-error.js.map

@@ -1,31 +0,25 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var eval_error_1 = require("./eval-error");
describe('evalError', function () {
it('creates a new EvalError with a message', function () {
expect(eval_error_1.evalError('Exception'))
import { evalError, isEvalError, isNotEvalError } from './eval-error';
describe('evalError', () => {
it('creates a new EvalError with a message', () => {
expect(evalError('Exception'))
.toStrictEqual(new EvalError('Exception'));
});
it('creates a new EvalError without a message', function () {
expect(eval_error_1.evalError())
.toStrictEqual(new EvalError());
});
});
describe('isEvalError', function () {
it('returns true when value is an EvalError', function () {
expect(eval_error_1.isEvalError(new EvalError()))
describe('isEvalError', () => {
it('returns true when value is an EvalError', () => {
expect(isEvalError(new EvalError()))
.toBe(true);
});
it('returns false when value is not an EvalError', function () {
expect(eval_error_1.isEvalError('EvalError'))
it('returns false when value is not an EvalError', () => {
expect(isEvalError('EvalError'))
.toBe(false);
});
});
describe('isNotEvalError', function () {
it('returns false when value is an EvalError', function () {
expect(eval_error_1.isNotEvalError(new EvalError()))
describe('isNotEvalError', () => {
it('returns false when value is an EvalError', () => {
expect(isNotEvalError(new EvalError()))
.toBe(false);
});
it('returns true when value is not an EvalError', function () {
expect(eval_error_1.isNotEvalError('EvalError'))
it('returns true when value is not an EvalError', () => {
expect(isNotEvalError('EvalError'))
.toBe(true);

@@ -32,0 +26,0 @@ });

@@ -1,4 +0,4 @@

export declare function rangeError(message?: string): RangeError;
export declare function rangeError(message: string): RangeError;
export declare function isRangeError<T>(value: RangeError | T): value is RangeError;
export declare function isNotRangeError<T>(value: RangeError | T): value is T;
//# sourceMappingURL=range-error.d.ts.map

@@ -1,16 +0,10 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.isNotRangeError = exports.isRangeError = exports.rangeError = void 0;
function rangeError(message) {
export function rangeError(message) {
return new RangeError(message);
}
exports.rangeError = rangeError;
function isRangeError(value) {
export function isRangeError(value) {
return value instanceof RangeError;
}
exports.isRangeError = isRangeError;
function isNotRangeError(value) {
export function isNotRangeError(value) {
return !(value instanceof RangeError);
}
exports.isNotRangeError = isNotRangeError;
//# sourceMappingURL=range-error.js.map

@@ -1,31 +0,25 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var range_error_1 = require("./range-error");
describe('rangeError', function () {
it('creates a new RangeError with a message', function () {
expect(range_error_1.rangeError('Exception'))
import { isNotRangeError, isRangeError, rangeError } from './range-error';
describe('rangeError', () => {
it('creates a new RangeError with a message', () => {
expect(rangeError('Exception'))
.toStrictEqual(new RangeError('Exception'));
});
it('creates a new RangeError without a message', function () {
expect(range_error_1.rangeError())
.toStrictEqual(new RangeError());
});
});
describe('isRangeError', function () {
it('returns true when value is an RangeError', function () {
expect(range_error_1.isRangeError(new RangeError()))
describe('isRangeError', () => {
it('returns true when value is an RangeError', () => {
expect(isRangeError(new RangeError()))
.toBe(true);
});
it('returns false when value is not an RangeError', function () {
expect(range_error_1.isRangeError('RangeError'))
it('returns false when value is not an RangeError', () => {
expect(isRangeError('RangeError'))
.toBe(false);
});
});
describe('isNotRangeError', function () {
it('returns false when value is an RangeError', function () {
expect(range_error_1.isNotRangeError(new RangeError()))
describe('isNotRangeError', () => {
it('returns false when value is an RangeError', () => {
expect(isNotRangeError(new RangeError()))
.toBe(false);
});
it('returns true when value is not an RangeError', function () {
expect(range_error_1.isNotRangeError('RangeError'))
it('returns true when value is not an RangeError', () => {
expect(isNotRangeError('RangeError'))
.toBe(true);

@@ -32,0 +26,0 @@ });

@@ -1,4 +0,4 @@

export declare function referenceError(message?: string): ReferenceError;
export declare function referenceError(message: string): ReferenceError;
export declare function isReferenceError<T>(value: ReferenceError | T): value is ReferenceError;
export declare function isNotReferenceError<T>(value: ReferenceError | T): value is T;
//# sourceMappingURL=reference-error.d.ts.map

@@ -1,16 +0,10 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.isNotReferenceError = exports.isReferenceError = exports.referenceError = void 0;
function referenceError(message) {
export function referenceError(message) {
return new ReferenceError(message);
}
exports.referenceError = referenceError;
function isReferenceError(value) {
export function isReferenceError(value) {
return value instanceof ReferenceError;
}
exports.isReferenceError = isReferenceError;
function isNotReferenceError(value) {
export function isNotReferenceError(value) {
return !(value instanceof ReferenceError);
}
exports.isNotReferenceError = isNotReferenceError;
//# sourceMappingURL=reference-error.js.map

@@ -1,31 +0,25 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var reference_error_1 = require("./reference-error");
describe('referenceError', function () {
it('creates a new ReferenceError with a message', function () {
expect(reference_error_1.referenceError('Exception'))
import { isNotReferenceError, isReferenceError, referenceError } from './reference-error';
describe('referenceError', () => {
it('creates a new ReferenceError with a message', () => {
expect(referenceError('Exception'))
.toStrictEqual(new ReferenceError('Exception'));
});
it('creates a new ReferenceError without a message', function () {
expect(reference_error_1.referenceError())
.toStrictEqual(new ReferenceError());
});
});
describe('isReferenceError', function () {
it('returns true when value is an ReferenceError', function () {
expect(reference_error_1.isReferenceError(new ReferenceError()))
describe('isReferenceError', () => {
it('returns true when value is an ReferenceError', () => {
expect(isReferenceError(new ReferenceError()))
.toBe(true);
});
it('returns false when value is not an ReferenceError', function () {
expect(reference_error_1.isReferenceError('ReferenceError'))
it('returns false when value is not an ReferenceError', () => {
expect(isReferenceError('ReferenceError'))
.toBe(false);
});
});
describe('isNotReferenceError', function () {
it('returns false when value is an ReferenceError', function () {
expect(reference_error_1.isNotReferenceError(new ReferenceError()))
describe('isNotReferenceError', () => {
it('returns false when value is an ReferenceError', () => {
expect(isNotReferenceError(new ReferenceError()))
.toBe(false);
});
it('returns true when value is not an ReferenceError', function () {
expect(reference_error_1.isNotReferenceError('ReferenceError'))
it('returns true when value is not an ReferenceError', () => {
expect(isNotReferenceError('ReferenceError'))
.toBe(true);

@@ -32,0 +26,0 @@ });

@@ -1,4 +0,4 @@

export declare function syntaxError(message?: string): SyntaxError;
export declare function syntaxError(message: string): SyntaxError;
export declare function isSyntaxError<T>(value: SyntaxError | T): value is SyntaxError;
export declare function isNotSyntaxError<T>(value: SyntaxError | T): value is T;
//# sourceMappingURL=syntax-error.d.ts.map

@@ -1,16 +0,10 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.isNotSyntaxError = exports.isSyntaxError = exports.syntaxError = void 0;
function syntaxError(message) {
export function syntaxError(message) {
return new SyntaxError(message);
}
exports.syntaxError = syntaxError;
function isSyntaxError(value) {
export function isSyntaxError(value) {
return value instanceof SyntaxError;
}
exports.isSyntaxError = isSyntaxError;
function isNotSyntaxError(value) {
export function isNotSyntaxError(value) {
return !(value instanceof SyntaxError);
}
exports.isNotSyntaxError = isNotSyntaxError;
//# sourceMappingURL=syntax-error.js.map

@@ -1,31 +0,25 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var syntax_error_1 = require("./syntax-error");
describe('syntaxError', function () {
it('creates a new SyntaxError with a message', function () {
expect(syntax_error_1.syntaxError('Exception'))
import { isNotSyntaxError, isSyntaxError, syntaxError } from './syntax-error';
describe('syntaxError', () => {
it('creates a new SyntaxError with a message', () => {
expect(syntaxError('Exception'))
.toStrictEqual(new SyntaxError('Exception'));
});
it('creates a new SyntaxError without a message', function () {
expect(syntax_error_1.syntaxError())
.toStrictEqual(new SyntaxError());
});
});
describe('isSyntaxError', function () {
it('returns true when value is an SyntaxError', function () {
expect(syntax_error_1.isSyntaxError(new SyntaxError()))
describe('isSyntaxError', () => {
it('returns true when value is an SyntaxError', () => {
expect(isSyntaxError(new SyntaxError()))
.toBe(true);
});
it('returns false when value is not an SyntaxError', function () {
expect(syntax_error_1.isSyntaxError('SyntaxError'))
it('returns false when value is not an SyntaxError', () => {
expect(isSyntaxError('SyntaxError'))
.toBe(false);
});
});
describe('isNotSyntaxError', function () {
it('returns false when value is an SyntaxError', function () {
expect(syntax_error_1.isNotSyntaxError(new SyntaxError()))
describe('isNotSyntaxError', () => {
it('returns false when value is an SyntaxError', () => {
expect(isNotSyntaxError(new SyntaxError()))
.toBe(false);
});
it('returns true when value is not an SyntaxError', function () {
expect(syntax_error_1.isNotSyntaxError('SyntaxError'))
it('returns true when value is not an SyntaxError', () => {
expect(isNotSyntaxError('SyntaxError'))
.toBe(true);

@@ -32,0 +26,0 @@ });

@@ -1,4 +0,4 @@

export declare function typeError(message?: string): TypeError;
export declare function typeError(message: string): TypeError;
export declare function isTypeError<T>(value: TypeError | T): value is TypeError;
export declare function isNotTypeError<T>(value: TypeError | T): value is T;
//# sourceMappingURL=type-error.d.ts.map

@@ -1,16 +0,10 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.isNotTypeError = exports.isTypeError = exports.typeError = void 0;
function typeError(message) {
export function typeError(message) {
return new TypeError(message);
}
exports.typeError = typeError;
function isTypeError(value) {
export function isTypeError(value) {
return value instanceof TypeError;
}
exports.isTypeError = isTypeError;
function isNotTypeError(value) {
export function isNotTypeError(value) {
return !(value instanceof TypeError);
}
exports.isNotTypeError = isNotTypeError;
//# sourceMappingURL=type-error.js.map

@@ -1,31 +0,25 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var type_error_1 = require("./type-error");
describe('typeError', function () {
it('creates a new TypeError with a message', function () {
expect(type_error_1.typeError('Exception'))
import { isNotTypeError, isTypeError, typeError } from './type-error';
describe('typeError', () => {
it('creates a new TypeError with a message', () => {
expect(typeError('Exception'))
.toStrictEqual(new TypeError('Exception'));
});
it('creates a new TypeError without a message', function () {
expect(type_error_1.typeError())
.toStrictEqual(new TypeError());
});
});
describe('isTypeError', function () {
it('returns true when value is an TypeError', function () {
expect(type_error_1.isTypeError(new TypeError()))
describe('isTypeError', () => {
it('returns true when value is an TypeError', () => {
expect(isTypeError(new TypeError()))
.toBe(true);
});
it('returns false when value is not an TypeError', function () {
expect(type_error_1.isTypeError('TypeError'))
it('returns false when value is not an TypeError', () => {
expect(isTypeError('TypeError'))
.toBe(false);
});
});
describe('isNotTypeError', function () {
it('returns false when value is an TypeError', function () {
expect(type_error_1.isNotTypeError(new TypeError()))
describe('isNotTypeError', () => {
it('returns false when value is an TypeError', () => {
expect(isNotTypeError(new TypeError()))
.toBe(false);
});
it('returns true when value is not an TypeError', function () {
expect(type_error_1.isNotTypeError('TypeError'))
it('returns true when value is not an TypeError', () => {
expect(isNotTypeError('TypeError'))
.toBe(true);

@@ -32,0 +26,0 @@ });

@@ -1,2 +0,2 @@

export { error, isError, isNotError, } from './error/error';
export { error, errorOutput, isError, isNotError, stack, } from './error/error';
export { evalError, isEvalError, isNotEvalError, } from './error/eval-error';

@@ -7,3 +7,5 @@ export { isNotRangeError, isRangeError, rangeError, } from './error/range-error';

export { isNotTypeError, isTypeError, typeError, } from './error/type-error';
export { panic, throws, } from './panic/panic';
export { Trace, stackTrace, trace, } from './error/trace/trace';
export { Exception, causedBy, chainStack, exception, fault, isException, isNotException, } from './exception/exception';
export { panic, rethrow, rethrows, throws, } from './panic/panic';
//# sourceMappingURL=index.d.ts.map

@@ -1,30 +0,10 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var error_1 = require("./error/error");
Object.defineProperty(exports, "error", { enumerable: true, get: function () { return error_1.error; } });
Object.defineProperty(exports, "isError", { enumerable: true, get: function () { return error_1.isError; } });
Object.defineProperty(exports, "isNotError", { enumerable: true, get: function () { return error_1.isNotError; } });
var eval_error_1 = require("./error/eval-error");
Object.defineProperty(exports, "evalError", { enumerable: true, get: function () { return eval_error_1.evalError; } });
Object.defineProperty(exports, "isEvalError", { enumerable: true, get: function () { return eval_error_1.isEvalError; } });
Object.defineProperty(exports, "isNotEvalError", { enumerable: true, get: function () { return eval_error_1.isNotEvalError; } });
var range_error_1 = require("./error/range-error");
Object.defineProperty(exports, "isNotRangeError", { enumerable: true, get: function () { return range_error_1.isNotRangeError; } });
Object.defineProperty(exports, "isRangeError", { enumerable: true, get: function () { return range_error_1.isRangeError; } });
Object.defineProperty(exports, "rangeError", { enumerable: true, get: function () { return range_error_1.rangeError; } });
var reference_error_1 = require("./error/reference-error");
Object.defineProperty(exports, "isNotReferenceError", { enumerable: true, get: function () { return reference_error_1.isNotReferenceError; } });
Object.defineProperty(exports, "isReferenceError", { enumerable: true, get: function () { return reference_error_1.isReferenceError; } });
Object.defineProperty(exports, "referenceError", { enumerable: true, get: function () { return reference_error_1.referenceError; } });
var syntax_error_1 = require("./error/syntax-error");
Object.defineProperty(exports, "isNotSyntaxError", { enumerable: true, get: function () { return syntax_error_1.isNotSyntaxError; } });
Object.defineProperty(exports, "isSyntaxError", { enumerable: true, get: function () { return syntax_error_1.isSyntaxError; } });
Object.defineProperty(exports, "syntaxError", { enumerable: true, get: function () { return syntax_error_1.syntaxError; } });
var type_error_1 = require("./error/type-error");
Object.defineProperty(exports, "isNotTypeError", { enumerable: true, get: function () { return type_error_1.isNotTypeError; } });
Object.defineProperty(exports, "isTypeError", { enumerable: true, get: function () { return type_error_1.isTypeError; } });
Object.defineProperty(exports, "typeError", { enumerable: true, get: function () { return type_error_1.typeError; } });
var panic_1 = require("./panic/panic");
Object.defineProperty(exports, "panic", { enumerable: true, get: function () { return panic_1.panic; } });
Object.defineProperty(exports, "throws", { enumerable: true, get: function () { return panic_1.throws; } });
export { error, errorOutput, isError, isNotError, stack, } from './error/error';
export { evalError, isEvalError, isNotEvalError, } from './error/eval-error';
export { isNotRangeError, isRangeError, rangeError, } from './error/range-error';
export { isNotReferenceError, isReferenceError, referenceError, } from './error/reference-error';
export { isNotSyntaxError, isSyntaxError, syntaxError, } from './error/syntax-error';
export { isNotTypeError, isTypeError, typeError, } from './error/type-error';
export { stackTrace, trace, } from './error/trace/trace';
export { Exception, causedBy, chainStack, exception, fault, isException, isNotException, } from './exception/exception';
export { panic, rethrow, rethrows, throws, } from './panic/panic';
//# sourceMappingURL=index.js.map

@@ -1,3 +0,8 @@

export declare function throws<E extends Error>(error?: E | string): never;
export declare function panic<E extends Error>(error?: E | string): () => never;
import { ExceptionContext } from '../exception/exception-context';
export declare function throws<E extends Error>(message: string, context?: ExceptionContext): never;
export declare function throws<E extends Error>(error: E | string): never;
export declare function panic<E extends Error>(message: string, context?: ExceptionContext): () => never;
export declare function panic<E extends Error>(error: E | string): () => never;
export declare function rethrows(previous: Error, message: string, context?: ExceptionContext): never;
export declare function rethrow(message: string, context?: ExceptionContext): (previous: Error) => never;
//# sourceMappingURL=panic.d.ts.map

@@ -1,16 +0,18 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.panic = exports.throws = void 0;
var error_1 = require("../error/error");
function throws(error) {
if (error !== void 0 && error_1.isError(error)) {
import { isError } from '../error/error';
import { Exception, causedBy } from '../exception/exception';
export function throws(error, context = {}) {
if (isError(error)) {
throw error;
}
throw new Error(error);
throw new Exception(error, context, null);
}
exports.throws = throws;
function panic(error) {
return function () { return throws(error); };
export function panic(error, context = {}) {
return () => (isError(error) ? throws(error) : throws(error, context));
}
exports.panic = panic;
export function rethrows(previous, message, context = {}) {
throw new Exception(message, context, previous);
}
export function rethrow(message, context = {}) {
return (error) => throws(causedBy(error, message, context));
}
//# sourceMappingURL=panic.js.map

@@ -1,32 +0,58 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var panic_1 = require("./panic");
describe('throws', function () {
it('throws an Error without a message', function () {
expect(panic_1.throws)
.toThrow(Error);
import { rangeError } from '../error/range-error';
import { referenceError } from '../error/reference-error';
import { Exception } from '../exception/exception';
import { panic, rethrow, rethrows, throws } from './panic';
describe('throws', () => {
it('throws an Exception with a message', () => {
expect(() => throws('Failure'))
.toThrow('Failure');
expect(() => throws('Failure'))
.toThrow(Exception);
});
it('throws an Error with a message', function () {
expect(function () { return panic_1.throws('Failure'); })
.toThrow(new Error('Failure'));
it('throws an Exception with a message and context', () => {
expect(() => throws('Failed to load user {{id}}', {
id: '42',
})).toThrow('Failed to load user `42`');
});
it('throws a custom error', function () {
expect(function () { return panic_1.throws(new TypeError()); })
it('throws a custom error', () => {
expect(() => throws(new TypeError()))
.toThrow(TypeError);
});
});
describe('panic', function () {
it('creates a function that throws an Error without a message', function () {
expect(function () { return panic_1.panic()(); })
.toThrow(Error);
describe('panic', () => {
it('creates a function that throws an Exception with a message', () => {
expect(panic('Failure'))
.toThrow('Failure');
expect(panic('Failure'))
.toThrow(Exception);
});
it('creates a function that throws an Error with a message', function () {
expect(function () { return panic_1.panic('Failure')(); })
.toThrow(new Error('Failure'));
it('creates a function that throws an Exception with a message and context', () => {
expect(panic('Failed to load user {{id}}', {
id: '42',
})).toThrow('Failed to load user `42`');
});
it('creates a function that throws a custom error', function () {
expect(function () { return panic_1.panic(new TypeError())(); })
it('creates a function that throws a custom error', () => {
expect(panic(new TypeError()))
.toThrow(TypeError);
});
});
describe('rethrows', () => {
it('throws a Exception with the previous error', () => {
expect(() => rethrows(rangeError('Invalid code point -1'), 'Failed to process input'))
.toThrow('Failed to process input');
expect(() => rethrows(rangeError('Invalid code point -1'), 'Failed to process input {{value}}', {
value: '-1',
})).toThrow('Failed to process input `-1`');
});
});
describe('rethrow', () => {
describe('rethrow(message)', () => {
it('throws a Exception with the previous error', () => {
expect(() => rethrow('Unknown property')(referenceError('reference to undefined property "x"'))).toThrow('Unknown property');
expect(() => rethrow('Unknown property {{key}}', {
key: 'x',
})(referenceError('reference to undefined property "x"'))).toThrow('Unknown property `x`');
});
});
});
//# sourceMappingURL=panic.spec.js.map
{
"name": "@perfective/error",
"version": "0.1.1",
"version": "0.2.0-alpha",
"description": "Functions for the Error and other types to handle exceptions",
"keywords": [
"error",
"error chaining",
"error handling",
"exception",
"exception chaining",
"exception handling",
"panic",
"stack trace",
"throwable",
"es6",
"es2015"
],
"author": "Andrey Mikheychik <a.mikheychik@gmail.com>",

@@ -17,8 +30,10 @@ "homepage": "https://github.com/perfective/js",

"build:clean": "npm run clean && npm run build",
"clean": "rm -rf dist && rm -f *.tsbuildinfo && jest --clearCache",
"clean": "rm -rf dist && rm -f *.tsbuildinfo",
"lint": "npm run lint:eslint; npm run lint:tslint",
"lint:eslint": "eslint --fix --ext .ts ./src",
"lint:tslint": "tslint --fix --project ./tsconfig.lint.json",
"test": "jest"
"test": "jest",
"test:clean": "jest --clearCache",
"test:verbose": "jest --verbose"
}
}
# Error
The `@perfective/error` package provides functions for the
The `@perfective/error` package helps organize exceptions and error handling.
It defines an `Exception`, based on the JS
[`Error`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error) class
and other error types.
that supports localizable error messages and error chaining;
and provides functions to handle error stack output.
* `throws<E extends Error>(error?: E | string): never`
— throws a provided error.
* `panic<E extends Error>(error?: E | string): () => never`
— creates a function that throws a provided error.
Read the [full documentation](https://github.com/perfective/js/blob/master/packages/error/README.adoc)
in the repository.
* `Exception`:
* `Exception.toString()`
— outputs the stack of all error messages.
* `exception(message: string, context: ExceptionContext = {}): Exception`
— creates a new `Exception` without a previous error.
* `causedBy(previous: Error, message: string, context: ExceptionContext = {}): Exception`
— creates a new `Exception` with a previous error.
* `isException<T>(value: Exception | T): value is Exception`
— returns `true` when value is an `Exception`.
* `isNotException<T>(value: Exception | T): value is T`
— returns `true` when value is not an `Exception`.
* `chainStack(error: Error): string`
— outputs the stack of all errors with their stack trace.
* `fault(error: Error): Error`
— returns the first error in the chain.
* Throwing errors:
* `throws<E extends Error>(error: E): never`
— throws a provided error.
* `throws<E extends Error>(message: string, context: ExceptionContext = {}): never`
— creates and throws an `Exception` with the given `message` and `context`.
* `panic<E extends Error>(error: E): () => never`
— creates a function that throws a provided error.
* `panic<E extends Error>(message: string, context: ExceptionContext = {}): () => never`
— creates a function that throws an `Exception` with the given `message` and `context`.
* `rethrows(previous: Error, message: string, context: ExceptionContext = {}): never`
— creates and throws an exception with the given `message`, `context`, and `previous` error.
* `rethrow(message: string, context: ExceptionContext = {}): (previous: Error) => never`
— creates a function that throws an exception with the given `message`, `context`,
and `previous` error.
* [`Error`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error):

@@ -53,4 +83,1 @@ * `error(message?: string): Error`

— returns `true` when the value is not an instance of `TypeError`.
Read the [full documentation](https://github.com/perfective/js/blob/master/packages/error/README.adoc)
in the repository.

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

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

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

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

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