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

refactor: improve error message on platform mismatch #500

Merged
merged 2 commits into from
Aug 17, 2022
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
15 changes: 10 additions & 5 deletions cmd/oras/manifest/fetch.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@ package manifest
import (
"bytes"
"encoding/json"
"errors"
"fmt"
"os"

"github.com/spf13/cobra"
"oras.land/oras/cmd/oras/internal/errors"
"oras.land/oras-go/v2/errdef"
oerrors "oras.land/oras/cmd/oras/internal/errors"
"oras.land/oras/cmd/oras/internal/option"
"oras.land/oras/internal/cas"
)
Expand Down Expand Up @@ -81,7 +83,7 @@ Example - Fetch manifest with prettified json result:

func fetchManifest(opts fetchOptions) error {
ctx, _ := opts.SetLoggerLevel()
tagetPlatform, err := opts.Parse()
targetPlatform, err := opts.Parse()
if err != nil {
return err
}
Expand All @@ -90,18 +92,21 @@ func fetchManifest(opts fetchOptions) error {
return err
}
if repo.Reference.Reference == "" {
return errors.NewErrInvalidReference(repo.Reference)
return oerrors.NewErrInvalidReference(repo.Reference)
}
repo.ManifestMediaTypes = opts.mediaTypes

// Fetch and output
var content []byte
if opts.fetchDescriptor {
content, err = cas.FetchDescriptor(ctx, repo, opts.targetRef, tagetPlatform)
content, err = cas.FetchDescriptor(ctx, repo, opts.targetRef, targetPlatform)
} else {
content, err = cas.FetchManifest(ctx, repo, opts.targetRef, tagetPlatform)
content, err = cas.FetchManifest(ctx, repo, opts.targetRef, targetPlatform)
}
if err != nil {
if targetPlatform != nil && errors.Is(err, errdef.ErrNotFound) {
return fmt.Errorf("no manifest with platform %s was found", opts.Platform.Platform)
}
return err
}
if opts.pretty {
Expand Down