Skip to content

Commit

Permalink
fix: improve error message for plugin (notaryproject#870)
Browse files Browse the repository at this point in the history
Signed-off-by: Junjie Gao <[email protected]>
Signed-off-by: rgnote <[email protected]>
  • Loading branch information
JeyJeyGao authored and rgnote committed Mar 8, 2024
1 parent 9b79374 commit 17d7e1e
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 6 deletions.
11 changes: 11 additions & 0 deletions cmd/notation/plugin/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"net/url"
"os"
"path/filepath"
"runtime"
"strings"

"github.com/notaryproject/notation-go/dir"
Expand Down Expand Up @@ -330,6 +331,16 @@ func installPluginWithOptions(ctx context.Context, opts plugin.CLIInstallOptions
if errors.As(err, &errPluginDowngrade) {
return fmt.Errorf("%w.\nIt is not recommended to install an older version. To force the installation, use the \"--force\" option", errPluginDowngrade)
}

var errExeFile *plugin.PluginExecutableFileError
if errors.As(err, &errExeFile) {
return fmt.Errorf("%w.\nPlease ensure that the plugin executable file is compatible with %s/%s and has appropriate permissions.", err, runtime.GOOS, runtime.GOARCH)
}

var errMalformedPlugin *plugin.PluginMalformedError
if errors.As(err, &errMalformedPlugin) {
return fmt.Errorf("%w.\nPlease ensure that the plugin executable file is intact and compatible with %s/%s. Contact the plugin publisher for further assistance.", errMalformedPlugin, runtime.GOOS, runtime.GOARCH)
}
return err
}
if existingPluginMetadata != nil {
Expand Down
6 changes: 6 additions & 0 deletions cmd/notation/plugin/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
package plugin

import (
"errors"
"fmt"
"os"
"text/tabwriter"
Expand Down Expand Up @@ -44,6 +45,11 @@ func listPlugins(command *cobra.Command) error {
mgr := plugin.NewCLIManager(dir.PluginFS())
pluginNames, err := mgr.List(command.Context())
if err != nil {
var errPluginDirWalk plugin.PluginDirectoryWalkError
if errors.As(err, &errPluginDirWalk) {
pluginDir, _ := dir.PluginFS().SysPath("")
return fmt.Errorf("%w.\nPlease ensure that the current user has permission to access the plugin directory: %s", errPluginDirWalk, pluginDir)
}
return err
}

Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.21

require (
github.com/notaryproject/notation-core-go v1.0.1
github.com/notaryproject/notation-go v1.0.2-0.20240112021749-b315de42f912
github.com/notaryproject/notation-go v1.0.2-0.20240118131949-690448ee6711
github.com/opencontainers/go-digest v1.0.0
github.com/opencontainers/image-spec v1.1.0-rc5
github.com/oras-project/oras-credentials-go v0.3.1
Expand All @@ -25,7 +25,7 @@ require (
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/veraison/go-cose v1.1.0 // indirect
github.com/x448/float16 v0.8.4 // indirect
golang.org/x/crypto v0.17.0 // indirect
golang.org/x/crypto v0.18.0 // indirect
golang.org/x/mod v0.14.0 // indirect
golang.org/x/sync v0.4.0 // indirect
golang.org/x/sys v0.16.0 // indirect
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
github.com/notaryproject/notation-core-go v1.0.1 h1:01doxjDERbd0vocLQrlJdusKrRLNNn50OJzp0c5I4Cw=
github.com/notaryproject/notation-core-go v1.0.1/go.mod h1:rayl8WlKgS4YxOZgDO0iGGB4Ef515ZFZUFaZDmsPXgE=
github.com/notaryproject/notation-go v1.0.2-0.20240112021749-b315de42f912 h1:7abHy5FOfA4mq47/+0pIg/vjI2xfj9qH6cQ47Vc3arM=
github.com/notaryproject/notation-go v1.0.2-0.20240112021749-b315de42f912/go.mod h1:Sj9N0ZRdwIEHL8ewzMjKFEIcLCJhp0r8h6IoT48Q/8E=
github.com/notaryproject/notation-go v1.0.2-0.20240118131949-690448ee6711 h1:3mUupkKwYtGj1vRvuyI5q9X69BdQ2mdQk281MbfznJI=
github.com/notaryproject/notation-go v1.0.2-0.20240118131949-690448ee6711/go.mod h1:/ddbxt03OnWzfb/jZD6STe/gbuWhFaYLWCkq1BkgUCQ=
github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U=
github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM=
github.com/opencontainers/image-spec v1.1.0-rc5 h1:Ygwkfw9bpDvs+c9E34SdgGOj41dX/cbdlwvlWt0pnFI=
Expand Down Expand Up @@ -51,8 +51,8 @@ github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5t
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/crypto v0.13.0/go.mod h1:y6Z2r+Rw4iayiXXAIxJIDAJ1zMW4yaTpebo8fPOliYc=
golang.org/x/crypto v0.17.0 h1:r8bRNjWL3GshPW3gkd+RpvzWrZAwPS49OmTGZ/uhM4k=
golang.org/x/crypto v0.17.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq4=
golang.org/x/crypto v0.18.0 h1:PGVlW0xEltQnzFZ55hkuX5+KLyrMYhHld1YHO4AKcdc=
golang.org/x/crypto v0.18.0/go.mod h1:R0j02AL6hcrfOiy9T4ZYp/rcWeMxM3L6QYxlOuEG1mg=
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
golang.org/x/mod v0.14.0 h1:dGoOF9QVLYng8IHTm7BAyWqCqSheQ5pYWGhzW00YJr0=
Expand Down

0 comments on commit 17d7e1e

Please sign in to comment.