Search Apps Documentation Source Content File Folder Download Copy Actions Download State String Boolean Number Struct Map Slice Pointer Function Closure Reference Nil Package Type Interface Unknown

v2 source pure

Package errs provides utilities for combining multiple errors. This is a simplified version of [https://github.com/ub...

Readme View source

gno.land/p/moul/errs/v1

TODO: describe this package.


Part of moul/gno-contracts — moul's versioned gno.land contracts. See the repository for the full catalog, build/test tooling, and usage.

⚠️ Disclaimer: provided as-is, without warranty; not security-audited. Full disclaimer: DISCLAIMER.

Overview

Package errs provides utilities for combining multiple errors. This is a simplified version of https://github.com/uber-go/multierr (MIT License), adapted for the Gno programming language with a focus on core functionality and idiomatic usage patterns.

Example usage:

Example
1err1 := doSomething()
2err2 := doSomethingElse()
3if err := errs.Combine(err1, err2); err != nil {
4    return err // Returns combined errors or single error
5}

Functions 2

func Combine

1func Combine(errs ...error) error
source

Combine merges multiple errors into a single error efficiently. It handles several cases:

  • If all input errors are nil, returns nil
  • If there's exactly one non-nil error, returns that error directly
  • If there are multiple non-nil errors, returns a multiError containing them
  • Flattens any *multiError in the input

func Errors

1func Errors(err error) []error
source

Errors extracts the underlying errors from an error interface. If the error is a multiError, it returns its contained errors. If the error is nil, returns nil. If the error is a regular error, returns a slice containing just that error.

Imports 1

  • strings stdlib

Source Files 3