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

chore: make error of non-existed source OCI layout more readable #1176

Merged
merged 7 commits into from
Nov 10, 2023
Merged
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
14 changes: 13 additions & 1 deletion cmd/oras/internal/option/target.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import (
"context"
"errors"
"fmt"
"io"
"io/fs"
"os"
"strings"
"sync"
Expand Down Expand Up @@ -154,12 +156,22 @@ func (opts *Target) NewReadonlyTarget(ctx context.Context, common Common, logger
}
info, err := os.Stat(opts.Path)
if err != nil {
if errors.Is(err, fs.ErrNotExist) {
return nil, fmt.Errorf("invalid argument %q: failed to find path %q: %w", opts.RawReference, opts.Path, err)
}
return nil, err
}
if info.IsDir() {
return oci.NewFromFS(ctx, os.DirFS(opts.Path))
}
return oci.NewFromTar(ctx, opts.Path)
store, err := oci.NewFromTar(ctx, opts.Path)
if err != nil {
if errors.Is(err, io.ErrUnexpectedEOF) {
return nil, fmt.Errorf("%q does not look like a tar archive: %w", opts.Path, err)
}
return nil, err
}
return store, nil
case TargetTypeRemote:
repo, err := opts.NewRepository(opts.RawReference, common, logger)
if err != nil {
Expand Down
Loading