npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

maybe-combine-errors

v1.0.0

Published

Combine 0 or more errors into one

Downloads

18,997

Readme

maybe-combine-errors

Combine 0 or more errors into one.

npm status node Travis build status JavaScript Style Guide

Usage

const combine = require('maybe-combine-errors')

const err1 = new Error('one')
const err2 = new Error('two')

console.log(combine([err1, err2]).message)
console.log(combine([err1, err2]) instanceof Error)
console.log(combine([err1, null]) === err1)
console.log(combine([]) === undefined)

throw combine([err1, err2])
$ node example.js
one; two
true
true
true
example.js:9
throw combine([err1, err2])
^

Error: one
    at Object.<anonymous> (example.js:3:14)
    at Module._compile (internal/modules/cjs/loader.js:945:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:962:10)
    at Module.load (internal/modules/cjs/loader.js:798:32)
    at Function.Module._load (internal/modules/cjs/loader.js:711:12)
    at Function.Module.runMain (internal/modules/cjs/loader.js:1014:10)
    at internal/main/run_main_module.js:17:11

Error: two
    at Object.<anonymous> (example.js:4:14)
    at Module._compile (internal/modules/cjs/loader.js:945:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:962:10)
    at Module.load (internal/modules/cjs/loader.js:798:32)
    at Function.Module._load (internal/modules/cjs/loader.js:711:12)
    at Function.Module.runMain (internal/modules/cjs/loader.js:1014:10)
    at internal/main/run_main_module.js:17:11

API

combine(errors)

The errors argument must be an array.

Elements 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.

Respects 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:

if (err.expected) {
  console.error(err.message)
  process.exit(1)
} else {
  throw err
}

Alternatives

combine-errors

Same message and stack behavior. Different in that it always returns an error regardless of input length.

aggregate-error

Sets 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.

Install

With npm do:

npm install maybe-combine-errors

License

MIT © 2020-present Vincent Weevers