mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-05 10:19:50 +00:00
make CheckErr testable
This commit is contained in:
parent
629237bbb7
commit
b7c485ee9a
@ -53,6 +53,10 @@ type debugError interface {
|
|||||||
// This method is generic to the command in use and may be used by non-Kubectl
|
// This method is generic to the command in use and may be used by non-Kubectl
|
||||||
// commands.
|
// commands.
|
||||||
func CheckErr(err error) {
|
func CheckErr(err error) {
|
||||||
|
checkErr(err, fatal)
|
||||||
|
}
|
||||||
|
|
||||||
|
func checkErr(err error, handleErr func(string)) {
|
||||||
if err == nil {
|
if err == nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -61,22 +65,22 @@ func CheckErr(err error) {
|
|||||||
details := err.(*errors.StatusError).Status().Details
|
details := err.(*errors.StatusError).Status().Details
|
||||||
prefix := fmt.Sprintf("The %s %q is invalid:", details.Kind, details.Name)
|
prefix := fmt.Sprintf("The %s %q is invalid:", details.Kind, details.Name)
|
||||||
errs := statusCausesToAggrError(details.Causes)
|
errs := statusCausesToAggrError(details.Causes)
|
||||||
fatal(MultilineError(prefix, errs))
|
handleErr(MultilineError(prefix, errs))
|
||||||
}
|
}
|
||||||
|
|
||||||
// handle multiline errors
|
// handle multiline errors
|
||||||
if clientcmd.IsConfigurationInvalid(err) {
|
if clientcmd.IsConfigurationInvalid(err) {
|
||||||
fatal(MultilineError("Error in configuration: ", err))
|
handleErr(MultilineError("Error in configuration: ", err))
|
||||||
}
|
}
|
||||||
if agg, ok := err.(utilerrors.Aggregate); ok && len(agg.Errors()) > 0 {
|
if agg, ok := err.(utilerrors.Aggregate); ok && len(agg.Errors()) > 0 {
|
||||||
fatal(MultipleErrors("", agg.Errors()))
|
handleErr(MultipleErrors("", agg.Errors()))
|
||||||
}
|
}
|
||||||
|
|
||||||
msg, ok := StandardErrorMessage(err)
|
msg, ok := StandardErrorMessage(err)
|
||||||
if !ok {
|
if !ok {
|
||||||
msg = fmt.Sprintf("error: %s\n", err.Error())
|
msg = fmt.Sprintf("error: %s\n", err.Error())
|
||||||
}
|
}
|
||||||
fatal(msg)
|
handleErr(msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
func statusCausesToAggrError(scs []api.StatusCause) utilerrors.Aggregate {
|
func statusCausesToAggrError(scs []api.StatusCause) utilerrors.Aggregate {
|
||||||
|
Loading…
Reference in New Issue
Block a user