error-retainer

1.0.0 • Public • Published

error-retainer

Build Status GitHub code size in bytes GitHub package.json version GitHub

Retain stack traces when breaking out of the current stack.

Example Usage

Simple single step

const createErrorRetainer = require('error-retainer');

function throwOutOfStack (callback) {
  // Create a retainer that will remember the call stack until this point.
  const retainer = createErrorRetainer();

  process.nextTick(() => {
    const error = new Error('whoops');

    // Apply our retainer to the new error object.
    retainer.retain(error);

    callback(error);
  });
}

Multiple call stack break outs

const createErrorRetainer = require('error-retainer');

function throwOutOfStack (callback) {
  // Create a retainer that will remember the call stack until this point.
  const retainer = createErrorRetainer();

  process.nextTick(() => {
    // We're going to break out of the stack trace a couple of times
    // so let's add this step to our retainer.
    retainer.step();

    process.nextTick(() => {

      const error = new Error('whoops');

      // Finally let's apply our retainer to our new error object.
      retainer.retain(error);

      callback(error);
    });
  })
}

Readme

Keywords

none

Package Sidebar

Install

npm i error-retainer

Weekly Downloads

0

Version

1.0.0

License

ISC

Unpacked Size

4.41 kB

Total Files

6

Last publish

Collaborators

  • markwylde