use errors.AsErr (#1849)

Co-authored-by: Manu Gupta <manugupt1@gmail.com>
This commit is contained in:
Zhongpeng Lin
2023-03-12 22:04:12 -07:00
committed by GitHub
parent 96f7cb8975
commit b72a768a05
2 changed files with 5 additions and 7 deletions
+1 -2
View File
@@ -2,7 +2,6 @@ package s3
import (
"context"
errs "errors"
"sync"
"github.com/aws/aws-sdk-go/aws"
@@ -46,7 +45,7 @@ func (s *Storage) Exists(ctx context.Context, module, version string) (bool, err
continue
}
var aerr awserr.Error
if errs.As(err, &aerr) && aerr.Code() == "NotFound" {
if errors.AsErr(err, &aerr) && aerr.Code() == "NotFound" {
err = nil
exists = false
}
+4 -5
View File
@@ -2,7 +2,6 @@ package s3
import (
"context"
errs "errors"
"fmt"
"io"
@@ -24,7 +23,7 @@ func (s *Storage) Info(ctx context.Context, module, version string) ([]byte, err
infoReader, err := s.open(ctx, config.PackageVersionedName(module, version, "info"))
if err != nil {
var aerr awserr.Error
if errs.As(err, &aerr) && aerr.Code() == s3.ErrCodeNoSuchKey {
if errors.AsErr(err, &aerr) && aerr.Code() == s3.ErrCodeNoSuchKey {
return nil, errors.E(op, errors.M(module), errors.V(version), errors.KindNotFound)
}
return nil, errors.E(op, err, errors.M(module), errors.V(version))
@@ -47,7 +46,7 @@ func (s *Storage) GoMod(ctx context.Context, module, version string) ([]byte, er
modReader, err := s.open(ctx, config.PackageVersionedName(module, version, "mod"))
if err != nil {
var aerr awserr.Error
if errs.As(err, &aerr) && aerr.Code() == s3.ErrCodeNoSuchKey {
if errors.AsErr(err, &aerr) && aerr.Code() == s3.ErrCodeNoSuchKey {
return nil, errors.E(op, errors.M(module), errors.V(version), errors.KindNotFound)
}
return nil, errors.E(op, err, errors.M(module), errors.V(version))
@@ -71,7 +70,7 @@ func (s *Storage) Zip(ctx context.Context, module, version string) (storage.Size
zipReader, err := s.open(ctx, config.PackageVersionedName(module, version, "zip"))
if err != nil {
var aerr awserr.Error
if errs.As(err, &aerr) && aerr.Code() == s3.ErrCodeNoSuchKey {
if errors.AsErr(err, &aerr) && aerr.Code() == s3.ErrCodeNoSuchKey {
return nil, errors.E(op, errors.M(module), errors.V(version), errors.KindNotFound)
}
return nil, errors.E(op, err, errors.M(module), errors.V(version))
@@ -92,7 +91,7 @@ func (s *Storage) open(ctx context.Context, path string) (storage.SizeReadCloser
goo, err := s.s3API.GetObjectWithContext(ctx, getParams)
if err != nil {
var aerr awserr.Error
if errs.As(err, &aerr) && aerr.Code() == s3.ErrCodeNoSuchKey {
if errors.AsErr(err, &aerr) && aerr.Code() == s3.ErrCodeNoSuchKey {
return nil, errors.E(op, errors.KindNotFound)
}
return nil, errors.E(op, err)