Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

storage: ErrObjectNotExist isn't returning while using CopierFrom. #10760

Open
nalkhovikleverx opened this issue Aug 23, 2024 · 1 comment
Open
Assignees
Labels
api: storage Issues related to the Cloud Storage API. priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.

Comments

@nalkhovikleverx
Copy link

Client

golang google cloud storage

Environment

Alpine Docker on GKE
go version go1.22.6 linux/amd64

Code and Dependencies

func (c *gcs) CopyObject(ctx context.Context, cmd CopyObjectCommand) (*storage.ObjectAttrs, error) {
	bucket := c.client.Bucket(cmd.Bucket)

	objAttr, err := bucket.Object(cmd.DestinationPath).CopierFrom(bucket.Object(cmd.SourcePath)).Run(ctx)
	if err != nil {
		if errors.Is(err, storage.ErrObjectNotExist) {
			return nil, application.ErrObjectNotExist
		}
	}

Client created like this:

	storageClient, err := storage.NewClient(ctx, option.WithTelemetryDisabled())
	if err != nil {
		return fmt.Errorf("failed to create storage client: %w", err)
	}
	storageClient.SetRetry(
		storage.WithBackoff(gax.Backoff{
			Initial:    cfg.StorageClient.InitialRetryDelay,
			Max:        cfg.StorageClient.MaxRetryDelay,
			Multiplier: cfg.StorageClient.RetryBackoffMultiplier,
		}),
		storage.WithPolicy(storage.RetryAlways),
	)
}
go.mod
module mymodule

go 1.22

require (
	cloud.google.com/go/storage v1.43.0
)

Expected behavior

When I call this function with not existed file I expect that the storage.ErrObjectNotExist returned.

Actual behavior

When I call this function with not existed file, I got the *googleapi.Error instance.

@nalkhovikleverx nalkhovikleverx added the triage me I really want to be triaged. label Aug 23, 2024
@product-auto-label product-auto-label bot added the api: storage Issues related to the Cloud Storage API. label Aug 23, 2024
@tritone tritone added type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. priority: p2 Moderately-important priority. Fix may not be included in next release. and removed triage me I really want to be triaged. labels Sep 30, 2024
@tritone
Copy link
Contributor

tritone commented Sep 30, 2024

I think we should probably fix this, but it's probably easier to process this as a googleapi.Error and check the code as suggested here: https://pkg.go.dev/cloud.google.com/go/storage@main#hdr-Errors

If we update this to use the sentinel we'll still keep the wrapping of the googleapi.Error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: storage Issues related to the Cloud Storage API. priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
Projects
None yet
Development

No branches or pull requests

2 participants