Skip to content

Commit

Permalink
Implement errors.PrettyPrinter for decoding errors
Browse files Browse the repository at this point in the history
  • Loading branch information
waterfountain1996 committed Nov 11, 2024
1 parent 8f36c1b commit c8182b8
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions decode.go
Original file line number Diff line number Diff line change
Expand Up @@ -607,6 +607,16 @@ type unknownFieldError struct {
err error
}

func (e *unknownFieldError) PrettyPrint(p errors.Printer, colored, inclSource bool) error {
var pp errors.PrettyPrinter
if errors.As(e.err, &pp) {
return pp.PrettyPrint(p, colored, inclSource)
}

p.Print(e)
return nil
}

func (e *unknownFieldError) Error() string {
return e.err.Error()
}
Expand All @@ -623,6 +633,16 @@ type duplicateKeyError struct {
err error
}

func (e *duplicateKeyError) PrettyPrint(p errors.Printer, colored, inclSource bool) error {
var pp errors.PrettyPrinter
if errors.As(e.err, &pp) {
return pp.PrettyPrint(p, colored, inclSource)
}

p.Print(e)
return nil
}

func (e *duplicateKeyError) Error() string {
return e.err.Error()
}
Expand Down

0 comments on commit c8182b8

Please sign in to comment.