From 9e25c61d4dbcbdc9847356585abcfe803e01221f Mon Sep 17 00:00:00 2001 From: Mark Sagi-Kazar Date: Sun, 2 Jun 2024 10:26:13 +0200 Subject: [PATCH] refactor: remove unused joined error Signed-off-by: Mark Sagi-Kazar --- error.go | 50 -------------------------------------------------- 1 file changed, 50 deletions(-) delete mode 100644 error.go diff --git a/error.go b/error.go deleted file mode 100644 index 65624fc..0000000 --- a/error.go +++ /dev/null @@ -1,50 +0,0 @@ -package mapstructure - -import ( - "errors" - "fmt" - "sort" - "strings" -) - -// joinedError implements the error interface and can represents multiple -// errors that occur in the course of a single decode. -type joinedError struct { - Errors []string -} - -func (e *joinedError) 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")) -} - -// Unwrap implements the Unwrap function added in Go 1.20. -func (e *joinedError) Unwrap() []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 -} - -// TODO: replace with errors.Join when Go 1.20 is minimum version. -func appendErrors(errors []string, err error) []string { - switch e := err.(type) { - case *joinedError: - return append(errors, e.Errors...) - default: - return append(errors, e.Error()) - } -}