Created
August 16, 2016 22:21
-
-
Save jnericks/388d5693262f5b313b51fa4d1195fa2c to your computer and use it in GitHub Desktop.
Compose multiple errors into one
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
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