
Research
/Security News
Critical Vulnerability in NestJS Devtools: Localhost RCE via Sandbox Escape
A flawed sandbox in @nestjs/devtools-integration lets attackers run code on your machine via CSRF, leading to full Remote Code Execution (RCE).
babel-plugin-transform-fake-error-class
Advanced tools
Transform error classes into error-returning functions
If you want to create your own error types, extending Error
is the best way to do that:
class MyError extends Error {
constructor(message) {
super(message)
this.name = 'MyError'
}
}
Unfortunately, this doesn't work in old ES5 environments, and Babel's built-in class transforms don't always give good stack traces.
Since extending the built-in Error
object doesn't always work, this plugin doesn't do that. Instead, it transforms the above class into something like this:
function MyError(message) {
var _this = new Error(message)
_this.name = 'MyError'
return _this
}
This works almost perfectly in both old and new environments. You still call new MyError()
, just as before, properties like name
appear as they should, and stack traces look perfect, but under the hood this is no longer a class. That means instanceof MyError
will always return false, but that's the only major downside.
This plugin also supports methods and class properties, including static ones:
class MyError extends Error {
name = 'MyError'
static isMyError(error) {
return error.constructor === MyError
}
getReason() {
return this.message
}
}
npm install --save-dev babel-plugin-transform-fake-error-class
# or
yarn add --dev babel-plugin-transform-fake-error-class
Now add this plugin to your .babelrc
:
{
"plugins": [
"babel-plugin-transform-fake-error-class"
]
}
FAQs
Transform error classes into error-returning functions
The npm package babel-plugin-transform-fake-error-class receives a total of 1,106 weekly downloads. As such, babel-plugin-transform-fake-error-class popularity was classified as popular.
We found that babel-plugin-transform-fake-error-class 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
A flawed sandbox in @nestjs/devtools-integration lets attackers run code on your machine via CSRF, leading to full Remote Code Execution (RCE).
Product
Customize license detection with Socket’s new license overlays: gain control, reduce noise, and handle edge cases with precision.
Product
Socket now supports Rust and Cargo, offering package search for all users and experimental SBOM generation for enterprise projects.