Skip to content

Commit 637c5ed

Browse files
authored
Update to latest internal module (#21872)
* Update to latest internal module Used NonRetriableError from internal. * update perf test
1 parent f0b1058 commit 637c5ed

File tree

11 files changed

+45
-66
lines changed

11 files changed

+45
-66
lines changed

Diff for: sdk/azcore/fake/fake.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ import (
1414

1515
"github.com/Azure/azure-sdk-for-go/sdk/azcore"
1616
"github.com/Azure/azure-sdk-for-go/sdk/azcore/fake/internal/exported"
17-
"github.com/Azure/azure-sdk-for-go/sdk/azcore/internal/shared"
1817
"github.com/Azure/azure-sdk-for-go/sdk/azcore/policy"
18+
"github.com/Azure/azure-sdk-for-go/sdk/internal/errorinfo"
1919
)
2020

2121
// TokenCredential is a fake credential that implements the azcore.TokenCredential interface.
@@ -26,13 +26,13 @@ type TokenCredential struct {
2626
// SetError sets the specified error to be returned from GetToken().
2727
// Use this to simulate an error during authentication.
2828
func (t *TokenCredential) SetError(err error) {
29-
t.err = shared.NonRetriableError(err)
29+
t.err = errorinfo.NonRetriableError(err)
3030
}
3131

3232
// GetToken implements the azcore.TokenCredential for the TokenCredential type.
3333
func (t *TokenCredential) GetToken(ctx context.Context, opts policy.TokenRequestOptions) (azcore.AccessToken, error) {
3434
if t.err != nil {
35-
return azcore.AccessToken{}, shared.NonRetriableError(t.err)
35+
return azcore.AccessToken{}, errorinfo.NonRetriableError(t.err)
3636
}
3737
return azcore.AccessToken{Token: "fake_token", ExpiresOn: time.Now().Add(24 * time.Hour)}, nil
3838
}

Diff for: sdk/azcore/fake/internal/exported/fake.go

+19-18
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
"github.com/Azure/azure-sdk-for-go/sdk/azcore"
2020
"github.com/Azure/azure-sdk-for-go/sdk/azcore/internal/exported"
2121
"github.com/Azure/azure-sdk-for-go/sdk/azcore/internal/shared"
22+
"github.com/Azure/azure-sdk-for-go/sdk/internal/errorinfo"
2223
)
2324

2425
// Responder represents a scalar response.
@@ -68,14 +69,14 @@ type ErrorResponder struct {
6869
// SetError sets the specified error to be returned.
6970
// Use SetResponseError for returning an *azcore.ResponseError.
7071
func (e *ErrorResponder) SetError(err error) {
71-
e.err = shared.NonRetriableError(err)
72+
e.err = errorinfo.NonRetriableError(err)
7273
}
7374

7475
// SetResponseError sets an *azcore.ResponseError with the specified values to be returned.
7576
// - errorCode is the value to be used in the ResponseError.Code field
7677
// - httpStatus is the HTTP status code
7778
func (e *ErrorResponder) SetResponseError(httpStatus int, errorCode string) {
78-
e.err = shared.NonRetriableError(&exported.ResponseError{ErrorCode: errorCode, StatusCode: httpStatus})
79+
e.err = errorinfo.NonRetriableError(&exported.ResponseError{ErrorCode: errorCode, StatusCode: httpStatus})
7980
}
8081

8182
// GetError returns the error for this responder.
@@ -90,11 +91,11 @@ func (e ErrorResponder) GetError(req *http.Request) error {
9091
// fix up the raw response
9192
rawResp, err := newErrorResponse(respErr.StatusCode, respErr.ErrorCode, req)
9293
if err != nil {
93-
return shared.NonRetriableError(err)
94+
return errorinfo.NonRetriableError(err)
9495
}
9596
respErr.RawResponse = rawResp
9697
}
97-
return shared.NonRetriableError(e.err)
98+
return errorinfo.NonRetriableError(e.err)
9899
}
99100

100101
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -115,13 +116,13 @@ func (p *PagerResponder[T]) AddPage(httpStatus int, page T, o *AddPageOptions) {
115116
// AddError adds an error to the sequence of responses.
116117
// The error is returned from the call to runtime.Pager[T].NextPage().
117118
func (p *PagerResponder[T]) AddError(err error) {
118-
p.pages = append(p.pages, shared.NonRetriableError(err))
119+
p.pages = append(p.pages, errorinfo.NonRetriableError(err))
119120
}
120121

121122
// AddResponseError adds an *azcore.ResponseError to the sequence of responses.
122123
// The error is returned from the call to runtime.Pager[T].NextPage().
123124
func (p *PagerResponder[T]) AddResponseError(httpStatus int, errorCode string) {
124-
p.pages = append(p.pages, shared.NonRetriableError(&exported.ResponseError{ErrorCode: errorCode, StatusCode: httpStatus}))
125+
p.pages = append(p.pages, errorinfo.NonRetriableError(&exported.ResponseError{ErrorCode: errorCode, StatusCode: httpStatus}))
125126
}
126127

127128
// AddPageOptions contains the optional values for PagerResponder[T].AddPage.
@@ -133,7 +134,7 @@ type AddPageOptions struct {
133134
// This function is called by the fake server internals.
134135
func (p *PagerResponder[T]) Next(req *http.Request) (*http.Response, error) {
135136
if len(p.pages) == 0 {
136-
return nil, shared.NonRetriableError(errors.New("fake paged response is empty"))
137+
return nil, errorinfo.NonRetriableError(errors.New("fake paged response is empty"))
137138
}
138139

139140
page := p.pages[0]
@@ -143,15 +144,15 @@ func (p *PagerResponder[T]) Next(req *http.Request) (*http.Response, error) {
143144
if ok {
144145
body, err := json.Marshal(pageT.entry)
145146
if err != nil {
146-
return nil, shared.NonRetriableError(err)
147+
return nil, errorinfo.NonRetriableError(err)
147148
}
148149
content := ResponseContent{
149150
HTTPStatus: pageT.httpStatus,
150151
Header: http.Header{},
151152
}
152153
resp, err := NewResponse(content, req)
153154
if err != nil {
154-
return nil, shared.NonRetriableError(err)
155+
return nil, errorinfo.NonRetriableError(err)
155156
}
156157
return SetResponseBody(resp, body, shared.ContentTypeAppJSON), nil
157158
}
@@ -162,11 +163,11 @@ func (p *PagerResponder[T]) Next(req *http.Request) (*http.Response, error) {
162163
// fix up the raw response
163164
rawResp, err := newErrorResponse(respErr.StatusCode, respErr.ErrorCode, req)
164165
if err != nil {
165-
return nil, shared.NonRetriableError(err)
166+
return nil, errorinfo.NonRetriableError(err)
166167
}
167168
respErr.RawResponse = rawResp
168169
}
169-
return nil, shared.NonRetriableError(err)
170+
return nil, errorinfo.NonRetriableError(err)
170171
}
171172

172173
// More returns true if there are more responses for consumption.
@@ -273,7 +274,7 @@ func (p *PollerResponder[T]) Next(req *http.Request) (*http.Response, error) {
273274
p.nonTermResps = p.nonTermResps[1:]
274275

275276
if resp.err != nil {
276-
return nil, shared.NonRetriableError(resp.err)
277+
return nil, errorinfo.NonRetriableError(resp.err)
277278
}
278279

279280
content := ResponseContent{
@@ -282,7 +283,7 @@ func (p *PollerResponder[T]) Next(req *http.Request) (*http.Response, error) {
282283
}
283284
httpResp, err := NewResponse(content, req)
284285
if err != nil {
285-
return nil, shared.NonRetriableError(err)
286+
return nil, errorinfo.NonRetriableError(err)
286287
}
287288
httpResp.Header.Set(shared.HeaderFakePollerStatus, resp.status)
288289

@@ -297,15 +298,15 @@ func (p *PollerResponder[T]) Next(req *http.Request) (*http.Response, error) {
297298
respErr := p.err
298299
rawResp, err := newErrorResponse(p.err.StatusCode, p.err.ErrorCode, req)
299300
if err != nil {
300-
return nil, shared.NonRetriableError(err)
301+
return nil, errorinfo.NonRetriableError(err)
301302
}
302303
respErr.RawResponse = rawResp
303304
p.err = nil
304-
return nil, shared.NonRetriableError(respErr)
305+
return nil, errorinfo.NonRetriableError(respErr)
305306
} else if p.res != nil {
306307
body, err := json.Marshal(*p.res)
307308
if err != nil {
308-
return nil, shared.NonRetriableError(err)
309+
return nil, errorinfo.NonRetriableError(err)
309310
}
310311
p.res = nil
311312
content := ResponseContent{
@@ -314,13 +315,13 @@ func (p *PollerResponder[T]) Next(req *http.Request) (*http.Response, error) {
314315
}
315316
resp, err := NewResponse(content, req)
316317
if err != nil {
317-
return nil, shared.NonRetriableError(err)
318+
return nil, errorinfo.NonRetriableError(err)
318319
}
319320
httpResp := SetResponseBody(resp, body, shared.ContentTypeAppJSON)
320321
httpResp.Header.Set(shared.HeaderFakePollerStatus, "Succeeded")
321322
return httpResp, nil
322323
} else {
323-
return nil, shared.NonRetriableError(errors.New("fake poller response is emtpy"))
324+
return nil, errorinfo.NonRetriableError(errors.New("fake poller response is emtpy"))
324325
}
325326
}
326327

Diff for: sdk/azcore/fake/server/server.go

+10-9
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
azexported "github.com/Azure/azure-sdk-for-go/sdk/azcore/internal/exported"
2020
fakepoller "github.com/Azure/azure-sdk-for-go/sdk/azcore/internal/pollers/fake"
2121
"github.com/Azure/azure-sdk-for-go/sdk/azcore/internal/shared"
22+
"github.com/Azure/azure-sdk-for-go/sdk/internal/errorinfo"
2223
)
2324

2425
// ResponseContent is used when building the *http.Response.
@@ -64,7 +65,7 @@ func MarshalResponseAsByteArray(content ResponseContent, body []byte, format aze
6465
func MarshalResponseAsJSON(content ResponseContent, v any, req *http.Request) (*http.Response, error) {
6566
body, err := json.Marshal(v)
6667
if err != nil {
67-
return nil, shared.NonRetriableError(err)
68+
return nil, errorinfo.NonRetriableError(err)
6869
}
6970
resp, err := exported.NewResponse(content, req)
7071
if err != nil {
@@ -94,7 +95,7 @@ func MarshalResponseAsText(content ResponseContent, body *string, req *http.Requ
9495
func MarshalResponseAsXML(content ResponseContent, v any, req *http.Request) (*http.Response, error) {
9596
body, err := xml.Marshal(v)
9697
if err != nil {
97-
return nil, shared.NonRetriableError(err)
98+
return nil, errorinfo.NonRetriableError(err)
9899
}
99100
resp, err := exported.NewResponse(content, req)
100101
if err != nil {
@@ -112,12 +113,12 @@ func UnmarshalRequestAsByteArray(req *http.Request, format azexported.Base64Enco
112113
}
113114
body, err := io.ReadAll(req.Body)
114115
if err != nil {
115-
return nil, shared.NonRetriableError(err)
116+
return nil, errorinfo.NonRetriableError(err)
116117
}
117118
req.Body.Close()
118119
var val []byte
119120
if err := azexported.DecodeByteArray(string(body), &val, format); err != nil {
120-
return nil, shared.NonRetriableError(err)
121+
return nil, errorinfo.NonRetriableError(err)
121122
}
122123
return val, nil
123124
}
@@ -131,11 +132,11 @@ func UnmarshalRequestAsJSON[T any](req *http.Request) (T, error) {
131132
}
132133
body, err := io.ReadAll(req.Body)
133134
if err != nil {
134-
return tt, shared.NonRetriableError(err)
135+
return tt, errorinfo.NonRetriableError(err)
135136
}
136137
req.Body.Close()
137138
if err = json.Unmarshal(body, &tt); err != nil {
138-
err = shared.NonRetriableError(err)
139+
err = errorinfo.NonRetriableError(err)
139140
}
140141
return tt, err
141142
}
@@ -148,7 +149,7 @@ func UnmarshalRequestAsText(req *http.Request) (string, error) {
148149
}
149150
body, err := io.ReadAll(req.Body)
150151
if err != nil {
151-
return "", shared.NonRetriableError(err)
152+
return "", errorinfo.NonRetriableError(err)
152153
}
153154
req.Body.Close()
154155
return string(body), nil
@@ -163,11 +164,11 @@ func UnmarshalRequestAsXML[T any](req *http.Request) (T, error) {
163164
}
164165
body, err := io.ReadAll(req.Body)
165166
if err != nil {
166-
return tt, shared.NonRetriableError(err)
167+
return tt, errorinfo.NonRetriableError(err)
167168
}
168169
req.Body.Close()
169170
if err = xml.Unmarshal(body, &tt); err != nil {
170-
err = shared.NonRetriableError(err)
171+
err = errorinfo.NonRetriableError(err)
171172
}
172173
return tt, err
173174
}

Diff for: sdk/azcore/go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module github.com/Azure/azure-sdk-for-go/sdk/azcore
33
go 1.18
44

55
require (
6-
github.com/Azure/azure-sdk-for-go/sdk/internal v1.4.0
6+
github.com/Azure/azure-sdk-for-go/sdk/internal v1.5.0
77
github.com/stretchr/testify v1.8.4
88
golang.org/x/net v0.17.0
99
)

Diff for: sdk/azcore/go.sum

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
github.com/Azure/azure-sdk-for-go/sdk/internal v1.4.0 h1:TuEMD+E+1aTjjLICGQOW6vLe8UWES7kopac9mUXL56Y=
2-
github.com/Azure/azure-sdk-for-go/sdk/internal v1.4.0/go.mod h1:s4kgfzA0covAXNicZHDMN58jExvcng2mC/DepXiF1EI=
1+
github.com/Azure/azure-sdk-for-go/sdk/internal v1.5.0 h1:d81/ng9rET2YqdVkVwkb6EXeRrLJIwyGnJcAlAWKwhs=
2+
github.com/Azure/azure-sdk-for-go/sdk/internal v1.5.0/go.mod h1:s4kgfzA0covAXNicZHDMN58jExvcng2mC/DepXiF1EI=
33
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
44
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
55
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=

Diff for: sdk/azcore/internal/shared/shared.go

-25
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ import (
1414
"regexp"
1515
"strconv"
1616
"time"
17-
18-
"github.com/Azure/azure-sdk-for-go/sdk/internal/errorinfo"
1917
)
2018

2119
// NOTE: when adding a new context key type, it likely needs to be
@@ -131,26 +129,3 @@ func (c *ContextWithDeniedValues) Value(key any) any {
131129
return c.Context.Value(key)
132130
}
133131
}
134-
135-
// NonRetriableError marks the specified error as non-retriable.
136-
func NonRetriableError(err error) error {
137-
return &nonRetriableError{err}
138-
}
139-
140-
type nonRetriableError struct {
141-
error
142-
}
143-
144-
func (p *nonRetriableError) Error() string {
145-
return p.error.Error()
146-
}
147-
148-
func (*nonRetriableError) NonRetriable() {
149-
// marker method
150-
}
151-
152-
func (p *nonRetriableError) Unwrap() error {
153-
return p.error
154-
}
155-
156-
var _ errorinfo.NonRetriable = (*nonRetriableError)(nil)

Diff for: sdk/azcore/runtime/policy_bearer_token.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"github.com/Azure/azure-sdk-for-go/sdk/azcore/internal/exported"
1313
"github.com/Azure/azure-sdk-for-go/sdk/azcore/internal/shared"
1414
"github.com/Azure/azure-sdk-for-go/sdk/azcore/policy"
15+
"github.com/Azure/azure-sdk-for-go/sdk/internal/errorinfo"
1516
"github.com/Azure/azure-sdk-for-go/sdk/internal/temporal"
1617
)
1718

@@ -90,7 +91,7 @@ func (b *BearerTokenPolicy) Do(req *policy.Request) (*http.Response, error) {
9091
err = b.authenticateAndAuthorize(req)(policy.TokenRequestOptions{Scopes: b.scopes})
9192
}
9293
if err != nil {
93-
return nil, shared.NonRetriableError(err)
94+
return nil, errorinfo.NonRetriableError(err)
9495
}
9596

9697
res, err := req.Next()
@@ -107,14 +108,14 @@ func (b *BearerTokenPolicy) Do(req *policy.Request) (*http.Response, error) {
107108
}
108109
}
109110
if err != nil {
110-
err = shared.NonRetriableError(err)
111+
err = errorinfo.NonRetriableError(err)
111112
}
112113
return res, err
113114
}
114115

115116
func checkHTTPSForAuth(req *policy.Request) error {
116117
if strings.ToLower(req.Raw().URL.Scheme) != "https" {
117-
return shared.NonRetriableError(errors.New("authenticated requests are not permitted for non TLS protected (https) endpoints"))
118+
return errorinfo.NonRetriableError(errors.New("authenticated requests are not permitted for non TLS protected (https) endpoints"))
118119
}
119120
return nil
120121
}

Diff for: sdk/azcore/runtime/policy_bearer_token_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ func TestBearerTokenPolicy_AuthZHandlerErrors(t *testing.T) {
206206
// the policy should propagate the handler's errors, wrapping them to make them nonretriable, if necessary
207207
fatalErr := errors.New("something went wrong")
208208
var nre errorinfo.NonRetriable
209-
for i, e := range []error{fatalErr, shared.NonRetriableError(fatalErr)} {
209+
for i, e := range []error{fatalErr, errorinfo.NonRetriableError(fatalErr)} {
210210
handler.onReqErr = e
211211
_, err = pl.Do(req)
212212
require.ErrorAs(t, err, &nre)

Diff for: sdk/azcore/runtime/poller_test.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626
"github.com/Azure/azure-sdk-for-go/sdk/azcore/internal/pollers/fake"
2727
"github.com/Azure/azure-sdk-for-go/sdk/azcore/internal/shared"
2828
"github.com/Azure/azure-sdk-for-go/sdk/azcore/policy"
29+
"github.com/Azure/azure-sdk-for-go/sdk/internal/errorinfo"
2930
"github.com/Azure/azure-sdk-for-go/sdk/internal/mock"
3031
"github.com/Azure/azure-sdk-for-go/sdk/internal/poller"
3132
"github.com/stretchr/testify/require"
@@ -399,7 +400,7 @@ func TestOpPollerWithWidgetFinalGetError(t *testing.T) {
399400
srv.AppendResponse(mock.WithStatusCode(http.StatusOK), mock.WithBody([]byte(`{"status": "Succeeded"}`)))
400401
// PUT and PATCH state that a final GET will happen
401402
// the first attempt at a final GET returns an error
402-
srv.AppendError(shared.NonRetriableError(errors.New("failed attempt")))
403+
srv.AppendError(errorinfo.NonRetriableError(errors.New("failed attempt")))
403404
srv.AppendResponse(mock.WithStatusCode(http.StatusOK), mock.WithBody([]byte(`{"size": 2}`)))
404405
defer close()
405406

Diff for: sdk/azcore/testdata/perf/go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ go 1.18
44

55
require (
66
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.8.0
7-
github.com/Azure/azure-sdk-for-go/sdk/internal v1.4.0
7+
github.com/Azure/azure-sdk-for-go/sdk/internal v1.5.0
88
)
99

1010
require (

Diff for: sdk/azcore/testdata/perf/go.sum

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
github.com/Azure/azure-sdk-for-go/sdk/internal v1.4.0 h1:TuEMD+E+1aTjjLICGQOW6vLe8UWES7kopac9mUXL56Y=
2-
github.com/Azure/azure-sdk-for-go/sdk/internal v1.4.0/go.mod h1:s4kgfzA0covAXNicZHDMN58jExvcng2mC/DepXiF1EI=
1+
github.com/Azure/azure-sdk-for-go/sdk/internal v1.5.0 h1:d81/ng9rET2YqdVkVwkb6EXeRrLJIwyGnJcAlAWKwhs=
2+
github.com/Azure/azure-sdk-for-go/sdk/internal v1.5.0/go.mod h1:s4kgfzA0covAXNicZHDMN58jExvcng2mC/DepXiF1EI=
33
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
44
github.com/dnaeon/go-vcr v1.2.0 h1:zHCHvJYTMh1N7xnV7zf1m1GPBF9Ad0Jk/whtQ1663qI=
55
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=

0 commit comments

Comments
 (0)