Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

stderr-error-parser

roshanadh6ISC1.0.2

Parse error stack from stderr of a Node.js process

error, stack, stderr, process, parser

readme

stderr-error-parser

Node.js module to parse error stack from the stderr of a Node.js process

Installation

stderr-error-parser is available though npm

$ npm i stderr-err-parser

Using

// import stderr-error-parser
const parseError = require("stderr-error-parser");

const { exec } = require("child_process");
const path = require("path");

// filePath should be an absolute path
const filePath = path.resolve(
    __dirname,
    "executable-js-files",
    "throws-range-error.js"
);

exec(`node ${filePath}`, (error, stdout, stderr) => {
    if (stderr.trim() !== "") {
        const _parsed = parseError(filePath, stderr, stdout);
        console.dir(_parsed);
        /*
        _parsed =
        {
              outputPart: 'Hello World!\n',
              errorBody: {
                errorName: 'RangeError',
                errorMessage: 'This is a range error.',
                lineNumber: 2,
                columnNumber: 7,
                errorStack: 'RangeError: This is a range error.\n' +
                  '    at ....'
              }
        }
        */
    } else {
        console.log(stdout);
    }
});

Examples

To check some of the examples, clone the repository and install dependencies

$ git clone https://github.com/roshanadh/stderr-error-parser
$ cd stderr-error-parser
$ npm install

Then run the example you want to see

$ node examples/example-reference-error.js

Tests

To run the test suite, clone the repository and install dependencies, then run

$ npm test