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

v0 source pure

v0 - Unaudited: This is an initial version that has not yet been formally audited. A fully audited version will be pu...

Readme View source

v0 - Unaudited This is an initial version of this package that has not yet been formally audited. A fully audited version will be published as a subsequent release. Use in production at your own risk.

combinederr - Aggregate multiple errors

Collect several errors into a single error value with a semicolon-separated message. Useful for batch operations where you want to report every failure instead of bailing on the first.

Usage

 1import "gno.land/p/nt/combinederr/v0"
 2
 3ce := &combinederr.CombinedError{}
 4ce.Add(validateName(name))   // nil is silently skipped
 5ce.Add(validateEmail(email))
 6ce.Add(validateAge(age))
 7
 8if ce.Size() > 0 {
 9    return ce // "invalid name; bad email; age must be > 0"
10}
11return nil

API

 1// CombinedError aggregates multiple errors into a single error value.
 2type CombinedError struct { /* ... */ }
 3
 4// Add appends err to the combined error. Nil errors are ignored.
 5func (e *CombinedError) Add(err error)
 6
 7// Error returns all collected errors joined with "; ".
 8func (e *CombinedError) Error() string
 9
10// Size returns the number of collected errors.
11func (e *CombinedError) Size() int

Notes

  • A zero-value CombinedError{} with no errors added has Size() == 0 and Error() == "".
  • The pointer receiver on Add means you must use &CombinedError{}.
  • Aggregation is message-only: there is no Unwrap, so errors.Is/errors.As never see the collected errors. Use it when you want one human-readable combined string, not typed error matching.

Overview

v0 - Unaudited: This is an initial version that has not yet been formally audited. A fully audited version will be published as a subsequent release. Use in production at your own risk.

Package combinederr provides a combined error type for aggregating multiple errors into a single error value.

Types 1

type CombinedError

struct
1type CombinedError struct {
2	errors []error
3}
source

CombinedError is a combined execution error

Methods on CombinedError

func Add

method on CombinedError
1func (e *CombinedError) Add(err error)
source

Add adds a new error to the execution error

func Error

method on CombinedError
1func (e *CombinedError) Error() string
source

Error returns the combined execution error

func Size

method on CombinedError
1func (e *CombinedError) Size() int
source

Size returns a

Imports 1

  • strings stdlib

Source Files 4