From 0e27588ad0125f1e37f8e8df56ea38970f292cc3 Mon Sep 17 00:00:00 2001 From: Miles Crabill Date: Tue, 4 Jun 2024 13:57:45 -0700 Subject: [PATCH] blob_fs: convert gocloud errors into appropriate fs errors - wraps gocloud NotFound and PermissionDenied errors around their `io/fs` counterparts - does not perform wrapping for other gocloud errors as they can either not occur or are ambiguous in this context --- blob/blob_fs.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/blob/blob_fs.go b/blob/blob_fs.go index 7cd6216f35..3b75a8e31f 100644 --- a/blob/blob_fs.go +++ b/blob/blob_fs.go @@ -16,11 +16,13 @@ package blob import ( "context" + "fmt" "io" "io/fs" "path/filepath" "time" + "gocloud.dev/gcerrors" "gocloud.dev/internal/gcerr" ) @@ -203,6 +205,13 @@ func (b *Bucket) Open(path string) (fs.File, error) { // It's a file; open it and return a wrapper. r, err := b.NewReader(ctx, path, readerOpts) if err != nil { + code := gcerrors.Code(err) + switch code { + case gcerrors.NotFound: + err = fmt.Errorf("%w: %w", err, fs.ErrNotExist) + case gcerrors.PermissionDenied: + err = fmt.Errorf("%w: %w", err, fs.ErrPermission) + } return nil, &fs.PathError{Op: "open", Path: path, Err: err} } return &iofsOpenFile{r, filepath.Base(path)}, nil