Security News
Fluent Assertions Faces Backlash After Abandoning Open Source Licensing
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
It makes simple throw qualified errors. Inspired in errno, create-error-class and fault.
Error
interface in browser and NodeJS.This library is a compromise to provide a clean API for use Error
native class.
npm install whoops --save
Basically it turns:
const error = Error('Something is wrong')
error.name = 'DAMNError'
throw error // => 'DAMNError: ENOFILE, Something is wrong'
Into a one line more productive declaration:
const whoops = require('whoops')
const userError = whoops('UserError')
throw userError('User not found') // => 'UserError: User not found'
Call whoops
to get a constructor function. Every time you call the constructor, you get an Error
instance:
const whoops = require('whoops')
const myError = whoops()
throw myError()
Create domain specific errors providing a className
as first argument:
const whoops = require('whoops')
const userError = whoops('userError')
throw userError()
The qualified error will be extends from Error
:
const whoops = require('whoops')
const userError = whoops('userError')
const error = userError()
console.log(error instanceof Error); // => true
Attach extra information passing a props
as second argument:
const whoops = require('whoops')
const userError = whoops('userError', {code: 'ENOVALID'})
const err = userError()
console.log(`My error code is ${err.code}`) // => My error code is ENOVALID
You can associate dynamic props
as well:
const whoops = require('whoops')
const userError = whoops('userError', {
code: 'ENOVALID',
message: props => `User '${props.username}' not found`
})
const err = userError({username: 'kiko'})
console.log(err.message) // => User 'kiko' not found
By default you will get Error
instances calling whoops, but you can get different errors calling the properly method:
Name | Method |
---|---|
Error | whoops |
TypeError | whoops.type |
RangeError | whoops.range |
EvalError | whoops.eval |
SyntaxError | whoops.syntax |
ReferenceError | whoops.reference |
URIError | whoops.uri |
If you code implementation is
Error
. If you just return the Error
nothings happens!.Error
in the first argument of the callback (or using promises).About asynchronous code, is correct return a Object
that is not a Error
in the first argument of the callback to express unexpected behavior, but the Object
doesn't have a type and definitely can't follow a error interface for determinate a special behavior:
callback('LOL something was wrong') // poor
callback({message: 'LOL something was wrong' } // poor, but better
callback(whoops('LOL, something was wrong') // BEST!
Passing always an Error
you can can associated different type of error with different behavior:
switch (err.name) {
case 'JSONError':
console.log('your error logic here')
break
default:
console.log('undefined code')
break
};
MIT © Kiko Beats
4.0.2 (2019-03-08)
<a name="4.0.1"></a>
FAQs
It makes simple throw qualified errors.
The npm package whoops receives a total of 140,681 weekly downloads. As such, whoops popularity was classified as popular.
We found that whoops 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
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.