Merge pull request #120313 from dairlair/patch-1
Refactor checkErr func
This commit is contained in:
		@@ -73,10 +73,11 @@ 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 {
 | 
					 | 
				
			||||||
		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.
 | 
						// check if the verbosity level in klog is high enough and print a stack trace.
 | 
				
			||||||
	f := flag.CommandLine.Lookup("v")
 | 
						f := flag.CommandLine.Lookup("v")
 | 
				
			||||||
	if f != nil {
 | 
						if f != nil {
 | 
				
			||||||
@@ -90,11 +91,7 @@ func checkErr(err error, handleErr func(string, int)) {
 | 
				
			|||||||
			}
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if err == nil {
 | 
					 | 
				
			||||||
		return
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	switch {
 | 
						switch {
 | 
				
			||||||
	case err == ErrExit:
 | 
						case err == ErrExit:
 | 
				
			||||||
		handleErr("", DefaultErrorExitCode)
 | 
							handleErr("", DefaultErrorExitCode)
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user