node-error-codes

Error codes of node.js including system errors.

Downloads in past

Stats

StarsIssuesVersionUpdatedCreatedSize
node-error-codes
0.0.45 years ago5 years agoMinified + gzip package size for node-error-codes in KB

Readme

Error codes for Node.js > 8.0

Why

Recently node.js added Error#code https://medium.com/the-node-js-collection/node-js-errors-changes-you-need-to-know-about-dc8c82417f65
But currently it doesn't export the "strings" via internal module.\ So I've created this static ES6 Modules that exports constants.\ So you can figure out typos during bundle time.

Usage:

The modules exports constants
ES6+:
import { ERR_ASSERTION } from "node-error-codes";

try {
  assert(false, "False");
} catch (err) {
  if (err.code === ERR_ASSERTION) {
    console.log("An assertion error was thrown");
  }
}

CommonJS:
const errorCodes = require("node-error-codes");

try {
  assert(false, "False");
} catch (err) {
  if (err.code === errorCodes.ERR_ASSERTION) {
    console.log("An assertion error was thrown");
  }
}

Building

Run gen.js node which fetches the latest error codes from node.js /lib/internal/errors.js.
Parses with babylon, and creates errorcodes.mjs
System Errors with libUV hasnt been implemented yet!

TODO:

Configure tests/linter.
Implement libuv errors.

Liscence: ISC