
Security News
Meet Socket at Black Hat and DEF CON 2025 in Las Vegas
Meet Socket at Black Hat & DEF CON 2025 for 1:1s, insider security talks at Allegiant Stadium, and a private dinner with top minds in software supply chain security.
assertion library that throws user-specified error types (accepts error class and message)
assertion library that throws user-specified error types (accepts error class and message)
npm i --save assert-err
// example-1.js
var assertErr = require('assert-err')
function add (a, b) {
assertErr(typeof a === 'number', TypeError, '"a" must be a number')
assertErr(typeof b === 'number', TypeError, '"b" must be a number') // line 6
return a + b
}
add(1, 'no') // line 10
/*
TypeError: "b" must be a number
at add (example-1.js:6:3)
at Object.<anonymous> (example-1.js:10:1)
at Module._compile (module.js:413:34)
at Object.Module._extensions..js (module.js:422:10)
at Module.load (module.js:357:32)
at Function.Module._load (module.js:314:12)
at Function.Module.runMain (module.js:447:10)
at startup (node.js:139:18)
at node.js:999:3
*/
If using global.Error, assertErr accepts a props
argument to extend error
assertErr(false, Error, 'message', { code: 1, status: 'status' }) // 0 args
// { [Error: boom] code: 1, status: 'status' }
assertErr supports up to 5 err constructor args
assertErr(false, CustomError) // 0 args
assertErr(false, CustomError, 'foo') // 1 args
assertErr(false, CustomError, 'foo', 'bar') // 2 args
assertErr(false, CustomError, 'foo', 'bar', 'qux') // 3 args
assertErr(false, CustomError, 'foo', 'bar', 'qux', 'corge') // 4 args
assertErr(false, CustomError, 'foo', 'bar', 'qux', 'corge', 'yolo') // 5 args
// error...
assertErr(false, CustomError, 'foo', 'bar', 'qux', 'corge', 'yolo', 'toomany') // 6 args
// Error: assertErr does not support more than five Error args
MIT
FAQs
assertion library that throws user-specified error types (accepts error class and message)
We found that assert-err demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Meet Socket at Black Hat & DEF CON 2025 for 1:1s, insider security talks at Allegiant Stadium, and a private dinner with top minds in software supply chain security.
Security News
CAI is a new open source AI framework that automates penetration testing tasks like scanning and exploitation up to 3,600× faster than humans.
Security News
Deno 2.4 brings back bundling, improves dependency updates and telemetry, and makes the runtime more practical for real-world JavaScript projects.