build: modernize with "go fix -errorsastype": use errors.AsType
This commit is contained in:
@@ -576,8 +576,7 @@ func (f *Fs) shouldRetry(ctx context.Context, err error) (bool, error) {
|
||||
if fserrors.ContextError(ctx, &err) {
|
||||
return false, err
|
||||
}
|
||||
var storageErr *azcore.ResponseError
|
||||
if errors.As(err, &storageErr) {
|
||||
if storageErr, ok := errors.AsType[*azcore.ResponseError](err); ok {
|
||||
// General errors from:
|
||||
// https://learn.microsoft.com/en-us/rest/api/storageservices/common-rest-api-error-codes
|
||||
// Blob specific errors from:
|
||||
@@ -2796,8 +2795,7 @@ func (f *Fs) OpenChunkWriter(ctx context.Context, remote string, src fs.ObjectIn
|
||||
// isInvalidBlockOrBlob looks for the InvalidBlockOrBlob error in err
|
||||
// returning true if it is found
|
||||
func isInvalidBlockOrBlob(err error) bool {
|
||||
var storageErr *azcore.ResponseError
|
||||
if errors.As(err, &storageErr) {
|
||||
if storageErr, ok := errors.AsType[*azcore.ResponseError](err); ok {
|
||||
return storageErr.ErrorCode == string(bloberror.InvalidBlobOrBlock)
|
||||
}
|
||||
return false
|
||||
|
||||
@@ -194,8 +194,7 @@ var retryErrorCodes = []int{
|
||||
|
||||
// Return true if the api error has the status given
|
||||
func isAPIErr(err error, status string) bool {
|
||||
var apiErr api.Error
|
||||
if errors.As(err, &apiErr) {
|
||||
if apiErr, ok := errors.AsType[api.Error](err); ok {
|
||||
return apiErr.Status == status
|
||||
}
|
||||
return false
|
||||
|
||||
@@ -54,8 +54,7 @@ func (f *Fs) shouldRetry(ctx context.Context, err error) (bool, error) {
|
||||
if fserrors.ContextError(ctx, &err) {
|
||||
return false, err
|
||||
}
|
||||
var httpErr *sdkerrors.HTTPError
|
||||
if errors.As(err, &httpErr) {
|
||||
if httpErr, ok := errors.AsType[*sdkerrors.HTTPError](err); ok {
|
||||
switch httpErr.StatusCode() {
|
||||
case 401:
|
||||
if !f.authFailed {
|
||||
@@ -1064,8 +1063,7 @@ func (o *Object) Update(ctx context.Context, in io.Reader, src fs.ObjectInfo, op
|
||||
err := o.f.pacer.Call(func() (bool, error) {
|
||||
err := files.DeleteFile(ctx, o.f.cfg, backupUUID)
|
||||
if err != nil {
|
||||
var httpErr *sdkerrors.HTTPError
|
||||
if errors.As(err, &httpErr) {
|
||||
if httpErr, ok := errors.AsType[*sdkerrors.HTTPError](err); ok {
|
||||
// Treat 404 (Not Found) and 204 (No Content) as success
|
||||
switch httpErr.StatusCode() {
|
||||
case 404, 204:
|
||||
@@ -1117,8 +1115,7 @@ func isEmptyFileLimitError(err error) bool {
|
||||
// fileTooLargeError extracts the SDK's FileTooLargeError from a wrapped error
|
||||
// chain, returning it (or nil) so callers can branch on the size limit.
|
||||
func fileTooLargeError(err error) *sdkerrors.FileTooLargeError {
|
||||
var tooLarge *sdkerrors.FileTooLargeError
|
||||
if errors.As(err, &tooLarge) {
|
||||
if tooLarge, ok := errors.AsType[*sdkerrors.FileTooLargeError](err); ok {
|
||||
return tooLarge
|
||||
}
|
||||
return nil
|
||||
|
||||
@@ -1019,8 +1019,7 @@ func (f *Fs) shouldRetry(ctx context.Context, resp *http.Response, err error) (b
|
||||
// intermittently returns an HTML challenge page with a 200
|
||||
// status instead of JSON. This surfaces as a JSON syntax error,
|
||||
// so retry it to let the pacer back off until the block lifts.
|
||||
var syntaxErr *json.SyntaxError
|
||||
if errors.As(err, &syntaxErr) {
|
||||
if _, ok := errors.AsType[*json.SyntaxError](err); ok {
|
||||
return true, err
|
||||
}
|
||||
return fserrors.ShouldRetry(err) || fserrors.ShouldRetryHTTP(resp, retryErrorCodes), err
|
||||
|
||||
@@ -432,8 +432,7 @@ func (f *Fs) shouldRetry(ctx context.Context, resp *http.Response, err error) (b
|
||||
|
||||
// traceback to possible api.Error wrapped in err, and re-authorize if necessary
|
||||
// "unauthenticated" (16): when access_token is invalid, but should be handled by oauthutil
|
||||
var terr *oauth2.RetrieveError
|
||||
if errors.As(err, &terr) {
|
||||
if terr, ok := errors.AsType[*oauth2.RetrieveError](err); ok {
|
||||
apiErr := new(api.Error)
|
||||
if err := json.Unmarshal(terr.Body, apiErr); err == nil {
|
||||
if apiErr.Reason == "invalid_grant" {
|
||||
|
||||
@@ -262,8 +262,7 @@ func shouldRetry(ctx context.Context, err error) (bool, error) {
|
||||
if err == nil {
|
||||
return false, nil
|
||||
}
|
||||
var apiErr *proton.APIError
|
||||
if errors.As(err, &apiErr) {
|
||||
if apiErr, ok := errors.AsType[*proton.APIError](err); ok {
|
||||
// Code 200501 is a generic Drive operation-failure code. Proton also
|
||||
// returns it with an HTTP 422 for permanent validation failures (for
|
||||
// example a content key packet that cannot be verified, or an upload
|
||||
|
||||
+4
-8
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -307,8 +307,7 @@ func (s *server) serviceControlHandler(w http.ResponseWriter, r *http.Request) {
|
||||
var env soap.Envelope
|
||||
r.Body = http.MaxBytesReader(w, r.Body, maxSOAPBodySize)
|
||||
if err := xml.NewDecoder(r.Body).Decode(&env); err != nil {
|
||||
var maxBytesErr *http.MaxBytesError
|
||||
if errors.As(err, &maxBytesErr) {
|
||||
if _, ok := errors.AsType[*http.MaxBytesError](err); ok {
|
||||
http.Error(w, "SOAP request body too large", http.StatusRequestEntityTooLarge)
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user