matterbridge/vendor/github.com/wiggin77/merror
Wim d16645c952
Update mattermost library (#2152)
* Update mattermost library

* Fix linting
2024-05-24 23:08:09 +02:00
..
.gitignore Update vendor (#1265) 2020-10-19 23:40:00 +02:00
append.go Update mattermost library (#2152) 2024-05-24 23:08:09 +02:00
format.go Update vendor (#1265) 2020-10-19 23:40:00 +02:00
LICENSE Update vendor (#1265) 2020-10-19 23:40:00 +02:00
merror.go Update mattermost library (#2152) 2024-05-24 23:08:09 +02:00
README.md Update mattermost library (#2152) 2024-05-24 23:08:09 +02:00

merror

GoDoc Build Status

Multiple Error aggregator for Go.

Usage

func foo() error {
  merr := merror.New()

  if err := DoSomething(); err != nil {
    merr.Append(err)
  }

  return merr.ErrorOrNil()
}

A bounded merror can be used to guard against memory ballooning.

func bar() error {
  merr := merror.NewWithCap(10)

  for i := 0; i < 15; i++ {
    if err := DoSomething(); err != nil {
      merr.Append(err)
    }
  }

  fmt.Printf("Len: %d,  Overflow: %d", merr.Len(), merr.Overflow()) 
  // Len: 10,  Overflow: 5

  return merr.ErrorOrNil()
}

errors.Is

If any of the errors appended to a merror match the target error passed to errors.Is(err, target error) then true is returned.

errors.As

If any of the errors appended to a merror match the target type passed to errors.As(err error, target any) then true is returned and the target is set to the matching error.