@grimen/mybad
Advanced tools
Comparing version 0.2.0 to 0.2.1
{ | ||
"name": "@grimen/mybad", | ||
"version": "0.2.0", | ||
"version": "0.2.1", | ||
"description": "My friendly error base class - for Node/JavaScript.", | ||
@@ -43,6 +43,6 @@ "keywords": [ | ||
"devDependencies": { | ||
"babel-eslint": "^10.0.1", | ||
"eslint": "^5.14.1", | ||
"jest": "^24.1.0", | ||
"jest-tobetype": "^1.2.2", | ||
"babel-eslint": "^10.0.2", | ||
"eslint": "^6.0.1", | ||
"jest": "^24.8.0", | ||
"jest-tobetype": "^1.2.3", | ||
"strip-ansi": "^5.2.0" | ||
@@ -49,0 +49,0 @@ }, |
@@ -221,2 +221,7 @@ | ||
## Related | ||
- [**`python-mybad`**](https://github.com/grimen/python-mybase) - *"My friendly error base class - for Python"* | ||
## About | ||
@@ -223,0 +228,0 @@ |
@@ -46,6 +46,2 @@ | ||
// error = error || args.find((arg) => { | ||
// return (typeof arg === 'string') | ||
// }) | ||
if (error) { | ||
@@ -69,3 +65,10 @@ if (!(error instanceof Error)) { | ||
if (!error) { | ||
if (error) { | ||
id = id || error.id | ||
key = key || error.key | ||
code = code || error.code | ||
message = message || error.message | ||
details = details || error.details | ||
} else { | ||
error = options.error | ||
@@ -72,0 +75,0 @@ } |
@@ -26,7 +26,7 @@ /* global jest describe test expect */ | ||
process.COLORS = false | ||
process.ERROR_COLORS = false | ||
process.env.COLORS = false | ||
process.env.ERROR_COLORS = false | ||
process.VERBOSE = false | ||
process.ERROR_VERBOSE = false | ||
process.env.VERBOSE = false | ||
process.env.ERROR_VERBOSE = false | ||
@@ -64,3 +64,3 @@ | ||
const someRaisedError = new TypeError('No good') | ||
let someRaisedError = new TypeError('No good') | ||
@@ -71,2 +71,7 @@ error = new mybad.Error(someRaisedError) | ||
expect(error.error.toString()).toEqual('TypeError: No good') | ||
error = new mybad.Error(error) | ||
expect(error.error).toBeInstanceOf(mybad.Error) | ||
expect(error.error.toString()).toEqual('No good') | ||
}) | ||
@@ -94,2 +99,7 @@ | ||
expect(error.id).toEqual('123') | ||
error = new mybad.Error(error) | ||
expect(error.id).toBeType('string') | ||
expect(error.id).toEqual('123') | ||
}) | ||
@@ -117,2 +127,7 @@ | ||
expect(error.key).toEqual('123') | ||
error = new mybad.Error(error) | ||
expect(error.key).toBeType('string') | ||
expect(error.key).toEqual('123') | ||
}) | ||
@@ -140,2 +155,7 @@ | ||
expect(error.code).toEqual('123') | ||
error = new mybad.Error(error) | ||
expect(error.code).toBeType('string') | ||
expect(error.code).toEqual('123') | ||
}) | ||
@@ -164,2 +184,7 @@ | ||
expect(error.message).toEqual('123') | ||
error = new mybad.Error(error) | ||
expect(error.message).toBeType('string') | ||
expect(error.message).toEqual('123') | ||
}) | ||
@@ -200,2 +225,10 @@ | ||
}) | ||
error = new mybad.Error(error) | ||
expect(error.details).toBeType('object') | ||
expect(error.details).toEqual({ | ||
foo: 'bar', | ||
baz: [1, 2, 3], | ||
}) | ||
}) | ||
@@ -210,2 +243,7 @@ | ||
expect(error.stacktrace.length).toBeGreaterThan(0) | ||
error = new mybad.Error(error) | ||
expect(error.stack).toBeType('string') | ||
expect(error.stacktrace.length).toBeGreaterThan(0) | ||
}) | ||
@@ -220,2 +258,7 @@ | ||
expect(error.stacktrace.length).toBeGreaterThan(0) | ||
error = new mybad.Error(error) | ||
expect(error.stacktrace).toBeType('string') | ||
expect(error.stacktrace.length).toBeGreaterThan(0) | ||
}) | ||
@@ -230,2 +273,7 @@ | ||
expect(error.stackframes.length).toBeGreaterThan(0) | ||
error = new mybad.Error(error) | ||
expect(error.stackframes).toBeType('array') | ||
expect(error.stackframes.length).toBeGreaterThan(0) | ||
}) | ||
@@ -244,4 +292,15 @@ | ||
expect(error.stackobjects[0].function).toEqual(expect.stringMatching(/^Object\.(?:test|<anonymous>|mybad\.Error)$/)) | ||
expect(error.stackobjects[0].line).toEqual(223) | ||
expect(error.stackobjects[0].line).toEqual(271) | ||
expect(error.stackobjects[0].source).toEqual(undefined) | ||
error = new mybad.Error(error) | ||
expect(error.stackobjects).toBeType('array') | ||
expect(error.stackobjects.length).toBeGreaterThan(0) | ||
expect(error.stackobjects[0]).toBeType('object') | ||
expect(error.stackobjects[0].column).toEqual(expect.any(Number)) | ||
expect(error.stackobjects[0].file).toEqual(`${ROOT_PATH}/test/test_errors.js`) | ||
expect(error.stackobjects[0].function).toEqual(expect.stringMatching(/^Object\.(?:test|<anonymous>|mybad\.Error)$/)) | ||
expect(error.stackobjects[0].line).toEqual(284) | ||
expect(error.stackobjects[0].source).toEqual(undefined) | ||
}) | ||
@@ -276,4 +335,21 @@ | ||
expect(error.data.stack[0].function).toEqual(expect.stringMatching(/^Object\.(?:test|<anonymous>|mybad\.Error)$/)) | ||
expect(error.data.stack[0].line).toEqual(238) | ||
expect(error.data.stack[0].line).toEqual(297) | ||
expect(error.data.stack[0].source).toEqual(undefined) | ||
error = new mybad.Error(error) | ||
expect(error.data.type).toEqual('BaseError') | ||
expect(error.data.id).toEqual(undefined) | ||
expect(error.data.code).toEqual(undefined) | ||
expect(error.data.key).toEqual(undefined) | ||
expect(error.data.message).toEqual('Unknown') | ||
expect(error.data.details).toEqual({}) | ||
expect(error.data.stack.length).toBeGreaterThan(0) | ||
expect(error.data.stack[0]).toBeType('object') | ||
expect(error.data.stack[0].column).toEqual(expect.any(Number)) | ||
expect(error.data.stack[0].file).toEqual(`${ROOT_PATH}/test/test_errors.js`) | ||
expect(error.data.stack[0].function).toEqual(expect.stringMatching(/^Object\.(?:test|<anonymous>|mybad\.Error)$/)) | ||
expect(error.data.stack[0].line).toEqual(326) | ||
expect(error.data.stack[0].source).toEqual(undefined) | ||
}) | ||
@@ -286,7 +362,7 @@ | ||
const json = error.json() | ||
let json = error.json() | ||
expect(json).toBeType('string') | ||
const data = JSON.parse(json) | ||
let data = JSON.parse(json) | ||
@@ -308,4 +384,28 @@ expect(data.type).toBeType('string') | ||
expect(data.stack[0].function).toEqual(expect.stringMatching(/^Object\.(?:test|<anonymous>|mybad\.Error)$/)) | ||
expect(data.stack[0].line).toEqual(269) | ||
expect(data.stack[0].line).toEqual(345) | ||
expect(data.stack[0].source).toEqual(undefined) | ||
error = new mybad.Error(error) | ||
json = error.json() | ||
data = JSON.parse(json) | ||
expect(data.type).toBeType('string') | ||
expect(data.type).toEqual('BaseError') | ||
expect(data.message).toBeType('string') | ||
expect(data.message).toEqual('Unknown') | ||
expect(data.details).toBeType('object') | ||
expect(data.details).toEqual({}) | ||
expect(data.stack).toBeType('array') | ||
expect(data.stack.length).toBeGreaterThan(0) | ||
expect(data.stack[0]).toBeType('object') | ||
expect(data.stack[0].column).toEqual(expect.any(Number)) | ||
expect(data.stack[0].file).toEqual(`${ROOT_PATH}/test/test_errors.js`) | ||
expect(data.stack[0].function).toEqual(expect.stringMatching(/^Object\.(?:test|<anonymous>|mybad\.Error)$/)) | ||
expect(data.stack[0].line).toEqual(373) | ||
expect(data.stack[0].source).toEqual(undefined) | ||
}) | ||
@@ -321,2 +421,8 @@ | ||
}).toNotThrow | ||
error = new mybad.Error(error) | ||
expect(() => { | ||
error.inspect() | ||
}).toNotThrow | ||
}) | ||
@@ -343,2 +449,14 @@ | ||
expect(stripAnsi(error.toString())).toEqual('Boo-hoo') | ||
error = new mybad.Error(error) | ||
expect(stripAnsi(error.toString())).toBeType('string') | ||
expect(stripAnsi(error.toString())).toEqual('Boo-hoo') | ||
error = new mybad.Error(error, { | ||
message: 'Boo-hoo', | ||
}) | ||
expect(stripAnsi(error.toString())).toBeType('string') | ||
expect(stripAnsi(error.toString())).toEqual('Boo-hoo') | ||
}) | ||
@@ -386,3 +504,3 @@ | ||
expect(errorObject.stack[0].function).toEqual(expect.stringMatching(/^Object\.(?:test|<anonymous>|mybad\.Error)$/)) | ||
expect(errorObject.stack[0].line).toEqual(344) | ||
expect(errorObject.stack[0].line).toEqual(462) | ||
expect(errorObject.stack[0].source).toEqual(undefined) | ||
@@ -417,3 +535,3 @@ | ||
expect(errorObject.stack[0].function).toEqual(expect.stringMatching(/^Object\.(?:test|<anonymous>|mybad\.Error)$/)) | ||
expect(errorObject.stack[0].line).toEqual(374) | ||
expect(errorObject.stack[0].line).toEqual(492) | ||
expect(errorObject.stack[0].source).toEqual(undefined) | ||
@@ -446,3 +564,3 @@ | ||
expect(errorObject.stack[0].function).toEqual(expect.stringMatching(/^Object\.(?:test|<anonymous>|mybad\.Error)$/)) | ||
expect(errorObject.stack[0].line).toEqual(402) | ||
expect(errorObject.stack[0].line).toEqual(520) | ||
expect(errorObject.stack[0].source).toEqual(undefined) | ||
@@ -449,0 +567,0 @@ }) |
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 4 instances in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
39956
760
234