build: modernize with "go fix -errorsastype": use errors.AsType

This commit is contained in:
Nick Craig-Wood
2026-08-21 12:23:31 +01:00
parent 77f9c70cf6
commit 33e9251b52
9 changed files with 15 additions and 30 deletions
+4 -8
View File
@@ -1279,8 +1279,7 @@ func (f *Fs) shouldRetry(ctx context.Context, err error) (bool, error) {
}
// https://github.com/aws/aws-sdk-go-v2/blob/main/CHANGELOG.md#error-handling
// If this is an awserr object, try and extract more useful information to determine if we should retry
var awsError smithy.APIError
if errors.As(err, &awsError) {
if awsError, ok := errors.AsType[smithy.APIError](err); ok {
// Simple case, check the original embedded error in case it's generically retryable
if fserrors.ShouldRetry(awsError) {
return true, err
@@ -2507,8 +2506,7 @@ func (f *Fs) list(ctx context.Context, opt listOpt, fn listFn) error {
listBucket.URLEncodeListings(urlEncodeListings)
resp, versionIDs, err = listBucket.List(ctx)
if err != nil && !urlEncodeListings {
var xmlErr *xml.SyntaxError
if errors.As(err, &xmlErr) {
if _, ok := errors.AsType[*xml.SyntaxError](err); ok {
// Retry the listing with URL encoding as there were characters that XML can't encode
urlEncodeListings = true
fs.Debugf(f, "Retrying listing because of characters which can't be XML encoded")
@@ -2945,8 +2943,7 @@ func (f *Fs) makeBucket(ctx context.Context, bucket string) error {
if err == nil {
fs.Infof(f, "Bucket %q created with ACL %q", bucket, f.opt.BucketACL)
}
var awsErr smithy.APIError
if errors.As(err, &awsErr) {
if awsErr, ok := errors.AsType[smithy.APIError](err); ok {
switch awsErr.ErrorCode() {
case "BucketAlreadyOwnedByYou":
err = nil
@@ -4415,8 +4412,7 @@ func (o *Object) Open(ctx context.Context, options ...fs.OpenOption) (in io.Read
resp, err = o.fs.c.GetObject(ctx, &req, s3.WithAPIOptions(APIOptions...))
return o.fs.shouldRetry(ctx, err)
})
var awsError smithy.APIError
if errors.As(err, &awsError) {
if awsError, ok := errors.AsType[smithy.APIError](err); ok {
if awsError.ErrorCode() == "InvalidObjectState" {
return nil, fmt.Errorf("Object in GLACIER, restore first: bucket=%q, key=%q", bucket, bucketPath)
}
+1 -2
View File
@@ -496,10 +496,9 @@ func (f *Fs) InternalTestVersions(t *testing.T) {
return f.shouldRetry(ctx, err)
})
var errString string
var awsError smithy.APIError
if err == nil {
errString = "No Error"
} else if errors.As(err, &awsError) {
} else if awsError, ok := errors.AsType[smithy.APIError](err); ok {
errString = awsError.ErrorCode()
} else {
assert.Fail(t, "Unknown error %T %v", err, err)