Fix kubectl panic when handling invalid error.
Kubernetes-commit: 12d944b860e4872085fa1155590c7fcef58e6bb8
This commit is contained in:
parent
ced7900f20
commit
7c6594395c
|
@ -131,9 +131,13 @@ func checkErr(err error, handleErr func(string, int)) {
|
|||
handleErr("", DefaultErrorExitCode)
|
||||
case kerrors.IsInvalid(err):
|
||||
details := err.(*kerrors.StatusError).Status().Details
|
||||
s := fmt.Sprintf("The %s %q is invalid", details.Kind, details.Name)
|
||||
if len(details.Kind) == 0 && len(details.Name) == 0 {
|
||||
s = "The request is invalid"
|
||||
s := "The request is invalid"
|
||||
if details == nil {
|
||||
handleErr(s, DefaultErrorExitCode)
|
||||
return
|
||||
}
|
||||
if len(details.Kind) != 0 || len(details.Name) != 0 {
|
||||
s = fmt.Sprintf("The %s %q is invalid", details.Kind, details.Name)
|
||||
}
|
||||
if len(details.Causes) > 0 {
|
||||
errs := statusCausesToAggrError(details.Causes)
|
||||
|
|
|
@ -19,6 +19,7 @@ package util
|
|||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"os"
|
||||
"strings"
|
||||
"syscall"
|
||||
|
@ -226,6 +227,16 @@ func TestCheckInvalidErr(t *testing.T) {
|
|||
"The Invalid4 \"invalidation\" is invalid: field4: Invalid value: \"multi4\": details\n",
|
||||
DefaultErrorExitCode,
|
||||
},
|
||||
{
|
||||
&errors.StatusError{metav1.Status{
|
||||
Status: metav1.StatusFailure,
|
||||
Code: http.StatusUnprocessableEntity,
|
||||
Reason: metav1.StatusReasonInvalid,
|
||||
// Details is nil.
|
||||
}},
|
||||
"The request is invalid",
|
||||
DefaultErrorExitCode,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue