<commit_before># MError

MError: VError with error levels

[![Build Status](https://travis-ci.org/Wizcorp/MError.png)](https://travis-ci.org/Wizcorp/MError)

## The purpose of this module

[VError](https://www.npmjs.com/package/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:

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

**error.getLevel()**

Returns the current level of the error.

Example:

```js
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:

```js
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.

```js
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.

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

<commit_msg>Explain chaining<commit_after># MError

MError: VError with error levels

[![Build Status](https://travis-ci.org/Wizcorp/MError.png)](https://travis-ci.org/Wizcorp/MError)

## The purpose of this module

[VError](https://www.npmjs.com/package/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:

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

**error.getLevel()**

Returns the current level of the error.

Example:

```js
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:

```js
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.

```js
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.

```js
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:

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

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


{'fraction_non_alphanumeric': 0.1347455133862901, 'fraction_numerical': 0.0, 'mean_word_length': 4.647840531561462, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 6, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3884644', 'n_tokens_mistral': 1132, 'n_tokens_neox': 1064, 'n_words': 418}