Skip to content

Commit

Permalink
v2.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
rjrodger committed Dec 6, 2019
1 parent 9a0cdb8 commit 54cf018
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 26 deletions.
43 changes: 23 additions & 20 deletions eraro.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ function eraro(options) {
var msgprefix =
false === options.prefix
? ''
: 'string' === typeof(options.prefix)
: 'string' === typeof options.prefix
? options.prefix
: 'string' === typeof(options.package)
: 'string' === typeof options.package
? options.package + ': '
: ''

Expand All @@ -77,23 +77,25 @@ function eraro(options) {
details = arguments[2]
}

code = 'string' === typeof(code)
? code
: ex
? ex.code
code =
'string' === typeof code
? code
: ex
? ex.code
: ex.message
? ex.message
? ex.code
: ex.message
? ex.message
: 'unknown'
: 'unknown'
: 'unknown'

details = 'object' === typeof(details)
? details
: 'object' === typeof(msg) && 'string' !== typeof(msg)
? msg
: {}
details =
'object' === typeof details
? details
: 'object' === typeof msg && 'string' !== typeof msg
? msg
: {}

msg = 'string' === typeof(msg) ? msg : null
msg = 'string' === typeof msg ? msg : null
msg = buildmessage(
options,
msg,
Expand Down Expand Up @@ -165,7 +167,7 @@ function callpoint(error, markers) {

var found = false
for (var j = 0; j < markers.length; j++) {
if ('string' === typeof(markers[j])) {
if ('string' === typeof markers[j]) {
found = -1 != line.indexOf(markers[j])
if (found) break
}
Expand All @@ -174,7 +176,7 @@ function callpoint(error, markers) {
if (!found) break line_loop
}

out = 'string' === typeof(lines[i]) ? lines[i].substring(4) : out
out = 'string' === typeof lines[i] ? lines[i].substring(4) : out
}

return out
Expand Down Expand Up @@ -208,9 +210,9 @@ function buildmessage(
) {
var message =
msgprefix +
('string' === typeof(msg)
('string' === typeof msg
? msg
: 'string' === typeof(msgmap[code])
: 'string' === typeof msgmap[code]
? msgmap[code]
: ex
? originalmsg(options.override, ex)
Expand All @@ -237,7 +239,8 @@ function buildmessage(
if ({ undefined: 1, NaN: 1 }[key]) {
key = key + '$'
}
valstrmap[key] = inspect && 'string' !== typeof(val) ? Util.inspect(val) : val
valstrmap[key] =
inspect && 'string' !== typeof val ? Util.inspect(val) : val
})

var done = false
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "eraro",
"version": "1.1.0",
"version": "2.0.0",
"description": "Create JavaScript Error objects with code strings, context details, and templated messages.",
"main": "eraro.js",
"scripts": {
Expand Down
5 changes: 0 additions & 5 deletions test/eraro.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ describe('eraro', function() {
expect(e1.foo).to.be.true()
expect(e1.code).to.equal('c1')
expect(e1.details.a).to.equal(1)

})

it('has', async () => {
Expand Down Expand Up @@ -130,7 +129,6 @@ describe('eraro', function() {
details: { orig$: err, message$: 'x11' }
})
expect(erraror.orig).to.equal(err)

})

it('defined prefix', async () => {
Expand All @@ -144,7 +142,6 @@ describe('eraro', function() {
msg: 'foo: x2',
details: { a: 3, orig$: err, message$: 'x2' }
}) // [Error: x2]

})
})

Expand All @@ -157,7 +154,6 @@ describe('eraro', function() {

var templatedError = eraro('i0', '<%=a%>', { a: { b: 99 } })
expect(templatedError.message).to.equal('foo: { b: 99 }')

})

it('handle different erraros', async () => {
Expand All @@ -166,6 +162,5 @@ describe('eraro', function() {

var barEraro = Eraro({ package: 'bar', prefix: false })
expect(barEraro('code1').message).to.equal('code1')

})
})

0 comments on commit 54cf018

Please sign in to comment.