Skip to content

Commit b739f25

Browse files
committed
Add debug log on error closing temp coverprofile
1 parent 2ee9577 commit b739f25

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
@@ -1846,18 +1846,24 @@ func (c *runCache) saveOutput(a *work.Action, coverprofileFile string) {
18461846
if err != nil {
18471847
return
18481848
}
1849-
saveCoverProfile := func(testID cache.ActionID) {
1850-
if coverprofileFile == "" {
1851-
return
1849+
var coverprof *os.File
1850+
if coverprofileFile != "" {
1851+
coverprof, err = os.Open(coverprofileFile)
1852+
if err != nil && cache.DebugTest {
1853+
fmt.Fprintf(os.Stderr, "testcache: %s: failed to open temporary coverprofile: %s", a.Package.ImportPath, err)
18521854
}
1853-
coverprof, err := os.Open(coverprofileFile)
1854-
if err != nil {
1855-
if cache.DebugTest {
1856-
fmt.Fprintf(os.Stderr, "testcache: %s: failed to open temporary coverprofile file: %s", a.Package.ImportPath, err)
1855+
}
1856+
if coverprof != nil {
1857+
defer func() {
1858+
if err := coverprof.Close(); err != nil && cache.DebugTest {
1859+
fmt.Fprintf(os.Stderr, "testcache: %s: closing temporary coverprofile: %v", a.Package.ImportPath, err)
18571860
}
1861+
}()
1862+
}
1863+
saveCoverProfile := func(testID cache.ActionID) {
1864+
if coverprof == nil {
18581865
return
18591866
}
1860-
defer coverprof.Close()
18611867
cache.Default().Put(testCoverProfileKey(testID, testInputsID), coverprof)
18621868
}
18631869
if c.id1 != (cache.ActionID{}) {

0 commit comments

Comments
 (0)