
Research
Security News
Malicious npm Packages Use Telegram to Exfiltrate BullX Credentials
Socket uncovers an npm Trojan stealing crypto wallets and BullX credentials via obfuscated code and Telegram exfiltration.
The makeerror npm package provides a simple way to create custom error types in JavaScript. It allows developers to define new error types with specific properties and methods, enhancing error handling in applications by making it more structured and informative.
Creating custom error types
This feature allows developers to create new error types. The example shows how to define a custom error type named 'MyError' and create an instance of it with a specific message.
const makeError = require('makeerror');
const MyError = makeError('MyError');
const errorInstance = new MyError('Something went wrong!');
console.log(errorInstance.name); // 'MyError'
console.log(errorInstance.message); // 'Something went wrong!'
Custom error with additional properties
This feature demonstrates how to add additional properties to a custom error type. In the example, a 'statusCode' property is added to the 'MyError' type, which can be useful for HTTP error handling.
const makeError = require('makeerror');
const MyError = makeError('MyError', { statusCode: 404 });
const errorInstance = new MyError('Not found');
console.log(errorInstance.statusCode); // 404
The verror package provides a way to create rich JavaScript errors, which can include multiple error causes, formatted messages, and other metadata. It is more feature-rich compared to makeerror, offering advanced error chaining and customization options.
This package is specifically designed to generate HTTP errors for Node.js applications. Unlike makeerror, which is general-purpose, http-errors focuses on HTTP status codes and messages, making it ideal for web server development.
A library to make errors.
Makes an Error constructor function with the signature below. All arguments are
optional, and if the first argument is not a String
, it will be assumed to be
data
:
function(message, data)
You'll typically do something like:
var makeError = require('makeerror')
var UnknownFileTypeError = makeError(
'UnknownFileTypeError',
'The specified type is not known.'
)
var er = UnknownFileTypeError()
er
will have a prototype chain that ensures:
er instanceof UnknownFileTypeError
er instanceof Error
There is support for simple string substitutions like:
var makeError = require('makeerror')
var UnknownFileTypeError = makeError(
'UnknownFileTypeError',
'The specified type "{type}" is not known.'
)
var er = UnknownFileTypeError({ type: 'bmp' })
Now er.message
or er.toString()
will return 'The specified type "bmp" is not known.'
.
You can create simple hierarchies as well using the prototype
chain:
var makeError = require('makeerror')
var ParentError = makeError('ParentError')
var ChildError = makeError(
'ChildError',
'The child error.',
{ proto: ParentError() }
)
var er = ChildError()
er
will have a prototype chain that ensures:
er instanceof ChildError
er instanceof ParentError
er instanceof Error
FAQs
A library to make errors.
The npm package makeerror receives a total of 20,242,843 weekly downloads. As such, makeerror popularity was classified as popular.
We found that makeerror 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
Socket uncovers an npm Trojan stealing crypto wallets and BullX credentials via obfuscated code and Telegram exfiltration.
Research
Security News
Malicious npm packages posing as developer tools target macOS Cursor IDE users, stealing credentials and modifying files to gain persistent backdoor access.
Security News
AI-generated slop reports are making bug bounty triage harder, wasting maintainer time, and straining trust in vulnerability disclosure programs.