From 170b8b4b12be50eeccbcdadb8523fb4fc670ca72 Mon Sep 17 00:00:00 2001 From: Damien Neil Date: Wed, 27 Mar 2019 08:40:12 -0700 Subject: all: add Unwrap and Is methods to various error types Add Unwrap methods to types which wrap an underlying error: "encodinc/csv".ParseError "encoding/json".MarshalerError "net/http".transportReadFromServerError "net".OpError "net".DNSConfigError "net/url".Error "os/exec".Error "signal/internal/pty".PtyError "text/template".ExecError Add os.ErrTemporary. A case could be made for putting this error value in package net, since no exported error types in package os include a Temporary method. However, syscall errors returned from the os package do include this method. Add Is methods to error types with a Timeout or Temporary method, making errors.Is(err, os.Err{Timeout,Temporary}) equivalent to testing the corresponding method: "context".DeadlineExceeded "internal/poll".TimeoutError "net".adrinfoErrno "net".OpError "net".DNSError "net/http".httpError "net/http".tlsHandshakeTimeoutError "net/pipe".timeoutError "net/url".Error Updates #30322 Updates #29934 Change-Id: I409fb20c072ea39116ebfb8c7534d493483870dc Reviewed-on: https://go-review.googlesource.com/c/go/+/170037 Run-TryBot: Damien Neil TryBot-Result: Gobot Gobot Reviewed-by: Marcel van Lohuizen --- src/encoding/json/encode.go | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/encoding/json/encode.go') diff --git a/src/encoding/json/encode.go b/src/encoding/json/encode.go index 383460e52b..464ee3ece4 100644 --- a/src/encoding/json/encode.go +++ b/src/encoding/json/encode.go @@ -270,6 +270,8 @@ func (e *MarshalerError) Error() string { return "json: error calling MarshalJSON for type " + e.Type.String() + ": " + e.Err.Error() } +func (e *MarshalerError) Unwrap() error { return e.Err } + var hex = "0123456789abcdef" // An encodeState encodes JSON into a bytes.Buffer. -- cgit v1.3