Skip to content

Commit

Permalink
Merge pull request #1 from noxer/master
Browse files Browse the repository at this point in the history
Add an Append function for easier usage of merror
  • Loading branch information
wiggin77 authored Aug 17, 2022
2 parents 77a531f + 9a0862b commit 673e356
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions append.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package merror

// Append an error to a multi-error.
// If `to` is `nil` it will just assign `err`.
// If `to` is not a `*MError` it will create a new `*MError` and append both errors.
// If `err` is `nil` it will just return `to`.
// Otherwise it will just append to the existing `*MError`.
func Append(to, err error) error {
if err == nil {
return to
}
if to == nil {
return err
}

if merr, ok := to.(*MError); ok {
merr.Append(err)
return merr
}

merr := New()
merr.Append(to)
merr.Append(err)
return merr
}

0 comments on commit 673e356

Please sign in to comment.