Skip to content

Commit

Permalink
don't include a stack-trace with user errors returned by CLI commands
Browse files Browse the repository at this point in the history
  • Loading branch information
BenTheElder committed Sep 6, 2019
1 parent 444b7fd commit acb4fdd
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 13 deletions.
2 changes: 1 addition & 1 deletion cmd/kind/create/cluster/createcluster.go
Expand Up @@ -65,7 +65,7 @@ func runE(flags *flagpole) error {
return err
}
if known {
return errors.Errorf("a cluster with the name %q already exists", flags.Name)
return fmt.Errorf("a cluster with the name %q already exists", flags.Name)
}

// create a cluster context and create the cluster
Expand Down
2 changes: 1 addition & 1 deletion cmd/kind/delete/cluster/deletecluster.go
Expand Up @@ -55,7 +55,7 @@ func runE(flags *flagpole) error {
return err
}
if !known {
return errors.Errorf("unknown cluster %q", flags.Name)
return fmt.Errorf("unknown cluster %q", flags.Name)
}
// Delete the cluster
fmt.Printf("Deleting cluster %q ...\n", flags.Name)
Expand Down
3 changes: 1 addition & 2 deletions cmd/kind/export/logs/logs.go
Expand Up @@ -20,7 +20,6 @@ package logs
import (
"fmt"

"github.com/pkg/errors"
"github.com/spf13/cobra"

"sigs.k8s.io/kind/pkg/cluster"
Expand Down Expand Up @@ -55,7 +54,7 @@ func runE(flags *flagpole, args []string) error {
return err
}
if !known {
return errors.Errorf("unknown cluster %q", flags.Name)
return fmt.Errorf("unknown cluster %q", flags.Name)
}
// get the optional directory argument, or create a tempdir
var dir string
Expand Down
3 changes: 2 additions & 1 deletion cmd/kind/get/kubeconfig/kubeconfig.go
Expand Up @@ -18,6 +18,7 @@ limitations under the License.
package kubeconfig

import (
"fmt"
"io"
"os"

Expand Down Expand Up @@ -69,7 +70,7 @@ func runE(flags *flagpole) error {
}
nodes, known := n[flags.Name]
if !known {
return errors.Errorf("unknown cluster %q", flags.Name)
return fmt.Errorf("unknown cluster %q", flags.Name)
}
// get the bootstrap node to get the kubeconfig
node, err := clusternodes.BootstrapControlPlaneNode(nodes)
Expand Down
3 changes: 1 addition & 2 deletions cmd/kind/get/nodes/nodes.go
Expand Up @@ -20,7 +20,6 @@ package nodes
import (
"fmt"

"github.com/pkg/errors"
"github.com/spf13/cobra"

"sigs.k8s.io/kind/pkg/cluster"
Expand Down Expand Up @@ -60,7 +59,7 @@ func runE(flags *flagpole) error {
}
nodes, known := n[flags.Name]
if !known {
return errors.Errorf("unknown cluster %q", flags.Name)
return fmt.Errorf("unknown cluster %q", flags.Name)
}
for _, node := range nodes {
fmt.Println(node.String())
Expand Down
7 changes: 4 additions & 3 deletions cmd/kind/load/docker-image/docker-image.go
Expand Up @@ -18,6 +18,7 @@ limitations under the License.
package load

import (
"fmt"
"os"
"path/filepath"

Expand Down Expand Up @@ -74,15 +75,15 @@ func runE(flags *flagpole, args []string) error {
// Check that the image exists locally and gets its ID, if not return error
imageID, err := docker.ImageID(imageName)
if err != nil {
return errors.Errorf("Image: %q not present locally", imageName)
return fmt.Errorf("Image: %q not present locally", imageName)
}
// Check if the cluster name exists
known, err := cluster.IsKnown(flags.Name)
if err != nil {
return err
}
if !known {
return errors.Errorf("unknown cluster %q", flags.Name)
return fmt.Errorf("unknown cluster %q", flags.Name)
}

context := cluster.NewContext(flags.Name)
Expand All @@ -107,7 +108,7 @@ func runE(flags *flagpole, args []string) error {
for _, name := range flags.Nodes {
node, ok := nodesByName[name]
if !ok {
return errors.Errorf("unknown node: %q", name)
return fmt.Errorf("unknown node: %q", name)
}
candidateNodes = append(candidateNodes, node)
}
Expand Down
7 changes: 4 additions & 3 deletions cmd/kind/load/image-archive/image-archive.go
Expand Up @@ -18,6 +18,7 @@ limitations under the License.
package load

import (
"fmt"
"os"

"github.com/pkg/errors"
Expand All @@ -39,7 +40,7 @@ func NewCommand() *cobra.Command {
cmd := &cobra.Command{
Args: func(cmd *cobra.Command, args []string) error {
if len(args) < 1 {
return errors.New("name of image archive is required")
return fmt.Errorf("name of image archive is required")
}
return nil
},
Expand Down Expand Up @@ -77,7 +78,7 @@ func runE(flags *flagpole, args []string) error {
return err
}
if !known {
return errors.Errorf("unknown cluster %q", flags.Name)
return fmt.Errorf("unknown cluster %q", flags.Name)
}

context := cluster.NewContext(flags.Name)
Expand All @@ -102,7 +103,7 @@ func runE(flags *flagpole, args []string) error {
for _, name := range flags.Nodes {
node, ok := nodesByName[name]
if !ok {
return errors.Errorf("unknown node: %s", name)
return fmt.Errorf("unknown node: %s", name)
}
selectedNodes = append(selectedNodes, node)
}
Expand Down

0 comments on commit acb4fdd

Please sign in to comment.