Skip to content

Commit

Permalink
fix: correct tests and implement Unwrap method
Browse files Browse the repository at this point in the history
  • Loading branch information
nieomylnieja committed Feb 3, 2024
1 parent 115ebb1 commit 683ac4f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
8 changes: 8 additions & 0 deletions decode.go
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,10 @@ func (e *unknownFieldError) Error() string {
return e.err.Error()
}

func (e *unknownFieldError) Unwrap() error {
return e.err
}

func errUnknownField(msg string, tk *token.Token) *unknownFieldError {
return &unknownFieldError{err: errors.ErrSyntax(msg, tk)}
}
Expand All @@ -550,6 +554,10 @@ func (e *duplicateKeyError) Error() string {
return e.err.Error()
}

func (e *duplicateKeyError) Unwrap() error {
return e.err
}

func errDuplicateKey(msg string, tk *token.Token) *duplicateKeyError {
return &duplicateKeyError{err: errors.ErrSyntax(msg, tk)}
}
Expand Down
8 changes: 5 additions & 3 deletions error_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@ package yaml
import (
"testing"

"golang.org/x/xerrors"

"github.com/goccy/go-yaml/internal/errors"
"github.com/goccy/go-yaml/token"
"golang.org/x/xerrors"
)

func TestAsSyntaxError(t *testing.T) {
Expand Down Expand Up @@ -52,7 +51,10 @@ func TestAsSyntaxError(t *testing.T) {
if syntaxErr != nil {
t.Fatalf("wanted nil, but go %v", syntaxErr)
}
return
continue
}
if syntaxErr == nil {
t.Fatalf("must not be nil")
}
if *test.expected.Token != *syntaxErr.Token && test.expected.Msg != syntaxErr.Msg {
t.Fatalf("unexpected output.\nexpect:\n[%v]\nactual:\n[%v]", test.expected, syntaxErr)
Expand Down

0 comments on commit 683ac4f

Please sign in to comment.