Skip to content

Commit d1577ae

Browse files
committed
Add debug log on error closing temp coverprofile
1 parent 2704585 commit d1577ae

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

src/cmd/go/internal/test/test.go

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1851,18 +1851,24 @@ func (c *runCache) saveOutput(a *work.Action, coverprofileFile string) {
18511851
if err != nil {
18521852
return
18531853
}
1854-
saveCoverProfile := func(testID cache.ActionID) {
1855-
if coverprofileFile == "" {
1856-
return
1854+
var coverprof *os.File
1855+
if coverprofileFile != "" {
1856+
coverprof, err = os.Open(coverprofileFile)
1857+
if err != nil && cache.DebugTest {
1858+
fmt.Fprintf(os.Stderr, "testcache: %s: failed to open temporary coverprofile: %s", a.Package.ImportPath, err)
18571859
}
1858-
coverprof, err := os.Open(coverprofileFile)
1859-
if err != nil {
1860-
if cache.DebugTest {
1861-
fmt.Fprintf(os.Stderr, "testcache: %s: failed to open temporary coverprofile file: %s", a.Package.ImportPath, err)
1860+
}
1861+
if coverprof != nil {
1862+
defer func() {
1863+
if err := coverprof.Close(); err != nil && cache.DebugTest {
1864+
fmt.Fprintf(os.Stderr, "testcache: %s: closing temporary coverprofile: %v", a.Package.ImportPath, err)
18621865
}
1866+
}()
1867+
}
1868+
saveCoverProfile := func(testID cache.ActionID) {
1869+
if coverprof == nil {
18631870
return
18641871
}
1865-
defer coverprof.Close()
18661872
cache.Default().Put(testCoverProfileKey(testID, testInputsID), coverprof)
18671873
}
18681874
if c.id1 != (cache.ActionID{}) {

0 commit comments

Comments
 (0)