fix(helm): fix error formatting

This fixes a number of issues with error formatting and handling in the
client.

Closes #668
pull/683/head
Matt Butcher 8 years ago
parent 9546b27d23
commit 463c7e25aa

@ -34,7 +34,7 @@ func init() {
func delRelease(cmd *cobra.Command, args []string) error {
if len(args) == 0 {
return errors.New("Command 'delete' requires a release name.")
return errors.New("command 'delete' requires a release name")
}
// TODO: Handle dry run use case.
@ -45,7 +45,7 @@ func delRelease(cmd *cobra.Command, args []string) error {
_, err := helm.UninstallRelease(args[0])
if err != nil {
return err
return prettyError(err)
}
return nil

@ -81,7 +81,7 @@ func getCmd(cmd *cobra.Command, args []string) error {
res, err := helm.GetReleaseContent(args[0])
if err != nil {
return err
return prettyError(err)
}
fmt.Printf("CHART: %s-%s\n", res.Release.Chart.Metadata.Name, res.Release.Chart.Metadata.Version)
@ -101,7 +101,7 @@ func getValues(cmd *cobra.Command, args []string) error {
res, err := helm.GetReleaseContent(args[0])
if err != nil {
return err
return prettyError(err)
}
return getToFile(res.Release.Config)
}
@ -114,7 +114,7 @@ func getManifest(cmd *cobra.Command, args []string) error {
res, err := helm.GetReleaseContent(args[0])
if err != nil {
return err
return prettyError(err)
}
return getToFile(res.Release.Manifest)
}

@ -1,11 +1,13 @@
package main
import (
"errors"
"fmt"
"os"
"strings"
"github.com/spf13/cobra"
"google.golang.org/grpc"
)
var stdout = os.Stdout
@ -48,7 +50,9 @@ func init() {
}
func main() {
RootCommand.Execute()
if err := RootCommand.Execute(); err != nil {
os.Exit(1)
}
}
func checkArgsLength(expectedNum, actualNum int, requiredArgs ...string) error {
@ -61,3 +65,11 @@ func checkArgsLength(expectedNum, actualNum int, requiredArgs ...string) error {
}
return nil
}
// prettyError unwraps or rewrites certain errors to make them more user-friendly.
func prettyError(err error) error {
// This is ridiculous. Why is 'grpc.rpcError' not exported? The least they
// could do is throw an interface on the lib that would let us get back
// the desc. Instead, we have to pass ALL errors through this.
return errors.New(grpc.ErrorDesc(err))
}

@ -42,11 +42,15 @@ var installCmd = &cobra.Command{
}
func runInstall(cmd *cobra.Command, args []string) error {
setupInstallEnv(args)
if err := checkArgsLength(1, len(args), "chart name"); err != nil {
return err
}
installArg = args[0]
setupInstallEnv()
res, err := helm.InstallRelease(installArg, installDryRun)
if err != nil {
return err
return prettyError(err)
}
printRelease(res.GetRelease())
@ -54,9 +58,6 @@ func runInstall(cmd *cobra.Command, args []string) error {
return nil
}
// TODO -- Display formatted description of install release status / info.
// Might be friendly to wrap our proto model with pretty-printers.
//
func printRelease(rel *release.Release) {
if rel == nil {
return
@ -71,16 +72,13 @@ func printRelease(rel *release.Release) {
}
}
func setupInstallEnv(args []string) {
if len(args) > 0 {
installArg = args[0]
} else {
fatalf("This command needs at least one argument, the name of the chart.")
}
// note: TILLER_HOST envvar is only
func setupInstallEnv() {
// note: TILLER_HOST envvar is
// acknowledged iff the host flag
// does not override the default.
//
// bug: except that if the host flag happens to set the host to the same
// value as the defaultHost, the env var will be used instead.
if tillerHost == defaultHost {
host := os.Getenv(hostEnvVar)
if host != "" {
@ -91,11 +89,6 @@ func setupInstallEnv(args []string) {
helm.Config.ServAddr = tillerHost
}
func fatalf(format string, args ...interface{}) {
fmt.Printf("fatal: %s\n", fmt.Sprintf(format, args...))
os.Exit(0)
}
func init() {
installCmd.Flags().StringVar(&tillerHost, "host", defaultHost, "address of tiller server")
installCmd.Flags().BoolVar(&installDryRun, "dry-run", false, "simulate an install")

@ -47,7 +47,7 @@ func listCmd(cmd *cobra.Command, args []string) error {
res, err := helm.ListReleases(listMax, listOffset)
if err != nil {
return err
return prettyError(err)
}
rels := res.Releases

@ -30,7 +30,7 @@ func status(cmd *cobra.Command, args []string) error {
res, err := helm.GetReleaseStatus(args[0])
if err != nil {
return err
return prettyError(err)
}
fmt.Printf("Last Deployed: %s\n", timeconv.String(res.Info.LastDeployed))

Loading…
Cancel
Save