Skip to content

Commit

Permalink
blob_fs: convert gocloud errors into appropriate fs errors
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
milescrabill committed Jun 4, 2024
1 parent ba58ec7 commit 0e27588
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions blob/blob_fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@ package blob

import (
"context"
"fmt"
"io"
"io/fs"
"path/filepath"
"time"

"gocloud.dev/gcerrors"
"gocloud.dev/internal/gcerr"
)

Expand Down Expand Up @@ -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)

Check warning on line 213 in blob/blob_fs.go

View check run for this annotation

Codecov / codecov/patch

blob/blob_fs.go#L208-L213

Added lines #L208 - L213 were not covered by tests
}
return nil, &fs.PathError{Op: "open", Path: path, Err: err}
}
return &iofsOpenFile{r, filepath.Base(path)}, nil
Expand Down

0 comments on commit 0e27588

Please sign in to comment.