New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

merror

Package Overview
Dependencies
Maintainers
2
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

merror

MError: VError with error levels

latest
Source
npmnpm
Version
0.1.1
Version published
Weekly downloads
1
-80%
Maintainers
2
Weekly downloads
 
Created
Source

MError

MError: VError with error levels

Build Status

The purpose of this module

VError is a really awesome NPM module. MError inherits from VError and adds some nice APIs that make it a bit nicer to work with (for me anyway, use it or don't).

API

The main API is documented by the VError module, so we will only go into detail on what is added.

MError.setupLevels(levels, defaultLevel)

You call this once to set up error log levels (in order of severity) that MError should be aware of, and to pass the default level that each error will carry until changed.

Example:

MError.setupLevels(['warning', 'error', 'fatal'], 'error');

error.getLevel()

Returns the current level of the error.

Example:

var error = new MError('Ouch');
console.log(error.getLevel()); // outputs: error

error.setLevel(level)

Changes the error level to any of the levels configured through MError.setupLevels.

Example:

var error = new MError('Ouch');
error.setLevel('fatal');

error.incLevel(level)

Changes the level to what is passed, but only if it's an increase in severity.

var error = new MError('Ouch');
error.incLevel('fatal');

error.decLevel(level)

Changes the level to what is passed, but only if it's a decrease in severity.

var error = new MError('Ouch');
error.decLevel('error');

Chaining

The constructor does not require the "new" keyword to function. This fact, combined with function chaining, allows for one-liner patterns like this:

function statMyFile(cb) {
	fs.stat(someFile, function (error, stats) {
		if (error) {
			return cb(MError(error, 'Stat failed').setLevel('fatal'));
		}

		return cb(null, stats);
	});
});

Keywords

merror

FAQs

Package last updated on 20 Jan 2015

Did you know?

Socket

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.

Install

Related posts