Skip to content

Commit 92dbe79

Browse files
committed
refactor: as-error-http (idiomatic)
Signed-off-by: Alex Aizman <[email protected]>
1 parent f8d9773 commit 92dbe79

File tree

20 files changed

+36
-48
lines changed

20 files changed

+36
-48
lines changed

ais/backend/ais.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ func extractErrCode(e error, uuid string) (int, error) {
9898
if cos.IsClientTimeout(e) {
9999
return http.StatusRequestTimeout, e
100100
}
101-
herr := cmn.UnwrapErrHTTP(e)
101+
herr := cmn.AsErrHTTP(e)
102102
if herr == nil {
103103
return http.StatusInternalServerError, e
104104
}

ais/htcommon.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,7 @@ func (res *callResult) toErr() error {
427427
return nil
428428
}
429429
// is cmn.ErrHTTP
430-
if herr := cmn.UnwrapErrHTTP(res.err); herr != nil {
430+
if herr := cmn.AsErrHTTP(res.err); herr != nil {
431431
// add status, details
432432
if res.status >= http.StatusBadRequest {
433433
herr.Status = res.status
@@ -467,7 +467,7 @@ func (res *callResult) errorf(format string, a ...any) error {
467467
debug.Assert(res.err != nil)
468468
// add formatted
469469
msg := fmt.Sprintf(format, a...)
470-
if herr := cmn.UnwrapErrHTTP(res.err); herr != nil {
470+
if herr := cmn.AsErrHTTP(res.err); herr != nil {
471471
herr.Message = msg + ": " + herr.Message
472472
res.err = herr
473473
} else {

ais/test/bucket_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ func TestCreateRemoteBucket(t *testing.T) {
342342
if err == nil {
343343
continue
344344
}
345-
herr := cmn.UnwrapErrHTTP(err)
345+
herr := cmn.AsErrHTTP(err)
346346
tassert.Fatalf(t, herr != nil, "expected ErrHTTP, got %v (bucket %q)", err, test.bck.String())
347347
if test.exists {
348348
tassert.Fatalf(t, strings.Contains(herr.Message, "already exists"),
@@ -894,7 +894,7 @@ func TestListObjectsStartAfter(t *testing.T) {
894894
len(lst.Entries), m.num/2,
895895
)
896896
case err != nil:
897-
herr := cmn.UnwrapErrHTTP(err)
897+
herr := cmn.AsErrHTTP(err)
898898
tlog.Logfln("Error is expected here, got %q", herr)
899899
default:
900900
tassert.Errorf(t, false, "expected an error, got nil")

ais/test/maintain_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -577,7 +577,7 @@ func testNodeShutdown(t *testing.T, nodeType string) {
577577
tlog.Logfln("%v", status)
578578
break
579579
}
580-
if herr := cmn.UnwrapErrHTTP(err); herr != nil {
580+
if herr := cmn.AsErrHTTP(err); herr != nil {
581581
tassert.Errorf(t, herr.Status == http.StatusNotFound, "expecting not found, got %+v", herr)
582582
}
583583
time.Sleep(time.Second)
@@ -690,7 +690,7 @@ func TestShutdownListObjects(t *testing.T) {
690690
tlog.Logfln("%v", status)
691691
break
692692
}
693-
herr := cmn.UnwrapErrHTTP(err)
693+
herr := cmn.AsErrHTTP(err)
694694
tassert.Errorf(t, herr.Status == http.StatusNotFound, "expecting not found, got %+v", herr)
695695
time.Sleep(time.Second)
696696
}

ais/test/object_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1621,7 +1621,7 @@ func TestChecksumValidateOnWarmGetForBucket(t *testing.T) {
16211621
func executeTwoGETsForChecksumValidation(proxyURL string, bck cmn.Bck, objName string, isChunked bool, t *testing.T) {
16221622
baseParams := tools.BaseAPIParams(proxyURL)
16231623
_, err := api.GetObjectWithValidation(baseParams, bck, objName, nil)
1624-
herr := cmn.UnwrapErrHTTP(err)
1624+
herr := cmn.AsErrHTTP(err)
16251625
switch {
16261626
case herr == nil:
16271627
t.Error("Error is nil, expected internal server error on a GET for an object")
@@ -1633,7 +1633,7 @@ func executeTwoGETsForChecksumValidation(proxyURL string, bck cmn.Bck, objName s
16331633

16341634
// Execute another GET to make sure that the object is deleted
16351635
_, err = api.GetObjectWithValidation(baseParams, bck, objName, nil)
1636-
herr = cmn.UnwrapErrHTTP(err)
1636+
herr = cmn.AsErrHTTP(err)
16371637
switch {
16381638
case herr == nil:
16391639
t.Error("Error is nil, expected not found on a second GET for a corrupted object")
@@ -2202,7 +2202,7 @@ func TestMultipartMaxChunks(t *testing.T) {
22022202

22032203
// We expect an error because we're exceeding MaxChunkCount
22042204
tassert.Fatalf(t, err != nil, "expected error when exceeding MaxChunkCount, but upload succeeded")
2205-
herr := cmn.UnwrapErrHTTP(err)
2205+
herr := cmn.AsErrHTTP(err)
22062206
tassert.Fatalf(t, herr != nil, "expected ErrHTTP, got %v", err)
22072207
tassert.Fatalf(t, strings.Contains(herr.Message, "exceeds the maximum allowed"),
22082208
"expected error message to contain 'exceeds the maximum allowed', got: %v", err)

api/client.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ func HTTPStatus(err error) int {
7777
if err == nil {
7878
return http.StatusOK
7979
}
80-
if herr := cmn.UnwrapErrHTTP(err); herr != nil {
80+
if herr := cmn.AsErrHTTP(err); herr != nil {
8181
return herr.Status
8282
}
8383
return -1 // invalid

cmd/cli/cli/bucket.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import (
2424
// Creates new ais bucket
2525
func createBucket(c *cli.Context, bck cmn.Bck, props *cmn.BpropsToSet, dontHeadRemote bool) (err error) {
2626
if err = api.CreateBucket(apiBP, bck, props, dontHeadRemote); err != nil {
27-
if herr := cmn.UnwrapErrHTTP(err); herr != nil {
27+
if herr := cmn.AsErrHTTP(err); herr != nil {
2828
if herr.Status == http.StatusConflict {
2929
desc := fmt.Sprintf("Bucket %q already exists", bck.String())
3030
if flagIsSet(c, ignoreErrorFlag) {

cmd/cli/cli/bucket_hdlr.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -566,7 +566,7 @@ func removeSpecificBuckets(c *cli.Context) error {
566566
return nil
567567
}
568568

569-
if herr := cmn.UnwrapErrHTTP(err); herr != nil && herr.TypeCode == "ErrUnsupp" {
569+
if herr := cmn.AsErrHTTP(err); herr != nil && herr.TypeCode == "ErrUnsupp" {
570570
return fmt.Errorf("%v\n(Tip: did you want to evict '%s' from aistore?)", err, bck.Cname(""))
571571
}
572572
return err

cmd/cli/cli/cpr.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ func (cpr *cprCtx) do(c *cli.Context) {
157157
)
158158
xs, cms, err := queryXactions(&xargs, true /*summarize*/)
159159
if err != nil {
160-
if herr := cmn.UnwrapErrHTTP(err); herr != nil && herr.Status == http.StatusNotFound {
160+
if herr := cmn.AsErrHTTP(err); herr != nil && herr.Status == http.StatusNotFound {
161161
briefPause(refreshRateMinDur / time.Second)
162162
continue
163163
}

cmd/cli/cli/err.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ func isUnreachableError(err error) (msg string, unreachable bool) {
126126
return "", false
127127
default:
128128
msg = err.Error()
129-
if herr := cmn.UnwrapErrHTTP(err); herr != nil {
129+
if herr := cmn.AsErrHTTP(err); herr != nil {
130130
unreachable = cos.IsUnreachable(herr, herr.Status)
131131
} else {
132132
regx := regexp.MustCompile("dial.*(timeout|refused)")
@@ -358,7 +358,7 @@ func completionErr(c *cli.Context, err error) {
358358

359359
func notV(err error) error {
360360
if err != nil && !cliConfVerbose() {
361-
if herr := cmn.UnwrapErrHTTP(err); herr != nil {
361+
if herr := cmn.AsErrHTTP(err); herr != nil {
362362
return errors.New(herr.Message)
363363
}
364364
}
@@ -367,7 +367,7 @@ func notV(err error) error {
367367

368368
func V(err error) error {
369369
if err != nil && cliConfVerbose() {
370-
if herr := cmn.UnwrapErrHTTP(err); herr != nil {
370+
if herr := cmn.AsErrHTTP(err); herr != nil {
371371
herr.Message = herr.StringEx()
372372
return herr
373373
}

0 commit comments

Comments
 (0)