1.0.1 • Published 4 years ago
nv-facutil-throw v1.0.1
nv-facutil-throw
- nv-facutil-throw is a simple-util for built-in errors
- include dump-to-json ans load-from-json
- support nested AggregateError
install
- npm install nv-facutil-throw
usage
const er = require("nv-facutil-throw")
example
aggregate error
var agg0 = er.agg([er.synx('s'),er.uri('u'),er.ref('r')],'agg')
var agg1 = er.agg([er.typ('t'),agg0,er.rng('rng')],'nest-agg')
> agg1
AggregateError: nest-agg
at Object.__M.agg (/opt/JS/NV5_/nv-facutil_/pkgs/nv-facutil-throw/index.js:47:25)
at REPL15:1:15
at Script.runInThisContext (node:vm:131:12)
...
var dumped = er.dump_agg(agg1);
console.log(JSON.stringify(dumped,null,2))
{
message: 'nest-agg',
name: 'AggregateError',
stack: '...',
errors: [
{ message: 't', name: 'TypeError', stack: '....' },
{
message: 'agg',
name: 'AggregateError',
stack: '...',
errors: [Array]
},
{ message: 'rng', name: 'RangeError', stack: '...' }
]
}
> er.from_json(d)
AggregateError: nest-agg
at Object._from_json [as from_json] (/opt/JS/NV5_/nv-facutil_/pkgs/nv-facutil-throw/index.js:77:16)
at REPL98:1:4
....
other errors
> er.synx('s')
SyntaxError: s
at Object.__M.<computed> [as synx] (/opt/JS/NV5_/nv-facutil_/pkgs/nv-facutil-throw/index.js:37:42)
.....
>
> er.throw_synx('s')
Uncaught SyntaxError: s
> er.is_synx(er.synx('s'))
true
>
APIS
- from_json(json):XxxxError
- dump_xxxx(err:XxxxError):JSON
- throw_xxxx(message, fileName, lineNumber)
- throw_agg(errors,message)
- is_xxxx(o):boolean
- xxxx(message, fileName, lineNumber):XxxxError // abbrev of (new XxxxError(....))
LICENSE
- ISC
1.0.1
4 years ago