diff options
author | Michael Muré <batolettre@gmail.com> | 2018-09-26 15:55:14 +0200 |
---|---|---|
committer | Michael Muré <batolettre@gmail.com> | 2018-09-26 16:26:50 +0200 |
commit | f969370901f9f6d3c71c0391c74ac933d683e784 (patch) | |
tree | 9230635ac72092f753edc06312d9319c2759f88e /vendor/github.com/mitchellh/mapstructure/error.go | |
parent | 879e147e2be0b6216a00f8141e71647a0be5b566 (diff) | |
download | git-bug-f969370901f9f6d3c71c0391c74ac933d683e784.tar.gz |
graphql: add a general test for the handler/resolvers
Diffstat (limited to 'vendor/github.com/mitchellh/mapstructure/error.go')
-rw-r--r-- | vendor/github.com/mitchellh/mapstructure/error.go | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/vendor/github.com/mitchellh/mapstructure/error.go b/vendor/github.com/mitchellh/mapstructure/error.go new file mode 100644 index 00000000..47a99e5a --- /dev/null +++ b/vendor/github.com/mitchellh/mapstructure/error.go @@ -0,0 +1,50 @@ +package mapstructure + +import ( + "errors" + "fmt" + "sort" + "strings" +) + +// Error implements the error interface and can represents multiple +// errors that occur in the course of a single decode. +type Error struct { + Errors []string +} + +func (e *Error) Error() string { + points := make([]string, len(e.Errors)) + for i, err := range e.Errors { + points[i] = fmt.Sprintf("* %s", err) + } + + sort.Strings(points) + return fmt.Sprintf( + "%d error(s) decoding:\n\n%s", + len(e.Errors), strings.Join(points, "\n")) +} + +// WrappedErrors implements the errwrap.Wrapper interface to make this +// return value more useful with the errwrap and go-multierror libraries. +func (e *Error) WrappedErrors() []error { + if e == nil { + return nil + } + + result := make([]error, len(e.Errors)) + for i, e := range e.Errors { + result[i] = errors.New(e) + } + + return result +} + +func appendErrors(errors []string, err error) []string { + switch e := err.(type) { + case *Error: + return append(errors, e.Errors...) + default: + return append(errors, e.Error()) + } +} |