func CheckErr(err error) {
	if err != nil {
		if debugErr, ok := err.(debugError); ok {
			glog.V(4).Infof(debugErr.DebugError())
		}
		_, isStatus := err.(client.APIStatus)
		switch {
		case clientcmd.IsConfigurationInvalid(err):
			fatal(MultilineError("Error in configuration: ", err))
		case isStatus:
			fatal(fmt.Sprintf("Error from server: %s", err.Error()))
		case errors.IsUnexpectedObjectError(err):
			fatal(fmt.Sprintf("Server returned an unexpected response: %s", err.Error()))
		}
		switch t := err.(type) {
		case *url.Error:
			glog.V(4).Infof("Connection error: %s %s: %v", t.Op, t.URL, t.Err)
			switch {
			case strings.Contains(t.Err.Error(), "connection refused"):
				host := t.URL
				if server, err := url.Parse(t.URL); err == nil {
					host = server.Host
				}
				fatal(fmt.Sprintf("The connection to the server %s was refused - did you specify the right host or port?", host))
			}
			fatal(fmt.Sprintf("Unable to connect to the server: %v", t.Err))
		}
		fatal(fmt.Sprintf("Error: %s", err.Error()))
	}
}
Exemple #2
0
// StandardErrorMessage translates common errors into a human readable message, or returns
// false if the error is not one of the recognized types. It may also log extended
// information to glog.
//
// This method is generic to the command in use and may be used by non-Kubectl
// commands.
func StandardErrorMessage(err error) (string, bool) {
	if debugErr, ok := err.(debugError); ok {
		glog.V(4).Infof(debugErr.DebugError())
	}
	_, isStatus := err.(client.APIStatus)
	switch {
	case isStatus:
		return fmt.Sprintf("Error from server: %s", err.Error()), true
	case errors.IsUnexpectedObjectError(err):
		return fmt.Sprintf("Server returned an unexpected response: %s", err.Error()), true
	}
	switch t := err.(type) {
	case *url.Error:
		glog.V(4).Infof("Connection error: %s %s: %v", t.Op, t.URL, t.Err)
		switch {
		case strings.Contains(t.Err.Error(), "connection refused"):
			host := t.URL
			if server, err := url.Parse(t.URL); err == nil {
				host = server.Host
			}
			return fmt.Sprintf("The connection to the server %s was refused - did you specify the right host or port?", host), true
		}
		return fmt.Sprintf("Unable to connect to the server: %v", t.Err), true
	}
	return "", false
}
Exemple #3
0
func CheckErr(err error) {
	if err != nil {
		if errors.IsStatusError(err) {
			glog.FatalDepth(1, fmt.Sprintf("Error received from API: %s", err.Error()))
		}
		if errors.IsUnexpectedObjectError(err) {
			glog.FatalDepth(1, fmt.Sprintf("Unexpected object received from server: %s", err.Error()))
		}
		if client.IsUnexpectedStatusError(err) {
			glog.FatalDepth(1, fmt.Sprintf("Unexpected status received from server: %s", err.Error()))
		}
		glog.FatalDepth(1, fmt.Sprintf("Client error processing command: %s", err.Error()))
	}
}