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