Skip to content

Commit

Permalink
blob/fileblob: convert gocloud errors into appropriate fs errors (#3443)
Browse files Browse the repository at this point in the history
  • Loading branch information
milescrabill committed Jun 13, 2024
1 parent e0142cf commit afdaba3
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)
}
return nil, &fs.PathError{Op: "open", Path: path, Err: err}
}
return &iofsOpenFile{r, filepath.Base(path)}, nil
Expand Down

0 comments on commit afdaba3

Please sign in to comment.