Commit 0f89b08e authored by Matt Butcher's avatar Matt Butcher

Merge pull request #683 from technosophos/fix/668-client-error-fmt

fix(helm): fix error formatting
parents 9fecf748 463c7e25
...@@ -34,7 +34,7 @@ func init() { ...@@ -34,7 +34,7 @@ func init() {
func delRelease(cmd *cobra.Command, args []string) error { func delRelease(cmd *cobra.Command, args []string) error {
if len(args) == 0 { 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. // TODO: Handle dry run use case.
...@@ -45,7 +45,7 @@ func delRelease(cmd *cobra.Command, args []string) error { ...@@ -45,7 +45,7 @@ func delRelease(cmd *cobra.Command, args []string) error {
_, err := helm.UninstallRelease(args[0]) _, err := helm.UninstallRelease(args[0])
if err != nil { if err != nil {
return err return prettyError(err)
} }
return nil return nil
......
...@@ -81,7 +81,7 @@ func getCmd(cmd *cobra.Command, args []string) error { ...@@ -81,7 +81,7 @@ func getCmd(cmd *cobra.Command, args []string) error {
res, err := helm.GetReleaseContent(args[0]) res, err := helm.GetReleaseContent(args[0])
if err != nil { if err != nil {
return err return prettyError(err)
} }
fmt.Printf("CHART: %s-%s\n", res.Release.Chart.Metadata.Name, res.Release.Chart.Metadata.Version) 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 { ...@@ -101,7 +101,7 @@ func getValues(cmd *cobra.Command, args []string) error {
res, err := helm.GetReleaseContent(args[0]) res, err := helm.GetReleaseContent(args[0])
if err != nil { if err != nil {
return err return prettyError(err)
} }
return getToFile(res.Release.Config) return getToFile(res.Release.Config)
} }
...@@ -114,7 +114,7 @@ func getManifest(cmd *cobra.Command, args []string) error { ...@@ -114,7 +114,7 @@ func getManifest(cmd *cobra.Command, args []string) error {
res, err := helm.GetReleaseContent(args[0]) res, err := helm.GetReleaseContent(args[0])
if err != nil { if err != nil {
return err return prettyError(err)
} }
return getToFile(res.Release.Manifest) return getToFile(res.Release.Manifest)
} }
......
package main package main
import ( import (
"errors"
"fmt" "fmt"
"os" "os"
"strings" "strings"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"google.golang.org/grpc"
) )
var stdout = os.Stdout var stdout = os.Stdout
...@@ -48,7 +50,9 @@ func init() { ...@@ -48,7 +50,9 @@ func init() {
} }
func main() { func main() {
RootCommand.Execute() if err := RootCommand.Execute(); err != nil {
os.Exit(1)
}
} }
func checkArgsLength(expectedNum, actualNum int, requiredArgs ...string) error { func checkArgsLength(expectedNum, actualNum int, requiredArgs ...string) error {
...@@ -61,3 +65,11 @@ func checkArgsLength(expectedNum, actualNum int, requiredArgs ...string) error { ...@@ -61,3 +65,11 @@ func checkArgsLength(expectedNum, actualNum int, requiredArgs ...string) error {
} }
return nil 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{ ...@@ -42,11 +42,15 @@ var installCmd = &cobra.Command{
} }
func runInstall(cmd *cobra.Command, args []string) error { 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) res, err := helm.InstallRelease(installArg, installDryRun)
if err != nil { if err != nil {
return err return prettyError(err)
} }
printRelease(res.GetRelease()) printRelease(res.GetRelease())
...@@ -54,9 +58,6 @@ func runInstall(cmd *cobra.Command, args []string) error { ...@@ -54,9 +58,6 @@ func runInstall(cmd *cobra.Command, args []string) error {
return nil 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) { func printRelease(rel *release.Release) {
if rel == nil { if rel == nil {
return return
...@@ -71,16 +72,13 @@ func printRelease(rel *release.Release) { ...@@ -71,16 +72,13 @@ func printRelease(rel *release.Release) {
} }
} }
func setupInstallEnv(args []string) { func setupInstallEnv() {
if len(args) > 0 { // note: TILLER_HOST envvar is
installArg = args[0]
} else {
fatalf("This command needs at least one argument, the name of the chart.")
}
// note: TILLER_HOST envvar is only
// acknowledged iff the host flag // acknowledged iff the host flag
// does not override the default. // 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 { if tillerHost == defaultHost {
host := os.Getenv(hostEnvVar) host := os.Getenv(hostEnvVar)
if host != "" { if host != "" {
...@@ -91,11 +89,6 @@ func setupInstallEnv(args []string) { ...@@ -91,11 +89,6 @@ func setupInstallEnv(args []string) {
helm.Config.ServAddr = tillerHost helm.Config.ServAddr = tillerHost
} }
func fatalf(format string, args ...interface{}) {
fmt.Printf("fatal: %s\n", fmt.Sprintf(format, args...))
os.Exit(0)
}
func init() { func init() {
installCmd.Flags().StringVar(&tillerHost, "host", defaultHost, "address of tiller server") installCmd.Flags().StringVar(&tillerHost, "host", defaultHost, "address of tiller server")
installCmd.Flags().BoolVar(&installDryRun, "dry-run", false, "simulate an install") installCmd.Flags().BoolVar(&installDryRun, "dry-run", false, "simulate an install")
......
...@@ -47,7 +47,7 @@ func listCmd(cmd *cobra.Command, args []string) error { ...@@ -47,7 +47,7 @@ func listCmd(cmd *cobra.Command, args []string) error {
res, err := helm.ListReleases(listMax, listOffset) res, err := helm.ListReleases(listMax, listOffset)
if err != nil { if err != nil {
return err return prettyError(err)
} }
rels := res.Releases rels := res.Releases
......
...@@ -30,7 +30,7 @@ func status(cmd *cobra.Command, args []string) error { ...@@ -30,7 +30,7 @@ func status(cmd *cobra.Command, args []string) error {
res, err := helm.GetReleaseStatus(args[0]) res, err := helm.GetReleaseStatus(args[0])
if err != nil { if err != nil {
return err return prettyError(err)
} }
fmt.Printf("Last Deployed: %s\n", timeconv.String(res.Info.LastDeployed)) fmt.Printf("Last Deployed: %s\n", timeconv.String(res.Info.LastDeployed))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment