Skip to content

Commit

Permalink
feat!: remove exported error type
Browse files Browse the repository at this point in the history
Signed-off-by: Mark Sagi-Kazar <[email protected]>
  • Loading branch information
sagikazarmark committed Jun 2, 2024
1 parent cb699d2 commit b94b0f8
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
10 changes: 5 additions & 5 deletions error.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ import (
"strings"
)

// Error implements the error interface and can represents multiple
// joinedError implements the error interface and can represents multiple
// errors that occur in the course of a single decode.
type Error struct {
type joinedError struct {
Errors []string
}

func (e *Error) Error() string {
func (e *joinedError) Error() string {
points := make([]string, len(e.Errors))
for i, err := range e.Errors {
points[i] = fmt.Sprintf("* %s", err)
Expand All @@ -27,7 +27,7 @@ func (e *Error) Error() string {

// 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 {
func (e *joinedError) WrappedErrors() []error {
if e == nil {
return nil
}
Expand All @@ -42,7 +42,7 @@ func (e *Error) WrappedErrors() []error {

func appendErrors(errors []string, err error) []string {
switch e := err.(type) {
case *Error:
case *joinedError:
return append(errors, e.Errors...)
default:
return append(errors, e.Error())
Expand Down
8 changes: 4 additions & 4 deletions mapstructure.go
Original file line number Diff line number Diff line change
Expand Up @@ -923,7 +923,7 @@ func (d *Decoder) decodeMapFromMap(name string, dataVal reflect.Value, val refle

// If we had errors, return those
if len(errors) > 0 {
return &Error{errors}
return &joinedError{errors}
}

return nil
Expand Down Expand Up @@ -1184,7 +1184,7 @@ func (d *Decoder) decodeSlice(name string, data interface{}, val reflect.Value)

// If there were errors, we return those
if len(errors) > 0 {
return &Error{errors}
return &joinedError{errors}
}

return nil
Expand Down Expand Up @@ -1250,7 +1250,7 @@ func (d *Decoder) decodeArray(name string, data interface{}, val reflect.Value)

// If there were errors, we return those
if len(errors) > 0 {
return &Error{errors}
return &joinedError{errors}
}

return nil
Expand Down Expand Up @@ -1495,7 +1495,7 @@ func (d *Decoder) decodeStructFromMap(name string, dataVal, val reflect.Value) e
}

if len(errors) > 0 {
return &Error{errors}
return &joinedError{errors}
}

// Add the unused keys to the list of unused keys if we're tracking metadata
Expand Down
12 changes: 6 additions & 6 deletions mapstructure_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2323,9 +2323,9 @@ func TestInvalidType(t *testing.T) {
t.Fatal("error should exist")
}

derr, ok := err.(*Error)
derr, ok := err.(*joinedError)
if !ok {
t.Fatalf("error should be kind of Error, instead: %#v", err)
t.Fatalf("error should be kind of joinedError, instead: %#v", err)
}

if derr.Errors[0] !=
Expand All @@ -2342,9 +2342,9 @@ func TestInvalidType(t *testing.T) {
t.Fatal("error should exist")
}

derr, ok = err.(*Error)
derr, ok = err.(*joinedError)
if !ok {
t.Fatalf("error should be kind of Error, instead: %#v", err)
t.Fatalf("error should be kind of joinedError, instead: %#v", err)
}

if derr.Errors[0] != "cannot parse 'Vuint', -42 overflows uint" {
Expand All @@ -2360,9 +2360,9 @@ func TestInvalidType(t *testing.T) {
t.Fatal("error should exist")
}

derr, ok = err.(*Error)
derr, ok = err.(*joinedError)
if !ok {
t.Fatalf("error should be kind of Error, instead: %#v", err)
t.Fatalf("error should be kind of joinedError, instead: %#v", err)
}

if derr.Errors[0] != "cannot parse 'Vuint', -42.000000 overflows uint" {
Expand Down

0 comments on commit b94b0f8

Please sign in to comment.