-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from noxer/master
Add an Append function for easier usage of merror
- Loading branch information
Showing
1 changed file
with
25 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |