]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/cover: don't ignore os.Create error
authorDaniel Martí <mvdan@mvdan.cc>
Wed, 16 Nov 2016 22:39:25 +0000 (22:39 +0000)
committerIan Lance Taylor <iant@golang.org>
Thu, 17 Nov 2016 00:10:10 +0000 (00:10 +0000)
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 <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>

src/cmd/cover/html.go

index b49f934d1b8cc9fc863b4429675c9bb95fa75ccb..04dc76fd59df9c6dc9c2fcf5a3bb9bc33d9046dd 100644 (file)
@@ -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