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

collins-error

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

collins-error - npm Package Compare versions

Comparing version 1.1.0 to 1.2.0

23

libs/error.js

@@ -54,6 +54,10 @@ 'use strict';

static convert (type, error) {
// INFO: given an Error, return a SlackError
let details = { details: error.message };
if (error) {
if (!(error instanceof Error)) {
throw new CoreError('Invalid:Input', 'invalid function call');
}
}
let details = { details: error ? error.message : null };
let convertedError = new CoreError(type, details);
convertedError.stack = error.stack;
convertedError.stack = constructStack(error.stack, convertedError);
return convertedError;

@@ -63,2 +67,15 @@ }

/**
* @summary construct static stack for error
* @param {String} fromStack `.stack` property from error being converted.
* @param {CoreError} constructObj CoreError object to receive stack.
* @return {String} Static stack to be assigned to CoreError object.
*/
function constructStack (fromStack, constructObj) {
return constructObj.stack.split('\n')[0] + '\n' +
fromStack
.replace(/^[^\(]+?[\n$]/gm, '')
.replace(/^Object.<anonymous>\s*\(/gm, '{anonymous}()@');
}
module.exports = CoreError;

2

package.json
{
"name": "collins-error",
"version": "1.1.0",
"version": "1.2.0",
"description": "Custom error class used by the collins system",

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

@@ -30,16 +30,62 @@ 'use strict';

});
describe('convert', () => {
let foreignError = new Error('testing');
it('takes an Error', () => {
Assert.equal(foreignError instanceof Error, true);
Assert.equal(foreignError instanceof CoreError, false);
describe('CoreError#convert', () => {
it('throws if second param is not an Error', () => {
Assert.throws(
() => {
CoreError.convert('TestError', {});
},
'invalid function call'
);
Assert.throws(
() => {
CoreError.convert('TestError', 1);
},
'invalid function call'
);
Assert.throws(
() => {
CoreError.convert('TestError', 'string');
},
'invalid function call'
);
Assert.throws(
() => {
CoreError.convert('TestError', () => {});
},
'invalid function call'
);
});
let convertedError = CoreError.convert('TestError', foreignError);
it('should convert Error into CoreError', () => {
let foreignError = new Error('testing');
let convertedError = CoreError.convert('TestError', foreignError);
Assert.equal(convertedError instanceof CoreError, true);
});
it('should transfer stack trace to new error object', () => {
Assert.equal(convertedError.stack, foreignError.stack);
it('should convert exceptions into CoreError', () => {
try {
throw new Error('test exception');
} catch (exception) {
let convertedError = CoreError.convert('TestError', exception);
Assert.equal(convertedError instanceof CoreError, true);
}
});
it('should contain *shallow* stack from passed exception', () => {
try {
throw new Error('test exception');
} catch (exception) {
let convertedError = CoreError.convert('TestError', exception);
Assert.deepEqual(
exception.stack.split('\n').slice(1, 5),
convertedError.stack.split('\n').slice(1, 5)
);
}
});
it('should contain *shallow* stack from passed error', () => {
let foreignError = new Error('testing');
let convertedError = CoreError.convert('TestError', foreignError);
Assert.deepEqual(
foreignError.stack.split('\n').slice(1, 5),
convertedError.stack.split('\n').slice(1, 5)
);
});
});
});
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