Skip to content

Commit

Permalink
chore: make error of non-existed source OCI layout more readable (ora…
Browse files Browse the repository at this point in the history
…s-project#1176)

Signed-off-by: Billy Zha <[email protected]>
Co-authored-by: Sajay Antony <[email protected]>
Signed-off-by: Feynman Zhou <[email protected]>
  • Loading branch information
2 people authored and FeynmanZhou committed May 11, 2024
1 parent f48e1eb commit 29d3888
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 29d3888

Please sign in to comment.