Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Try to stdlib errors.Unwrap errors as well #1660

Closed
wants to merge 6 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions lib/netext/httpext/error_codes.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ package httpext
import (
"crypto/tls"
"crypto/x509"
stderrors "errors"
"fmt"
"net"
"net/url"
Expand Down Expand Up @@ -79,7 +80,7 @@ const (
// errors till 1651 + 13 are other HTTP2 Connection errors with a specific errCode

// Custom k6 content errors, i.e. when the magic fails
//defaultContentError errCode = 1700 // reserved for future use
// defaultContentError errCode = 1700 // reserved for future use
responseDecompressionErrorCode errCode = 1701
)

Expand Down Expand Up @@ -107,7 +108,25 @@ func http2ErrCodeOffset(code http2.ErrCode) errCode {

// errorCodeForError returns the errorCode and a specific error message for given error.
func errorCodeForError(err error) (errCode, string) {
switch e := errors.Cause(err).(type) {
inner := stderrors.Unwrap(err)
if inner != nil && inner != err {
code, resultErr := errorCodeForError(inner)
if code != defaultErrorCode {
return code, resultErr
}
}
mstoykov marked this conversation as resolved.
Show resolved Hide resolved

causeErr := errors.Cause(err)

inner = stderrors.Unwrap(causeErr)
if inner != nil && inner != causeErr {
code, resultErr := errorCodeForError(inner)
if code != defaultErrorCode {
return code, resultErr
}
}

switch e := errors.Cause(causeErr).(type) {
case K6Error:
return e.Code, e.Message
case *net.DNSError:
Expand Down