Security News
RubyGems.org Adds New Maintainer Role
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Inherit from Error without performance penalties, instanceof behaves as expected and the error stack is correct
Inherit from Error without performance penalties, instanceof
behaves as expected and the error stack is correct. This library can be used cross-browser using Browserify.
A lot of solutions for inheriting from Error
in javascript are error-prone (pun intended) and tricky.
Using this library you can inherit Error
just like you would inherit from any other javascript object/class.
Here is an example using the inherits library.
var Throwable = require('throwable');
function MyError(wrapped)
{
Throwable.call(this, wrapped);
this.name = 'MyError';
}
require('inherits')(MyError, Throwable);
And this is how you can throw your error:
function failure()
{
throw new MyError(Error('Something went wrong!'));
}
This library has a few advantage some other solutions might not have:
Using instanceof
wil work as expected:
try
{
failure();
}
catch(err)
{
console.log(err instanceof Error); // true
console.log(err instanceof Throwable); // true
console.log(err instanceof MyError); // true
}
And the stack
, fileName
(firefox), lineNumber
(firefox) attributes will be set correctly (instead of pointing to a line in the Throwable constructor).
Also, the stack
attribute is accessed only when you need it, Error.captureStackTrace
is not used either. Accessing any of these two is a big performance hit in Node.js and Chrome.
FAQs
Inherit from Error without performance penalties, instanceof behaves as expected and the error stack is correct
The npm package throwable receives a total of 4 weekly downloads. As such, throwable popularity was classified as not popular.
We found that throwable 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
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.
Security News
Research
Socket's threat research team has detected five malicious npm packages targeting Roblox developers, deploying malware to steal credentials and personal data.