
Security News
Axios Maintainer Confirms Social Engineering Attack Behind npm Compromise
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.
alpha-errors
Advanced tools
Simple system that introduces useful "code" property to your errors and facilitates error management
Features:
npm install alpha-errors
import {create} from 'alpha-errors';
const errorsDomain = create();
export const Errors = {
// this creates "error descriptor" - a function that creates final error object
NOT_FOUND: errorsDomain.create('Entity not found'),
UNAUTHORIZED: errorsDomain.create('Unauthorized', 20), // custom error code
}
// create via "new"
const notFoundError = new Errors.NOT_FOUND()
notFoundError instanceof Error; // true
notFoundError.code; // 1
notFoundError.message; // Entity not found
// or call like a function
const unauthorizedError = Errors.UNAUTHORIZED('Please login first');
unauthorizedError.code; // 20
unauthorizedError.message; // Please login first
See jsdoc in *.d.ts files for detailed api. Below few example
// built-in generators
import {generators} from 'alpha-errors';
const number = generators.incrementNumber();
number(); // 1
number(); // 2
number(); // 3
const customizedNumber = generators.incrementNumber(100, 10);
customizedNumber(); // 100
customizedNumber(); // 110
customizedNumber(); // 120
// Uses util.format for final code
const format = generators.formatCode('WOO_%d');
format(); // WOO_1
format(); // WOO_2
format(); // WOO_3
const customizedFormat = generators.formatCode('WOO_%d', 100, 10);
format(); // WOO_100
format(); // WOO_110
format(); // WOO_120
// custom formatter function
const customFunctionFormat = generators.formatCode((n) => (n+'').padStart(4, '0'))
format(); // 0001
format(); // 0002
format(); // 0003
Provide custom generator for errors domain creator.
import {ErrorsDomain, generators} from 'alpha-errors';
const errorsDomain = new ErrorsDomain({codeGenerator: generators.formatCode('WOO_%d')});
const error = errorsDomain.create()() // error.code === 'WOO_1'
You can always override default message for event descriptor
const error1 = errorsDomain.create('Default message')(); // error1.message === 'Default message'
const error2 = errorsDomain.create('Default message')('New message'); // error1.message === 'New message'
You can inject extra properties to final error.
const errorDescriptor = errorsDomain.create('Default message', undefined, {foo: 'bar', bar: 'noo'});
const error1 = errorDescriptor();
// error1.foo === 'bar'
// error1.bar === 'noo'
const error2 = errorDescriptor(undefined, {foo: 'override bar', newProperty: 'test'});
// error2.foo === 'override bar'
// error2.bar === 'noo'
// error2.newProperty === 'test'
const domain = new ErrorsDomain({errorClass: CustomErrorClass});
const errorDescriptor1 = domain.create();
const errorDescriptor2 = domain.create({errorClass: AnotherCustomErrorClass});
errorDescriptor1() instanceof CustomErrorClass; // true
errorDescriptor2() instanceof AnotherCustomErrorClass; // true
Extra method is checks whether provided object is an object, have the same error code and is an instance of error class defined in descriptor.
const INVALID_USER = errorsDomain.create('Invalid user', '1', {errorClass: CustomErrorClass});
INVALID_USER.is(new INVALID_USER); // true
INVALID_USER.is(new Error('Some error')); // false - code doesn't match and it's not an instance of CustomErrorClass
INVALID_USER.is(new CustomErrorClass('Some error')); // false - code doesn't match
FAQs
Simple helper to create error domains with error codes
The npm package alpha-errors receives a total of 353 weekly downloads. As such, alpha-errors popularity was classified as not popular.
We found that alpha-errors 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
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.

Security News
The Axios compromise shows how time-dependent dependency resolution makes exposure harder to detect and contain.