Skip to content

Instantly share code, notes, and snippets.

@jnericks
Created August 16, 2016 22:21
Show Gist options
  • Save jnericks/388d5693262f5b313b51fa4d1195fa2c to your computer and use it in GitHub Desktop.
Save jnericks/388d5693262f5b313b51fa4d1195fa2c to your computer and use it in GitHub Desktop.
Compose multiple errors into one
package main
import "fmt"
// Errors allows you to compose multiple errors
type Errors []error
func (e Errors) Error() string {
if len(e) == 1 {
return e[0].Error()
}
msg := "multiple errors:"
for i, err := range e {
msg = fmt.Sprintf("%s\n\t%2d: %s", msg, i, err.Error())
}
return msg
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment