Skip to content

blob/gcsblob: Exists method should return false if the object doesn't exist instead of an error #3528

@BrennaEpp

Description

@BrennaEpp

Describe the bug

The Exists method should return false if the object doesn't exist instead of an error.

To Reproduce

package main

import (
	"context"

	"gocloud.dev/blob"

	_ "gocloud.dev/blob/gcsblob"
)

func main() {
	ctx := context.Background()
	bucket, err := blob.OpenBucket(ctx, "gs://my-bucket")
	if err != nil {
		panic(err)
	}

	exists, err := bucket.Exists(ctx, "valid.tar.gz")
	if err != nil {
		panic(err)
	}
	if !exists {
		panic("the file should have existed")
	}

	exists, err = bucket.Exists(ctx, "invalid.tar.gz")
	if err != nil {
		panic(err)
	}
	if exists {
		panic("the file should not have existed")
	}
}

This sample code is from @appaquet
Refer to googleapis/google-cloud-go#11845

Additional context

We recently changed the error wrapping in the GCS SDK. I believe the fix should be a simple change; I will open a PR.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions