2.0.0 • Public • Published

kind-error The MIT License

Base class for easily creating meaningful and quiet by default Error classes.

code climate standard code style travis build status coverage status dependency status


npm i kind-error --save


  • You can customize error name with name property in options object.
  • By default won't have stack property in the composed error object.
  • You should pass showStack: true in options if you want stacktraces.
  • Composes meaningful error output if actual and expected given.
  • If actual and expected is given, will compose message automatically.


For more use-cases see the tests

const KindError = require('kind-error')


Initialize KindError class with message and options.



const err = new KindError('msg', {
  showStack: true,
  custom: 123
console.log(err) // => [KindError: msg]
console.log(err.custom) // => 123
console.log(err.stack) // => error stack trace

Or if you give actual and expected it will make default message. See this example.

const assert = require('assert')
const err = new KindError({
  actual: [1, 2, 3],
  expected: {foo: 'bar'}
assert.deepEqual(err.actual, [1, 2, 3])
assert.deepEqual(err.expected, {foo: 'bar'})
assert.strictEqual(err.stack, undefined)
assert.strictEqual(err.type.actual, 'array')
assert.strictEqual(err.type.expected, 'object')
assert.strictEqual(err.inspect.actual, '[ 1, 2, 3 ]')
assert.strictEqual(err.inspect.expected, '{ foo: \'bar\' }')
assert.strictEqual(err.message, 'expect `object`, but `array` given')

Example AppError

Here we show how to create new error class

var util = require('util')
var KindError = require('kind-error')
function AppError () {
  KindError.apply(this, arguments) = 'AppError'
util.inherits(AppError, KindError) = function () {
  return 123
var err = new AppError('foo bar', {baz: 'qux'})
//=> err
// => 'AppError'
// err.message => 'foo bar'
// err.baz => 'qux'
// => 123


  • abbrev-kindof: Use abbreviations for checking type of given value. Like kindof(val, 'soa') to check that value is string, object or array.
  • assert-kindof: Check native type of the given value and throw TypeError if not okey. Expressive, elegant, behavior-driven API, good descriptive default error messages, simple and clean syntax.
  • is-kindof: Check type of given javascript value. Support promises, generators, streams, and native types. Thin wrapper around kind-of module.
  • kind-of-extra: Extends kind-of type check utility with support for promises, generators, streams and errors. Like kindof(Promise.resolve(1)) //=> 'promise' and etc.
  • kind-of-types: List of all javascript types. Used and useful for checking, validation, sanitizing and testing. Like isStream, isPromise, isWeakset and etc.
  • error-base: Create custom Error classes.


Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.
But before doing anything, please read the guidelines.

Charlike Make Reagent new message to charlike freenode #charlike keybase tunnckocore tunnckoCore npm tunnckoCore twitter tunnckoCore github

Package Sidebar


npm i kind-error

Weekly Downloads






Last publish


  • vanchoy
  • tunnckocore