
Research
Malicious npm Packages Impersonate Flashbots SDKs, Targeting Ethereum Wallet Credentials
Four npm packages disguised as cryptographic tools steal developer credentials and send them to attacker-controlled Telegram infrastructure.
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 46 weekly downloads. As such, babel-plugin-transform-fake-error-class popularity was classified as not 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
Four npm packages disguised as cryptographic tools steal developer credentials and send them to attacker-controlled Telegram infrastructure.
Security News
Ruby maintainers from Bundler and rbenv teams are building rv to bring Python uv's speed and unified tooling approach to Ruby development.
Security News
Following last week’s supply chain attack, Nx published findings on the GitHub Actions exploit and moved npm publishing to Trusted Publishers.