Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Generate error-first callback handlers naturally.
Handle errors via a dedicated error handler function, or by emitting them. Optionally invoke a 2nd function on no error, or regardless of error.
Potentially reduce the number of branches needing tests.
var onError = require('on-error')
// error handler
function handleIt (err) {}
// just do something on error
failToDoSomething(onError(handleIt))
// or emit it
failToDoSomething(onError.emit(emitter))
// if doSomething invokes this generated callback with an error
// handleIt will be called with that error, otherwise our
// anonymous function will be called with all remaining arguments
doSomething(onError(handleIt).otherwise(function (message) {
console.log('will see this: %s', message)
}))
failToDoSomething(onError(handleIt).otherwise(function (message) {
console.log('will NOT see this: %s', message)
}))
// if error handleIt, and always...
failToDoSomething(onError(handleIt).always(function (message) {
console.log('will see this too: %s', message)
}))
// if error handleIt, and always (include error for always func)...
failToDoSomething(onError(handleIt).alwaysWithError(function (err, message) {
console.log('will see this too (with the error): %s, %s', err, message)
}))
// maybe we want to emit the error instead...
var emitter = new EventEmitter().on('error', console.log)
failToDoSomething(onError.emit(emitter).otherwise(function (message) {
// will not get here
}))
// or, *gasp*, chain to a promise
doSomething(onError(reject).otherwise(resolve))
var onError = require('on-error')
Returns a function that when called with a truthy first argument, will execute cb
with said argument.
Returns a function that when called with a truthy first argument, will emit error
on the provided event emitter
with said argument.
Returns a function that when called with a truthy first argument, will execute cb1
with said argument. When executed with a non-truthy 1st argument, cb2
will instead be executed with the error argument stripped.
.otherwise
may also be chained from onError.emit()
Returns a function that when called with a truthy first argument, will execute cb1
with said argument. When executed with a non-truthy 1st argument, cb2
will instead be executed with the error argument in-tact.
.otherwiseWithError
may also be chained from onError.emit()
Returns a function that when called with a truthy first argument, will execute cb1
with said argument. In addition, cb2
will always be executed with the error argument stripped.
.always
may also be chained from onError.emit()
Returns a function that when called with a truthy first argument, will execute cb1
with said argument. In addition, cb2
will always be executed with the error argument in-tact.
.alwaysWithError
may also be chained from onError.emit()
npm test [--dot | --spec] [--grep=pattern]
Specifying --dot
or --spec
will change the output from the default TAP style.
Specifying --grep
will only run the test files that match the given pattern.
npm run coverage [--html]
This will output a textual coverage report. Including --html
will also open an HTML coverage report in the default browser.
FAQs
Handle callback errors without the if blocks.
The npm package on-error receives a total of 1,672 weekly downloads. As such, on-error popularity was classified as popular.
We found that on-error 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.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.