You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 7-8.RSVP
Socket
Socket
Sign inDemoInstall

go.uber.org/multierr

Package Overview
Dependencies
Alerts
File Explorer
Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

go.uber.org/multierr

Package multierr allows combining one or more errors together. Errors can be combined with the use of the Combine function. If only two errors are being combined, the Append function may be used instead. The underlying list of errors for a returned error object may be retrieved with the Errors function. You sometimes need to append into an error from a loop. Cases like this may require knowledge of whether an individual instance failed. This usually requires introduction of a new variable. multierr includes AppendInto to simplify cases like this. This will append the error into the err variable, and return true if that individual error was non-nil. See AppendInto for more information. Go makes it possible to modify the return value of a function in a defer block if the function was using named returns. This makes it possible to record resource cleanup failures from deferred blocks. multierr provides the Invoker type and AppendInvoke function to make cases like the above simpler and obviate the need for a closure. The following is roughly equivalent to the example above. See AppendInvoke and Invoker for more information. NOTE: If you're modifying an error from inside a defer, you MUST use a named return value for that function. Errors returned by Combine and Append MAY implement the following interface. Note that if you need access to list of errors behind a multierr error, you should prefer using the Errors function. That said, if you need cheap read-only access to the underlying errors slice, you can attempt to cast the error to this interface. You MUST handle the failure case gracefully because errors returned by Combine and Append are not guaranteed to implement this interface.


Version published

Readme

Source

multierr GoDoc Build Status Coverage Status

multierr allows combining one or more Go errors together.

Features

  • Idiomatic: multierr follows best practices in Go, and keeps your code idiomatic.
    • It keeps the underlying error type hidden, allowing you to deal in error values exclusively.
    • It provides APIs to safely append into an error from a defer statement.
  • Performant: multierr is optimized for performance:
    • It avoids allocations where possible.
    • It utilizes slice resizing semantics to optimize common cases like appending into the same error object from a loop.
  • Interoperable: multierr interoperates with the Go standard library's error APIs seamlessly:
    • The errors.Is and errors.As functions just work.
  • Lightweight: multierr comes with virtually no dependencies.

Installation

go get -u go.uber.org/multierr@latest

Status

Stable: No breaking changes will be made before 2.0.


Released under the MIT License.

FAQs

Package last updated on 29 Mar 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc