Skip to content

Commit

Permalink
replace Error.Err with Error.Wrap()
Browse files Browse the repository at this point in the history
  • Loading branch information
quartzmo committed Nov 4, 2022
1 parent 40cbb9b commit bf388e0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
12 changes: 9 additions & 3 deletions googleapi/googleapi.go
Expand Up @@ -79,8 +79,9 @@ type Error struct {
Header http.Header

Errors []ErrorItem
// Err is a wrapped apierror.APIError, typically derived from this Error.
Err error
// err is typically a wrapped apierror.APIError, see
// google-api-go-client/internal/gensupport/error.go.
err error
}

// ErrorItem is a detailed error code & message from the Google API frontend.
Expand Down Expand Up @@ -124,8 +125,13 @@ func (e *Error) Error() string {
return buf.String()
}

// Wrap allows an existing Error to wrap another error. See also [Error.Unwrap].
func (e *Error) Wrap(err error) {
e.err = err
}

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

type errorReply struct {
Expand Down
2 changes: 1 addition & 1 deletion internal/gensupport/error.go
Expand Up @@ -19,7 +19,7 @@ func WrapError(err error) error {
apiError, ok := apierror.ParseError(err, false)
var herr *googleapi.Error
if ok && errors.As(err, &herr) {
herr.Err = apiError
herr.Wrap(apiError)
}
return err
}

0 comments on commit bf388e0

Please sign in to comment.