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.
Execute error handler instead of, or in addition to callback, when 1st callback argument is truthy
Handle callback errors by executing an error handler function, or emitting the error, instead of or in addition to executing the callback.
var onError = require('on-error')
function fail (cb) {
cb(new Error('failed'))
}
function succeed (cb) {
cb(null, 'success')
}
Using error handler function:
function handleIt (err) {
console.error(err)
}
fail(onError(handleIt, function (status) {
console.log('will not see this')
}))
fail(onError(handleIt, {alwaysCall: true}, function (err, status) {
// When always call specified, err is passed
console.log('will see this')
}))
succeed(onError(handleIt, function (status) {
// Gets called with status of success
console.log(status)
}))
Using emitter:
var EventEmitter = require('events').EventEmitter
var emitter = new EventEmitter().on('error', function (err) {
console.error(err)
})
fail(onError.emit(emitter, function (status) {
console.log('will not see this')
}))
var onError = require('on-error')
Returns a function that when called with a truthy first argument, will execute the errHandler
with the 1st (error) argument supplied to the wrappedCb. If the option alwaysCall
is define,
the provided cb
will be executed in all cases with all arguments supplied to wrappedCb
, otherwise
if the 1st argument to wrappedCb
is falsey, the supplied cb
will be executed with all but the
1st argument supplied to wrappedCb
.
If no callback cb
is provided, then the generated callback will simply execute errHandler
when
called with a non-falsey 1st argument.
options:
true
or false
- if true, the provided callback cb
will always be called (and include
the 1st argument), otherwise it will only be called when a the first argument is falsey (and without the
1st argument)Same behaviour as above, except errors will be emitted to emitter
instead of passed to an error handler
function. All other options and arguments are the same.
npm test [--dot | --spec] [--coverage]
--dot
- output test results as dots instead of tap--spec
- output test results as spec instead of tap--coverage
- display text cover report--testling
- run tests in browser via testling (cannot be used with --coverage and
expects both browserify and testling to be installed globally)Only run test files matching a certain pattern by prefixing the
test command with grep=pattern
. Example:
grep=connect npm test --dot
Open it with npm run view-cover
or npm run vc
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.