This is just returning the error upwards, as far as I can tell.
This is the pattern I usually see in actual Go codebases:
infp, err := os.Open(infile)
if err != nil {
return err
}
defer infp.Close()
outfp, err := os.Create(outfile)
if err != nil {
return err
}
defer outfp.Close()
// ... do some stuff ...
return outfp.Close()
Note that double-close is explicitly OK, this pattern just avoids losing the error.