Commit Graph

5 Commits

Author SHA1 Message Date
Abhinav Gupta 520752cf5f Update license headers everywhere
License headers should be a range, not just the current year.
2021-05-06 10:23:05 -07:00
Abhinav Gupta 1014a7cd66
AppendInvoke: Merge test, real example (#48)
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.
2021-05-06 10:21:19 -07:00
baez90 a402392041
Add AppendInvoke (#47)
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>
2021-05-06 08:13:15 -07:00
Abhinav Gupta 60a318af5f
Add AppendInto function (#31)
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
2019-11-04 10:23:04 -08:00
Abhinav Gupta 9f702f5fed Add example tests (#20) 2017-06-28 09:54:24 -07:00