Follow up to #47 with the following changes.
- The tests for AppendInvoke with Close duplicate the tests for
AppendInvoke. These can be merged, and the unit tests for Close only
need to verify whether the Invoker returned by multierr.Close calls
the Close function in the provided io.Closer.
- Replace AppendInvoke example with something more realistic.
- Update changelog.
Add the following APIs:
type Invoker
type Invoke // implements Invoker
func Close(io.Closer) Invoker
func AppendInvoke(*error, Invoker)
Together, these APIs provide support for appending to an error from a
`defer` block.
func foo() (err error) {
file, err := os.Open(..)
if err != nil {
return err
}
defer multierr.AppendInvoke(&err, multierr.Close(file))
// ...
Resolves#46
Co-authored-by: Abhinav Gupta <abg@uber.com>
This adds an AppendInto function that behaves similarly to Append
except, it operates on a `*error` on the left side and it reports
whether the right side error was non-nil.
func AppendInto(*error, error) (errored bool)
Making the left side a pointer aligns with the fast path of `Append`.
Returning whether the right error was non-nil aligns with the standard
`if err := ...; err != nil` pattern.
```diff
-if err := thing(); err != nil {
+if multierr.AppendInto(&err, thing()) {
continue
}
```
Resolves#21