# spawn-error-forwarder

> Emit errors on stdout stream for a spawned child process

Latest version **1.0.0** (published 2014-11-23) · MIT license · 0 weekly downloads

## Install

```sh
npm install spawn-error-forwarder
pnpm add spawn-error-forwarder
yarn add spawn-error-forwarder
bun add spawn-error-forwarder
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2014-11-23 |
| First published | 2014-11-23 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Ben Drucker |
| Maintainers | bendrucker |
| Keywords | child_processs, spawn, error, stdout, stderr |

## Links

- npm: https://www.npmjs.com/package/spawn-error-forwarder
- Repository: https://github.com/bendrucker/spawn-error-forwarder
- Issues: https://github.com/bendrucker/spawn-error-forwarder/issues
- npm.io page: https://npm.io/package/spawn-error-forwarder

## Alternatives

- [@sentry/react-native](https://npm.io/package/@sentry/react-native.md) — 2.6M weekly downloads
- [@ardatan/aggregate-error](https://npm.io/package/@ardatan/aggregate-error.md) — 708.1K weekly downloads
- [custom-error-generator](https://npm.io/package/custom-error-generator.md) — 2.0K weekly downloads
- [@technik-sde/prosemirror-recreate-transform](https://npm.io/package/@technik-sde/prosemirror-recreate-transform.md) — 1.5K weekly downloads
- [@suchipi/error-utils](https://npm.io/package/@suchipi/error-utils.md) — 78 weekly downloads

## Recent versions

- 1.0.0 (latest) — 2014-11-23

## README

spawn-error-forwarder [![Build Status](https://travis-ci.org/bendrucker/spawn-error-forwarder.svg?branch=master)](https://travis-ci.org/bendrucker/spawn-error-forwarder)
=====================

Emit errors on stdout stream for a spawned child process. Useful for capturing errors from a spawned process when you want the output from stdout. 

## Setup
```bash
$ npm install spawn-error-forwarder
```

## API

#### `fwd(child [, errFactory]` -> `child`

Buffers `child.stderr` output. If the spawned process exits with a code `> 0`, the buffered output of `child.stderr` is used to generate an error which is emitted on `child.stdout`. By default, the error message is the output of `child.stderr`. If you provide an `errFactory` function, it will be called with `code, stderr` where `code` is the child's exit code and `stderr` is string that contains the output of `child.stderr`. `errFactory` should return an `Error` to be emitted on `child.stdout`. 

## Example

```js
var fwd   = require('spawn-error-forwarder');
var spawn = require('child_process').spawn;
var child = spawn('git', ['log', 'non-existent-path']);

fwd(child, function (code, stderr) {
  return new Error('git log exited with ' + code + ':\n\n' + stderr);
});

child.stdout
  .on('error', console.error.bind(console))
  .pipe(process.stdout);
```

We want to pipe the output of `git log` to `process.stdout` but since we're providing a path that doesn't exist git will exit with a non-zero code and we'll log its output with `console.error`.

---
_Source: https://npm.io/package/spawn-error-forwarder · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
