Skip to content

Commit

Permalink
chore: make error of non-existed source OCI layout more readable (#1176)
Browse files Browse the repository at this point in the history
Signed-off-by: Billy Zha <jinzha1@microsoft.com>
Co-authored-by: Sajay Antony <sajaya@microsoft.com>
  • Loading branch information
qweeah and sajayantony authored Nov 10, 2023
1 parent a4b052d commit 787d573
Showing 1 changed file with 13 additions and 1 deletion.
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

0 comments on commit 787d573

Please sign in to comment.