Ensure that Exec error is also logged to file

This change removes unneeded logging and renames the return error value to rerr
to avoid it being aliased by local error values.

Signed-off-by: Evan Lezar <elezar@nvidia.com>
This commit is contained in:
Evan Lezar 2022-02-22 15:17:10 +02:00
parent 48d5a1cd1a
commit c5c2ffd68f

View File

@ -31,7 +31,7 @@ func main() {
// run is an entry point that allows for idiomatic handling of errors
// when calling from the main function.
func run(argv []string) (err error) {
func run(argv []string) (rerr error) {
cfg, err := getConfig()
if err != nil {
return fmt.Errorf("error loading config: %v", err)
@ -43,8 +43,8 @@ func run(argv []string) (err error) {
}
defer func() {
// We capture and log a returning error before closing the log file.
if err != nil {
logger.Errorf("Error running %v: %v", argv, err)
if rerr != nil {
logger.Errorf("Error running %v: %v", argv, rerr)
}
logger.CloseFile()
}()
@ -54,7 +54,6 @@ func run(argv []string) (err error) {
return fmt.Errorf("error creating runtime: %v", err)
}
logger.Printf("Running %s\n", argv[0])
return r.Exec(argv)
}