Merge pull request #120313 from dairlair/patch-1

Refactor checkErr func
This commit is contained in:
Kubernetes Prow Robot 2023-08-31 22:02:42 -07:00 committed by GitHub
commit 83f2d89dc9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -73,28 +73,25 @@ type preflightError interface {
// checkErr formats a given error as a string and calls the passed handleErr
// func with that string and an exit code.
func checkErr(err error, handleErr func(string, int)) {
if err == nil {
return
}
var msg string
if err != nil {
msg = fmt.Sprintf("%s\nTo see the stack trace of this error execute with --v=5 or higher", err.Error())
// check if the verbosity level in klog is high enough and print a stack trace.
f := flag.CommandLine.Lookup("v")
if f != nil {
// assume that the "v" flag contains a parseable Int32 as per klog's "Level" type alias,
// thus no error from ParseInt is handled here.
if v, e := strconv.ParseInt(f.Value.String(), 10, 32); e == nil {
// https://git.k8s.io/community/contributors/devel/sig-instrumentation/logging.md
// klog.V(5) - Trace level verbosity
if v > 4 {
msg = fmt.Sprintf("%+v", err)
}
msg := fmt.Sprintf("%s\nTo see the stack trace of this error execute with --v=5 or higher", err.Error())
// check if the verbosity level in klog is high enough and print a stack trace.
f := flag.CommandLine.Lookup("v")
if f != nil {
// assume that the "v" flag contains a parseable Int32 as per klog's "Level" type alias,
// thus no error from ParseInt is handled here.
if v, e := strconv.ParseInt(f.Value.String(), 10, 32); e == nil {
// https://git.k8s.io/community/contributors/devel/sig-instrumentation/logging.md
// klog.V(5) - Trace level verbosity
if v > 4 {
msg = fmt.Sprintf("%+v", err)
}
}
}
if err == nil {
return
}
switch {
case err == ErrExit:
handleErr("", DefaultErrorExitCode)