by rco8786 · 11y ago · 0 comments
var err error tail.Stdin, err = git.StdoutPipe() if err != nil { log.Println("ERROR", err) }
tail.Stdout = &out
err = tail.Start() if err != nil { log.Println("ERROR", err) }
err = git.Run() if err != nil { log.Println("ERROR", err) }
err = tail.Wait() if err != nil { log.Println("ERROR", err) }
Specifically, you've:
1. Encountered an error
2. Detected it
3. Printed it
But you've continued execution, and some of those errors are clearly not going to let you continue cleanly.
If you couldn't call git on the command line (i.e. it is not installed), then what are you going to do with the stdout? And if git was somehow replaced with something that only returned a status code and no output, then what are you going to do with no output?
The important point is that errors can be thrown because errors can plausibly exist in a way that affects you. You should handle them, logging is fine as a bare minimum but you probably also want to return and exit out of the func in a way that communicates to the thing that called the func that "Something went wrong, and I don't have the results you're looking for".
log.Println("ERROR", err)
return out.Bytes(), err
Or just: log.Println("ERROR", err)
return []byte, err
But I figured since the error will eventually get returned at the end anyway I moved on and kind of forgot about it. log.Printf("WARNING: something bad happened (nonfatal): %v\n", err)
or: log.Fatalf("FATAL ERROR: %v\n", err)
or maybe: // pass the buck
return err
That's it.