Unverified Commit bf77961c authored by Matthew Fisher's avatar Matthew Fisher Committed by GitHub

Merge pull request #3383 from PureWhiteWu/refactor/error

refactor prettyError, closes #3381
parents fbe04e73 0ddfbaaf
...@@ -17,7 +17,6 @@ limitations under the License. ...@@ -17,7 +17,6 @@ limitations under the License.
package main // import "k8s.io/helm/cmd/helm" package main // import "k8s.io/helm/cmd/helm"
import ( import (
"errors"
"fmt" "fmt"
"io/ioutil" "io/ioutil"
"log" "log"
...@@ -25,8 +24,8 @@ import ( ...@@ -25,8 +24,8 @@ import (
"strings" "strings"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"google.golang.org/grpc"
"google.golang.org/grpc/grpclog" "google.golang.org/grpc/grpclog"
"google.golang.org/grpc/status"
"k8s.io/client-go/kubernetes" "k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest" "k8s.io/client-go/rest"
"k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset" "k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset"
...@@ -209,13 +208,16 @@ func checkArgsLength(argsReceived int, requiredArgs ...string) error { ...@@ -209,13 +208,16 @@ func checkArgsLength(argsReceived int, requiredArgs ...string) error {
// prettyError unwraps or rewrites certain errors to make them more user-friendly. // prettyError unwraps or rewrites certain errors to make them more user-friendly.
func prettyError(err error) error { func prettyError(err error) error {
// Add this check can prevent the object creation if err is nil.
if err == nil { if err == nil {
return nil return nil
} }
// This is ridiculous. Why is 'grpc.rpcError' not exported? The least they // If it's grpc's error, make it more user-friendly.
// could do is throw an interface on the lib that would let us get back if s, ok := status.FromError(err); ok {
// the desc. Instead, we have to pass ALL errors through this. return s.Err()
return errors.New(grpc.ErrorDesc(err)) }
// Else return the original error.
return err
} }
// configForContext creates a Kubernetes REST client configuration for a given kubeconfig context. // configForContext creates a Kubernetes REST client configuration for a given kubeconfig context.
......
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