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

extended-exceptions

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

extended-exceptions - npm Package Compare versions

Comparing version 2.0.2 to 2.1.0

2

bower.json
{
"name": "extended-exceptions.js",
"version": "2.0.2",
"version": "2.1.0",
"description": "Easy custom js exceptions for node & browser, AMD.",

@@ -5,0 +5,0 @@ "keywords": [

@@ -24,3 +24,3 @@ /* New Errors to be thrown,

define(function() {
"use strict";
'use strict';

@@ -55,3 +55,4 @@ // Note : extending js errors is not trivial at all ! cf.

// we must create an error to have an up-to-date stacktrace
message = message_or_error;
// we must handle cases where given message is not a string
message = '' + (message_or_error || '');
err = new Error(message);

@@ -63,7 +64,8 @@ }

// We must copy manually due to Error object specificity.
this.message = message; // assign directly from param. If we assign from err.message, FF sometimes fails to copy for unknown reasons
this.message = message; // assign directly from param.
// If we assign from err.message, FF sometimes fails to copy for unknown reasons
this.stack = err.stack;
// fix stuff
this.name = "ExtendedError";
this.name = 'ExtendedError';
}

@@ -82,8 +84,5 @@ ExtendedError.prototype = Object.create(error_instance.prototype); // since we can't directly access Error.prototype

function CustomExtendedErrorClass() {
//console.log("CustomExtendedErrorClass[" + name + "] constructor with args... ");
//console.log(arguments);
// Call the parent constructor
ParentErrorClass.prototype.constructor.apply(this, arguments);
this.name = name;
//console.log("CustomExtendedErrorClass[" + name + "].message = " + this.message);
}

@@ -106,6 +105,6 @@ CustomExtendedErrorClass.prototype = Object.create(ParentErrorClass.prototype);

// (e.g., violations of class invariants).
extended_exceptions.LogicError = create_custom_error("LogicError");
extended_exceptions.LogicError = create_custom_error('LogicError');
// invalid_argument thr. to report invalid arguments to functions.
extended_exceptions.InvalidArgument = create_custom_error("InvalidArgument", extended_exceptions.LogicError);
extended_exceptions.InvalidArgument = create_custom_error('InvalidArgument', extended_exceptions.LogicError);

@@ -115,3 +114,3 @@ // length_error thr. when an object is constructed

// (e.g., a basic_string instance).
extended_exceptions.LengthError = create_custom_error("LengthError", extended_exceptions.LogicError);
extended_exceptions.LengthError = create_custom_error('LengthError', extended_exceptions.LogicError);

@@ -121,3 +120,3 @@ // out_of_range indicate an argument whose value

// (e.g., boundary checks in basic_string).
extended_exceptions.OutOfRange = create_custom_error("OutOfRange", extended_exceptions.LogicError);
extended_exceptions.OutOfRange = create_custom_error('OutOfRange', extended_exceptions.LogicError);

@@ -127,3 +126,3 @@ // runtime_error represent problems outside the scope

// and can generally only be caught as the program executes.
extended_exceptions.RuntimeError = create_custom_error("RuntimeError");
extended_exceptions.RuntimeError = create_custom_error('RuntimeError');

@@ -134,6 +133,6 @@

// when we encounter code not implemented
extended_exceptions.NotImplemented = create_custom_error("NotImplemented", extended_exceptions.RuntimeError);
extended_exceptions.NotImplemented = create_custom_error('NotImplemented', extended_exceptions.RuntimeError);
// when we switch case on an enumerated var and don't recognize a value (usually a newly added one)
extended_exceptions.UnknownEnumValue = create_custom_error("UnknownEnumValue", extended_exceptions.RuntimeError);
extended_exceptions.UnknownEnumValue = create_custom_error('UnknownEnumValue', extended_exceptions.RuntimeError);

@@ -143,8 +142,8 @@ // Signals that a method has been invoked at an illegal or inappropriate time.

// requested operation.
extended_exceptions.IllegalState = create_custom_error("IllegalState", extended_exceptions.RuntimeError);
extended_exceptions.IllegalState = create_custom_error('IllegalState', extended_exceptions.RuntimeError);
// Signals that an invariant (= stuff the should always be true) is not met
// Signals that an invariant (= stuff that should always be true) is not met
// This should, of course, never happen...
// https://en.wikipedia.org/wiki/Invariant_%28computer_science%29
extended_exceptions.InvariantNotMet = create_custom_error("InvariantNotMet", extended_exceptions.LogicError);
extended_exceptions.InvariantNotMet = create_custom_error('InvariantNotMet', extended_exceptions.LogicError);

@@ -151,0 +150,0 @@

{
"name": "extended-exceptions",
"version": "2.0.2",
"version": "2.1.0",
"description": "Easy custom js exceptions for node & browser, AMD.",

@@ -15,3 +15,3 @@ "keywords": "exceptions, browser, server",

"dependencies": {
"amdefine": "~0.1"
"amdefine": "^0.1"
},

@@ -18,0 +18,0 @@ "engines": {

@@ -10,6 +10,5 @@ if (typeof define !== 'function') { var define = require('amdefine')(module); }

function(chai, EE) {
"use strict";
'use strict';
var expect = chai.expect;
chai.should();

@@ -20,32 +19,49 @@ describe('Extended exceptions', function() {

/*it('test', function() {
var out = new Error("Test error");
out.should.exist;
out.message.should.equals("Test error");
});*/
it('should inherit from Error', function() {
var out = new EE.ExtendedError("Test error");
out.should.exist;
var out = new EE.ExtendedError('Test error');
expect(out).to.exist;
out.should.be.an('object');
out.should.be.an.instanceof(Error);
out.should.be.an.instanceof(EE.ExtendedError);
expect(out).to.be.an('object');
expect(out).to.be.an.instanceof(Error);
expect(out).to.be.an.instanceof(EE.ExtendedError);
});
it('should behave like an Error', function() {
var out = new EE.ExtendedError("Test error");
var out = new EE.ExtendedError('Test error');
out.name.should.equals("ExtendedError");
out.message.should.equals("Test error");
out.stack.should.not.be.empty;
expect(out.name).to.equals('ExtendedError');
expect(out.message).to.equals('Test error');
expect(out.stack).not.to.be.empty;
});
// some 3rd party libs expect that
// see also GitHub issue #1
describe('message property systematic generation', function() {
it('should be done when none given', function() {
var out = new EE.ExtendedError(/* no param */);
expect(out.message).to.equals(''); // empty but not undefined
});
it('should be done when wrapping another error with none given', function() {
var base_err = new Error();
var out = new EE.ExtendedError(base_err);
expect(out.message).to.equals(''); // empty but not undefined
});
it('should be done when given a non-string object', function() {
var out = new EE.ExtendedError({foo: 'bar'});
expect(out.message).to.be.a('string');
expect(out.message).not.to.be.empty; // stringification may vary amongst interpreters
});
});
it('should allow wrapping/retyping of an existing Error', function() {
var base_err = new Error("Test error");
var base_err = new Error('Test error');
var out = new EE.ExtendedError(base_err);
out.name.should.equals("ExtendedError");
out.message.should.equals("Test error");
out.stack.should.not.be.empty;
expect(out.name).to.equals('ExtendedError');
expect(out.message).to.equals('Test error');
expect(out.stack).not.to.be.empty;
expect( out.stack ).to.equals(base_err.stack);

@@ -55,4 +71,4 @@ });

it('should work along chai expectations', function() {
var tempfn = function() {throw new EE.IllegalState("Not started !"); };
tempfn.should.throw(EE.IllegalState, "Not started !");
var tempfn = function() {throw new EE.IllegalState('Not started !'); };
expect(tempfn).to.throw(EE.IllegalState, 'Not started !');
});

@@ -63,20 +79,20 @@

var test_extended_error = function(CustomErrorClass, custom_error_name, ParentErrorClass) {
var out = new CustomErrorClass("test_extended_error 1");
out.should.exist;
var out = new CustomErrorClass('test_extended_error 1');
expect(out).to.exist;
out.should.be.an.instanceof(CustomErrorClass);
out.should.be.an.instanceof(ParentErrorClass);
expect(out).to.be.an.instanceof(CustomErrorClass);
expect(out).to.be.an.instanceof(ParentErrorClass);
out.name.should.equals(custom_error_name);
out.message.should.equals("test_extended_error 1");
out.stack.should.not.be.empty;
expect(out.name).to.equals(custom_error_name);
expect(out.message).to.equals('test_extended_error 1');
expect(out.stack).not.to.be.empty;
// should be throwable of course
try {
throw new CustomErrorClass("test_extended_error 2");
expect(false).to.be.true;
throw new CustomErrorClass('test_extended_error 2');
expect(false).to.be.true; // should never arrive here
}
catch(e) {
e.should.be.an.instanceof(CustomErrorClass);
e.message.should.equals("test_extended_error 2");
expect(e).to.be.an.instanceof(CustomErrorClass);
expect(e.message).to.equals('test_extended_error 2');
}

@@ -86,5 +102,5 @@

var tempfn = function() {
throw new CustomErrorClass("test_extended_error 3");
throw new CustomErrorClass('test_extended_error 3');
}
tempfn.should.throw(CustomErrorClass, "test_extended_error 3");
expect(tempfn).to.throw(CustomErrorClass, 'test_extended_error 3');
};

@@ -95,5 +111,5 @@

it('should allow easy creation of a custom error which works', function() {
var CustomError = EE.create_custom_error("CustomError", EE.RuntimeError);
var CustomError = EE.create_custom_error('CustomError', EE.RuntimeError);
test_extended_error(CustomError, "CustomError", EE.RuntimeError );
test_extended_error(CustomError, 'CustomError', EE.RuntimeError );
});

@@ -106,3 +122,3 @@ }); // describe feature

it('should work', function() {
test_extended_error(EE.LogicError, "LogicError", EE.ExtendedError );
test_extended_error(EE.LogicError, 'LogicError', EE.ExtendedError );
});

@@ -113,3 +129,3 @@ }); // describe feature

it('should work', function() {
test_extended_error(EE.InvalidArgument, "InvalidArgument", EE.LogicError );
test_extended_error(EE.InvalidArgument, 'InvalidArgument', EE.LogicError );
});

@@ -120,3 +136,3 @@ }); // describe feature

it('should work', function() {
test_extended_error(EE.LengthError, "LengthError", EE.LogicError );
test_extended_error(EE.LengthError, 'LengthError', EE.LogicError );
});

@@ -127,3 +143,3 @@ }); // describe feature

it('should work', function() {
test_extended_error(EE.OutOfRange, "OutOfRange", EE.LogicError );
test_extended_error(EE.OutOfRange, 'OutOfRange', EE.LogicError );
});

@@ -134,3 +150,3 @@ }); // describe feature

it('should work', function() {
test_extended_error(EE.RuntimeError, "RuntimeError", EE.ExtendedError );
test_extended_error(EE.RuntimeError, 'RuntimeError', EE.ExtendedError );
});

@@ -141,3 +157,3 @@ }); // describe feature

it('should work', function() {
test_extended_error(EE.NotImplemented, "NotImplemented", EE.RuntimeError );
test_extended_error(EE.NotImplemented, 'NotImplemented', EE.RuntimeError );
});

@@ -148,3 +164,3 @@ }); // describe feature

it('should work', function() {
test_extended_error(EE.UnknownEnumValue, "UnknownEnumValue", EE.RuntimeError );
test_extended_error(EE.UnknownEnumValue, 'UnknownEnumValue', EE.RuntimeError );
});

@@ -155,3 +171,3 @@ }); // describe feature

it('should work', function() {
test_extended_error(EE.IllegalState, "IllegalState", EE.RuntimeError );
test_extended_error(EE.IllegalState, 'IllegalState', EE.RuntimeError );
});

@@ -162,3 +178,3 @@ }); // describe feature

it('should work', function() {
test_extended_error(EE.InvariantNotMet, "InvariantNotMet", EE.LogicError );
test_extended_error(EE.InvariantNotMet, 'InvariantNotMet', EE.LogicError );
});

@@ -169,2 +185,1 @@ }); // describe feature

});
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