Skip to content

Commit

Permalink
Merge pull request #3040 from cpanato/remove-todo1
Browse files Browse the repository at this point in the history
 ✨ clusterctl: print stack trace if verbosity is >= 5
  • Loading branch information
k8s-ci-robot authored May 11, 2020
2 parents df9fcf9 + e217d2d commit bfa4990
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion cmd/clusterctl/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,16 @@ import (
"strings"

"github.com/MakeNowJust/heredoc"
"github.com/pkg/errors"
"github.com/spf13/cobra"
"sigs.k8s.io/cluster-api/cmd/clusterctl/client/config"
logf "sigs.k8s.io/cluster-api/cmd/clusterctl/log"
)

type stackTracer interface {
StackTrace() errors.StackTrace
}

var (
cfgFile string
verbosity *int
Expand All @@ -45,7 +50,13 @@ var RootCmd = &cobra.Command{

func Execute() {
if err := RootCmd.Execute(); err != nil {
// TODO: print error stack if log v>0
if verbosity != nil && *verbosity >= 5 {
if err, ok := err.(stackTracer); ok {
for _, f := range err.StackTrace() {
fmt.Fprintf(os.Stderr, "%+s:%d\n", f, f)
}
}
}
// TODO: print cmd help if validation error
os.Exit(1)
}
Expand Down

0 comments on commit bfa4990

Please sign in to comment.