Security News
The Dark Side of Open Source
At Node Congress, Socket CEO Feross Aboukhadijeh uncovers the darker aspects of open source, where applications that rely heavily on third-party dependencies can be exploited in supply chain attacks.
err-code
Advanced tools
Readme
Create new error instances with a code and additional properties.
$ npm install err-code
// or
$ bower install err-code
The browser file is named index.umd.js which supports CommonJS, AMD and globals (errCode).
I find myself doing this repeatedly:
var err = new Error('My message');
err.code = 'SOMECODE';
err.detail = 'Additional information about the error';
throw err;
Simple usage.
var errcode = require('err-code');
// fill error with message + code
throw errcode(new Error('My message'), 'ESOMECODE');
// fill error with message + code + props
throw errcode(new Error('My message'), 'ESOMECODE', { detail: 'Additional information about the error' });
// fill error with message + props
throw errcode(new Error('My message'), { detail: 'Additional information about the error' });
If the passed Error
already has a .code
field, or fields specified in the third argument to errcode
they will be overwritten, unless the fields are read only or otherwise throw during assignment in which case a new object will be created that shares a prototype chain with the original Error
. The .stack
and .message
properties will be carried over from the original error and .code
or any passed properties will be set on it.
$ npm test
Released under the MIT License.
FAQs
Create an error with a code
The npm package err-code receives a total of 11,986,785 weekly downloads. As such, err-code popularity was classified as popular.
We found that err-code demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers 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
At Node Congress, Socket CEO Feross Aboukhadijeh uncovers the darker aspects of open source, where applications that rely heavily on third-party dependencies can be exploited in supply chain attacks.
Research
Security News
The Socket Research team found this npm package includes code for collecting sensitive developer information, including your operating system username, Git username, and Git email.
Security News
OpenJS is warning of social engineering takeovers targeting open source projects after receiving a credible attempt on the foundation.