{"_id":"maybe-combine-errors","_rev":"4212154","name":"maybe-combine-errors","description":"Combine 0 or more errors into one","dist-tags":{"latest":"1.0.0"},"maintainers":[{"name":"vweevers","email":""}],"time":{"modified":"2026-03-04T17:06:51.000Z","created":"2020-07-23T09:58:50.964Z","1.0.0":"2020-07-23T09:58:50.964Z"},"users":{},"author":{"name":"Vincent Weevers"},"repository":{"type":"git","url":"git+https://github.com/vweevers/maybe-combine-errors.git"},"versions":{"1.0.0":{"name":"maybe-combine-errors","version":"1.0.0","description":"Combine 0 or more errors into one","license":"MIT","author":{"name":"Vincent Weevers"},"scripts":{"test":"standard && nyc node test"},"dependencies":{},"devDependencies":{"nyc":"^15.1.0","standard":"^14.3.4","tape":"^5.0.1"},"repository":{"type":"git","url":"git+https://github.com/vweevers/maybe-combine-errors.git"},"homepage":"https://github.com/vweevers/maybe-combine-errors","keywords":["combine","error","errors","exception"],"engines":{"node":">=10"},"gitHead":"7b1e640fad52317c5b9ad5f800ce6cf0b92236ad","bugs":{"url":"https://github.com/vweevers/maybe-combine-errors/issues"},"_id":"maybe-combine-errors@1.0.0","_nodeVersion":"12.11.1","_npmVersion":"6.11.3","_npmUser":{"name":"vweevers","email":"dev@vincentweevers.nl"},"maintainers":[{"name":"vweevers","email":""}],"dist":{"shasum":"e9592832e61fc47643a92cff3c1f33e27211e5be","size":2686,"noattachment":false,"key":"/maybe-combine-errors/-/maybe-combine-errors-1.0.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/maybe-combine-errors/download/maybe-combine-errors-1.0.0.tgz"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/maybe-combine-errors_1.0.0_1595498330860_0.25920115653273257"},"_hasShrinkwrap":false,"_cnpmcore_publish_time":"2021-12-19T15:31:47.116Z","publish_time":1595498330964,"_cnpm_publish_time":1595498330964}},"readme":"# maybe-combine-errors\n\n**Combine 0 or more errors into one.**\n\n[![npm status](http://img.shields.io/npm/v/maybe-combine-errors.svg)](https://www.npmjs.org/package/maybe-combine-errors)\n[![node](https://img.shields.io/node/v/maybe-combine-errors.svg)](https://www.npmjs.org/package/maybe-combine-errors)\n[![Travis build status](https://img.shields.io/travis/com/vweevers/maybe-combine-errors.svg?label=travis)](http://travis-ci.com/vweevers/maybe-combine-errors)\n[![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com)\n\n## Usage\n\n```js\nconst combine = require('maybe-combine-errors')\n\nconst err1 = new Error('one')\nconst err2 = new Error('two')\n\nconsole.log(combine([err1, err2]).message)\nconsole.log(combine([err1, err2]) instanceof Error)\nconsole.log(combine([err1, null]) === err1)\nconsole.log(combine([]) === undefined)\n\nthrow combine([err1, err2])\n```\n\n```\n$ node example.js\none; two\ntrue\ntrue\ntrue\nexample.js:9\nthrow combine([err1, err2])\n^\n\nError: one\n    at Object.<anonymous> (example.js:3:14)\n    at Module._compile (internal/modules/cjs/loader.js:945:30)\n    at Object.Module._extensions..js (internal/modules/cjs/loader.js:962:10)\n    at Module.load (internal/modules/cjs/loader.js:798:32)\n    at Function.Module._load (internal/modules/cjs/loader.js:711:12)\n    at Function.Module.runMain (internal/modules/cjs/loader.js:1014:10)\n    at internal/main/run_main_module.js:17:11\n\nError: two\n    at Object.<anonymous> (example.js:4:14)\n    at Module._compile (internal/modules/cjs/loader.js:945:30)\n    at Object.Module._extensions..js (internal/modules/cjs/loader.js:962:10)\n    at Module.load (internal/modules/cjs/loader.js:798:32)\n    at Function.Module._load (internal/modules/cjs/loader.js:711:12)\n    at Function.Module.runMain (internal/modules/cjs/loader.js:1014:10)\n    at internal/main/run_main_module.js:17:11\n```\n\n## API\n\n### `combine(errors)`\n\nThe `errors` argument must be an array.\n\nElements that are `null` or `undefined` are skipped. If the array is empty (after skipping `null` and `undefined`), `undefined` will be returned. If the array contains only 1 error, that error will be returned as-is. Otherwise, a combined error with joined messages and a lazily joined stack. Duplicate messages are skipped.\n\nRespects [`transient-error`](https://github.com/vweevers/transient-error) and `err.expected`: if all errors have `.transient === true` then the combined error will also be transient. Same for `.expected`, which is useful for the following pattern:\n\n```js\nif (err.expected) {\n  console.error(err.message)\n  process.exit(1)\n} else {\n  throw err\n}\n```\n\n## Alternatives\n\n### [`combine-errors`](https://github.com/MatthewMueller/combine-errors)\n\nSame message and stack behavior. Different in that it always returns an error regardless of input length.\n\n### [`aggregate-error`](https://github.com/sindresorhus/aggregate-error)\n\nSets message to a joined stack, which means you can't get a human-friendly message with e.g. `console.error(err.message)`. Removes \"mostly unhelpful\" internal Node.js entries from the stack.\n\n## Install\n\nWith [npm](https://npmjs.org) do:\n\n```\nnpm install maybe-combine-errors\n```\n\n## License\n\n[MIT](LICENSE.md) © 2020-present Vincent Weevers\n","_attachments":{},"homepage":"https://github.com/vweevers/maybe-combine-errors","bugs":{"url":"https://github.com/vweevers/maybe-combine-errors/issues"},"license":"MIT"}