npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

eratum

v2.2.0

Published

Module defining wrapper over Error class.

Downloads

7

Readme

Eratum

Installation

npm install --save eratum

Usage

Import

// Old way
const { default: Errors, registerError } = require('eratum');
// Module way
import Errors, { registerError } from 'eratum';

Throw

import Errors from 'eratum';

const error = Errors.notYetImplemented({ name: 'awesomeFeature', reason: 'Planned in v2.3' });
/*
{
	tag: 'NOT_YET_IMPLEMENTED',
	message: 'NOT_YET_IMPLEMENTED - Feature(awesomeFeature) is not yet implemented.Planned in v2.3'
}
*/

try {
	try {
		throw Errors.notEqual({ name: 'key.length', actualValue: 16, expectedValue: 32 });
	} catch (cause) {
		throw Errors.unexpectedError({ reason: 'Cipher fail', origin: 'CRYPTO', cause })
	}
} catch (cause) {
	throw Errors.internalError({ reason: 'Authentication fail', origin: 'LOGIN', cause })
}
/*
{
	tag: 'INTERNAL_ERROR',
	message: 'INTERNAL_ERROR - Authentication fail',
	origin: 'LOGIN'
	cause: {
		tag: 'UNEXPECTED_ERROR',
		message: 'UNEXPECTED_ERROR - Cipher fail',
		origin: 'CRYPTO'
		cause: {
			tag: 'NOT_EQUAL',
			message: 'NOT_EQUAL - key.length(16) is not equal to 32'
		},
	},
}
*/

Extends

import Errors, { registerError } from 'eratum';

registerError('outOfBound', 'Resource(<%= name %>) is out of bound(<%= bound %>)', [ 'name', 'bound' ] );
// Errors.outOfBound.tag === 'OUT_OF_BOUND'

const error = Errors.outOfBound({ name: 'amount', bound: 10 });
// error instanceof Errors.outOfBound.class === true
// error.tag === 'OUT_OF_BOUND'

// Optional parameters
registerError('notYetImplemented', 'Feature(<%- name %>) is not yet implemented.<% if (locals.reason) { %><%- reason %><% } %>', ['name']);

Documentation

Eratum

Class extending Error

  • Properties
    • tag String Unique string identifier for this error type. Must be capitalized snake case (/^[A-Z_]+$/). Generated from name when using registerError.
    • message String Human readable message explaining error. Generated by EJS template and parameters. Inherited from Error.
    • cause any Previous Error generating this one. (optional, default null)
    • origin String Human readable hint about thrower. Should be capitalized snake case (/^[A-Z_]*$/). (optional, default '')
    • parameters Object Object storing extra parameters while producing this Eratum (including required attributes).
  • Static properties
    • origin String Prefix for all generated errors.
    • isStackEnabled boolean Define default option for get function.
  • Functions
    • get Serilize error in JSON ready object.
      • Parameters
        • isStackEnabled boolean Define if stack is includes in returns. (optional, default Eratum.isStackEnabled)
      • Returns IEratum

IEratum

Interface defining properties of Eratum class

  • Properties
    • tag String Unique string identifier for this error type. Must be capitalized snake case (/^[A-Z_]+$/).
    • message String Human readable message explaining error.
    • cause any Previous Error generating this one.
    • origin String Human readable hint about thrower. Should be capitalized snake case (/^[A-Z_]*$/).

registerError

Register error by name

  • Parameters
    • name String Unique string name for this error type. Must be camel case (/^[a-z][a-zA-Z]*$/).
    • template String EJS template to build error message. (optional, default '')
    • requiredAttrs String[] Required attributes for previous EJS template. Rendering fail if those attributes are undefined. (optional, default [])
  • Return void
  • Throw Eratum.doesntExist if missing parameter
  • Throw Eratum.invalidType if type parameter missmatch
  • Throw Eratum.invalidFormat if format parameter missmatch
  • Throw Eratum.exist if error name is already registered

Error producer

All errors have the same producer signature.

  • Parameters
    • parameters EratumOptions
    • parameters.cause any
    • parameters.origin String ****
    • parameters[...requiredAttrs] Stringable
  • Return class extending Eratum
  • Throw Eratum.doesntExist if missing parameters or required attributes.
  • Throw Eratum.invalidType if type parameter missmatch

Registered errors

  • internalError
    • Tag INTERNAL_ERROR
    • Parameters
      • reason (optional, default '')
  • unexpectedError
    • Tag UNEXPECTED_ERROR
    • Parameters
      • reason (optional, default '')
  • programingFault
    • Tag PROGRAMING_FAULT
    • Parameters
      • reason (optional, default '')
  • notYetImplemented
    • Tag NOT_YET_IMPLEMENTED
    • Parameters
      • name
      • reason (optional, default '')
  • initialized
    • Tag INITIALIZED
    • Parameters
      • name
  • notInitialized
    • Tag NOT_INITIALIZED
    • Parameters
      • name
  • invalid
    • Tag INVALID
    • Parameters
      • name
      • reason (optional, default '')
  • invalidType
    • Tag INVALID_TYPE
    • Parameters
      • name
      • actualType
      • expectedType
  • invalidFormat
    • Tag INVALID_FORMAT
    • Parameters
      • name
      • value
      • format
  • exist
    • Tag EXIST
    • Parameters
      • name
  • doesntExist
    • Tag DOESNT_EXIST
    • Parameters
      • name
  • equal
    • Tag EQUAL
    • Parameters
      • name
      • value
  • notEqual
    • Tag NOT_EQUAL
    • Parameters
      • name
      • actualValue
      • expectedValue
  • included
    • Tag INCLUDED
    • Parameters
      • name
      • value
      • forbiddenValues
  • notIncluded
    • Tag NOT_INCLUDED
    • Parameters
      • name
      • value
      • possibleValues