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

simplify file not found messages - less is more #5414

Merged
merged 1 commit into from
Nov 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmd/super/root/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ func (c *Command) Run(args []string) error {
}
paths, ast, null, err := c.queryFlags.ParseSourcesAndInputs(c.query, args)
if err != nil {
return fmt.Errorf("super: %w", err)
return err
}
zctx := super.NewContext()
local := storage.NewLocalEngine()
Expand Down
2 changes: 1 addition & 1 deletion cmd/super/ztests/from-file-error.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ inputs:
outputs:
- name: stderr
regexp: |
a.jsup: file:///.*/a.jsup: file does not exist.*
a.jsup: file does not exist.*
2 changes: 1 addition & 1 deletion cmd/super/ztests/from-pool-error.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ script: |
outputs:
- name: stderr
regexp: |
a: file:///.*/a: file does not exist
a: file does not exist
4 changes: 2 additions & 2 deletions cmd/super/ztests/no-files.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
script: |
! super -z -c doesnotexist
! super -z doesnotexist

outputs:
- name: stdout
data: ""
- name: stderr
data: |
super: no data source found
doesnotexist: file does not exist
2 changes: 1 addition & 1 deletion cmd/super/ztests/single-arg-error.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ script: |
outputs:
- name: stderr
data: |
super: parse error at line 1, column 26:
parse error at line 1, column 26:
file sample.jsup | count(
=== ^ ===
2 changes: 1 addition & 1 deletion compiler/parser/ztests/syntax-error.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ inputs:
outputs:
- name: stderr
data: |
super: parse error at line 1, column 12:
parse error at line 1, column 12:
count() by ,x,y
=== ^ ===
2 changes: 1 addition & 1 deletion docs/tutorials/schools.md
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ super -z -c 'Defunct=' *.jsup
```
produces
```mdtest-output
super: parse error at line 1, column 9:
parse error at line 1, column 9:
Defunct=
=== ^ ===
```
Expand Down
3 changes: 2 additions & 1 deletion lake/data/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package data

import (
"context"
"fmt"
"io"

"github.com/brimdata/super/lake/seekindex"
Expand All @@ -22,7 +23,7 @@ func (o *Object) NewReader(ctx context.Context, engine storage.Engine, path *sto
objectPath := o.SequenceURI(path)
reader, err := engine.Get(ctx, objectPath)
if err != nil {
return nil, err
return nil, fmt.Errorf("%s: %w", objectPath, err)
}
var r io.Reader
var readBytes int64
Expand Down
4 changes: 2 additions & 2 deletions lake/ztests/vacuum.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ outputs:
would vacuum 1 object
vacuumed 1 object
- name: stderr
regexp:
file:.*file does not exist
regexp: |
file:///.*file does not exist
25 changes: 12 additions & 13 deletions pkg/storage/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package storage
import (
"bytes"
"context"
"fmt"
"io"
"io/fs"
"os"
Expand Down Expand Up @@ -31,26 +30,26 @@ func NewFileSystem() *FileSystem {

func (f *FileSystem) Get(ctx context.Context, u *URI) (Reader, error) {
r, err := pkgfs.Open(u.Filepath())
return &fileSizer{r, u}, wrapfileError(u, err)
return &fileSizer{r, u}, fileErr(err)
}

func (f *FileSystem) Put(_ context.Context, u *URI) (io.WriteCloser, error) {
path := u.Filepath()
if err := f.checkPath(path); err != nil {
return nil, wrapfileError(u, err)
return nil, fileErr(err)
}
w, err := pkgfs.OpenFile(path, os.O_RDWR|os.O_CREATE|os.O_TRUNC, f.perm)
return w, wrapfileError(u, err)
return w, fileErr(err)
}

func (f *FileSystem) PutIfNotExists(_ context.Context, u *URI, b []byte) error {
path := u.Filepath()
if err := f.checkPath(path); err != nil {
return wrapfileError(u, err)
return fileErr(err)
}
file, err := os.OpenFile(path, os.O_WRONLY|os.O_CREATE|os.O_TRUNC|os.O_EXCL, f.perm)
if err != nil {
return wrapfileError(u, err)
return fileErr(err)
}
_, err = io.Copy(file, bytes.NewReader(b))
if err != nil {
Expand All @@ -62,7 +61,7 @@ func (f *FileSystem) PutIfNotExists(_ context.Context, u *URI, b []byte) error {
}

func (f *FileSystem) Delete(_ context.Context, u *URI) error {
return wrapfileError(u, os.Remove(u.Filepath()))
return fileErr(os.Remove(u.Filepath()))
}

func (f *FileSystem) DeleteByPrefix(_ context.Context, u *URI) error {
Expand All @@ -72,7 +71,7 @@ func (f *FileSystem) DeleteByPrefix(_ context.Context, u *URI) error {
func (f *FileSystem) Size(_ context.Context, u *URI) (int64, error) {
info, err := os.Stat(u.Filepath())
if err != nil {
return 0, wrapfileError(u, err)
return 0, fileErr(err)
}
return info.Size(), nil
}
Expand All @@ -83,15 +82,15 @@ func (f *FileSystem) Exists(_ context.Context, u *URI) (bool, error) {
return false, nil
}
if err != nil {
return false, wrapfileError(u, err)
return false, fileErr(err)
}
return true, nil
}

func (f *FileSystem) List(ctx context.Context, u *URI) ([]Info, error) {
entries, err := os.ReadDir(u.Filepath())
if err != nil {
return nil, wrapfileError(u, err)
return nil, fileErr(err)
}
infos := make([]Info, len(entries))
for i, e := range entries {
Expand Down Expand Up @@ -127,9 +126,9 @@ func (f *FileSystem) checkPath(path string) error {
return nil
}

func wrapfileError(uri *URI, err error) error {
func fileErr(err error) error {
if os.IsNotExist(err) {
return fmt.Errorf("%s: %w", uri, fs.ErrNotExist)
return fs.ErrNotExist
}
return err
}
Expand All @@ -144,7 +143,7 @@ var _ Sizer = (*fileSizer)(nil)
func (f *fileSizer) Size() (int64, error) {
info, err := os.Stat(f.uri.Filepath())
if err != nil {
return 0, wrapfileError(f.uri, err)
return 0, fileErr(err)
}
return info.Size(), nil
}
14 changes: 7 additions & 7 deletions pkg/storage/s3.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,34 +27,34 @@ func NewS3() *S3Engine {

func (s *S3Engine) Get(ctx context.Context, u *URI) (Reader, error) {
r, err := s3io.NewReader(ctx, u.String(), s.client)
return r, wrapErr(err)
return r, s3Err(err)
}

func (s *S3Engine) Put(ctx context.Context, u *URI) (io.WriteCloser, error) {
w, err := s3io.NewWriter(ctx, u.String(), s.client)
return w, wrapErr(err)
return w, s3Err(err)
}

func (s *S3Engine) PutIfNotExists(context.Context, *URI, []byte) error {
return ErrNotSupported
}

func (s *S3Engine) Delete(ctx context.Context, u *URI) error {
return wrapErr(s3io.Remove(ctx, u.String(), s.client))
return s3Err(s3io.Remove(ctx, u.String(), s.client))
}

func (s *S3Engine) DeleteByPrefix(ctx context.Context, u *URI) error {
return wrapErr(s3io.RemoveAll(ctx, u.String(), s.client))
return s3Err(s3io.RemoveAll(ctx, u.String(), s.client))
}

func (s *S3Engine) Size(ctx context.Context, u *URI) (int64, error) {
info, err := s3io.Stat(ctx, u.String(), s.client)
return info.Size, wrapErr(err)
return info.Size, s3Err(err)
}

func (s *S3Engine) Exists(ctx context.Context, u *URI) (bool, error) {
ok, err := s3io.Exists(ctx, u.String(), s.client)
return ok, wrapErr(err)
return ok, s3Err(err)
}

func (s *S3Engine) List(ctx context.Context, uri *URI) ([]Info, error) {
Expand All @@ -72,7 +72,7 @@ func (s *S3Engine) List(ctx context.Context, uri *URI) ([]Info, error) {
return infos, nil
}

func wrapErr(err error) error {
func s3Err(err error) error {
var reqerr awserr.RequestFailure
if errors.As(err, &reqerr) && reqerr.StatusCode() == http.StatusNotFound {
return fs.ErrNotExist
Expand Down