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

Community realm. Read the code first. Community realm, deployed by its author. Read the code before you interact or send coins.

README.md

1.51 Kb · 43 lines

gno.land/p/nym-moultest123/errs

Combine several errors into one. A port of the core of uber-go/multierr (MIT), trimmed to what gno needs.

1func Combine(errs ...error) error   // nil, the single error, or a *multiError
2func Errors(err error) []error      // unwrap back to the flat list

Combine has three behaviours worth knowing, because they are what make it safe to call unconditionally:

  • all inputs nil gives nil, so if err := errs.Combine(...); err != nil works as written;
  • exactly one non-nil input is returned as itself, not wrapped, so a type assertion or errors.Is upstream still matches;
  • nested *multiError inputs are flattened, so combining in a loop does not build a tree.

The combined error prints two ways: Error() gives one line with ; between messages (for logs and panics), String() gives one error per line (for a Render block).

1err1 := doSomething()
2err2 := doSomethingElse()
3if err := errs.Combine(err1, err2); err != nil {
4	return err
5}

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.