Skip to content

Commit

Permalink
refactor prettyError, closes #3381
Browse files Browse the repository at this point in the history
  • Loading branch information
Pure White committed Jan 24, 2018
1 parent d757d98 commit 0ddfbaa
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions cmd/helm/helm.go
Expand Up @@ -17,16 +17,15 @@ limitations under the License.
package main // import "k8s.io/helm/cmd/helm"

import (
"errors"
"fmt"
"io/ioutil"
"log"
"os"
"strings"

"github.com/spf13/cobra"
"google.golang.org/grpc"
"google.golang.org/grpc/grpclog"
"google.golang.org/grpc/status"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"
"k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset"
Expand Down Expand Up @@ -209,13 +208,16 @@ func checkArgsLength(argsReceived int, requiredArgs ...string) error {

// prettyError unwraps or rewrites certain errors to make them more user-friendly.
func prettyError(err error) error {
// Add this check can prevent the object creation if err is nil.
if err == nil {
return nil
}
// 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))
// If it's grpc's error, make it more user-friendly.
if s, ok := status.FromError(err); ok {
return s.Err()
}
// Else return the original error.
return err
}

// configForContext creates a Kubernetes REST client configuration for a given kubeconfig context.
Expand Down

0 comments on commit 0ddfbaa

Please sign in to comment.