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 and create-error-class.
Basically turns:
var error = Error('ENOFILE, Something is wrong')
error.name = 'DAMNError'
error.code = 'ENOFILE'
throw error // => 'DAMNError: ENOFILE, Something is wrong'
into one line error declaration:
var Whoops = require('Whoops');
var error = Whoops('DAMError', 'ENOFILE', 'Something is wrong');
throw error // => 'DAMNError: ENOFILE, Something is wrong'
Also you can create custom class errors for avoid write the name of the error all the time:
var DAMError = Whoops.create('DAMError')
Now you can avoid the first parameter in the inline declaration:
var error = DAMError('ENOFILE', 'Something is wrong');
throw error // => 'DAMNError: ENOFILE, Something is wrong'
Constructor also can be executed in object mode for the cases where you need to setup more properties associated with the error:
var error = Whoops({
name: 'DAMError', , ''
code: 'ENOFILE'
message: 'Something is wrong'
path: 'filepath'
});
In this mode you can pass a generator function as message:
var error = Whoops({
name: 'DAMError', , ''
code: 'ENOFILE',
file: 'damnfile'
message: function() {
return "Something is wrong with the file '" + this.file "'."
}
});
throw error // => "DAMNError: ENOFILE, Something is wrong with the file 'damnfile'"
npm install whoops --save
If you want to use in the browser (powered by Browserify):
bower install whoops --save
and later link in your HTML:
<script src="bower_components/whoops/dist/whoops.js"></script>
Create a new Error
. You can use it using two different interfaces.
Following the schema .constructor([name], [code], {message})
Whatever property that you pass in an object will be associated with the Error
.
If you pass a function as message
property will be executed in the context
of the Error
.
For both constructor modes, if the code
of the error is provided will be
concatenated and the begin of the message
.
Create a new qualified Error
. All is the same than the normal constructor,
but in this case you don't have to provide the name
of the error.
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
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.