From: Daniel Martí Date: Wed, 16 Nov 2016 22:39:25 +0000 (+0000) Subject: cmd/cover: don't ignore os.Create error X-Git-Tag: go1.8beta1~128 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=14e9f4825bffd4339dbde43198ed1710a1e149b5;p=gostls13.git cmd/cover: don't ignore os.Create error Failing to create the output file would give confusing errors such as: cover: invalid argument Also do out.Close() even if Execute() errored. Fixes #17951. Change-Id: I897e1d31f7996871c54fde7cb09614cafbf6c3fc Reviewed-on: https://go-review.googlesource.com/33278 Reviewed-by: Ian Lance Taylor Run-TryBot: Ian Lance Taylor --- diff --git a/src/cmd/cover/html.go b/src/cmd/cover/html.go index b49f934d1b..04dc76fd59 100644 --- a/src/cmd/cover/html.go +++ b/src/cmd/cover/html.go @@ -64,9 +64,12 @@ func htmlOutput(profile, outfile string) error { } else { out, err = os.Create(outfile) } + if err != nil { + return err + } err = htmlTemplate.Execute(out, d) - if err == nil { - err = out.Close() + if err2 := out.Close(); err == nil { + err = err2 } if err != nil { return err