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

typed-errors

Package Overview
Dependencies
Maintainers
3
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

typed-errors - npm Package Compare versions

Comparing version 1.0.1 to 1.1.0

3

package.json
{
"name": "typed-errors",
"version": "1.0.1",
"version": "1.1.0",
"description": "Create custom error types that work with `instanceof` and have stack traces",

@@ -19,2 +19,3 @@ "license": "BSD-2-Clause",

"dependencies": {
"underscore": "^1.8.3"
},

@@ -21,0 +22,0 @@ "devDependencies": {

@@ -1,12 +0,18 @@

var makeTypedError = function (name) {
var _ = require('underscore');
var makeTypedError = function (name, Supertype) {
Supertype = Supertype || Error;
var TypedError = function (message) {
var sup = new Supertype(message);
_(this).extend(sup);
this.name = name;
this.message = message;
var tempStack = (new Error()).stack;
// replace 'Error' with actual name in stack trace
this.stack = this.name + tempStack.slice(5);
this.stack = sup.stack.replace(/^[^:]+:/, name + ':');
};
TypedError.prototype = Object.create(Error.prototype);
TypedError.prototype = Object.create(Supertype.prototype);
TypedError.prototype.constructor = TypedError;

@@ -13,0 +19,0 @@

@@ -11,3 +11,3 @@ require('should');

try {
throw new FooException('Foobar!');
throw new FooException('Exn_Message');
} catch (e) {

@@ -22,3 +22,3 @@ e.should.be.an.instanceof(FooException);

try {
throw new FooException('Foobar!');
throw new FooException('Exn_Message');
} catch (e) {

@@ -31,5 +31,5 @@ e.should.not.be.an.instanceof(CopyOfFooException);

try {
throw new FooException('Foobar!');
throw new FooException('Exn_Message');
} catch (e) {
e.message.should.equal('Foobar!');
e.message.should.equal('Exn_Message');
}

@@ -40,6 +40,6 @@ });

try {
throw new FooException('Foobar!');
throw new FooException('Exn_Message');
} catch (e) {
// starts with correct name and where it was thrown from
e.stack.should.match(/^FooException\n {4}at new TypedError \(\S+make-typed-error.js:\d+:\d+\)/);
e.stack.should.match(/^FooException: Exn_Message\n {4}at new TypedError \(\S+make-typed-error.js:\d+:\d+\)/);
// eventually points to where it was thrown in this very file

@@ -46,0 +46,0 @@ e.stack.should.match(/\(\S+make-typed-error.spec.js:\d+:\d+\)/);

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