node-error-codes

0.0.4 • Public • Published

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 error_codes.mjs
System Errors with libUV hasnt been implemented yet!

TODO:

Configure tests/linter.
Implement libuv errors.

Liscence: ISC

Readme

Keywords

none

Package Sidebar

Install

npm i node-error-codes

Weekly Downloads

0

Version

0.0.4

License

ISC

Last publish

Collaborators

  • cswl