{"record":{"id":"2c9445262e13e572","repo":"golang/go","slug":"writing-metafiles-file-v","errorCode":null,"errorMessage":"writing metafiles file: %v","messagePattern":"writing metafiles file: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/cmd/go/internal/work/cover.go","lineNumber":168,"sourceCode":"\t\tcollection.MetaFileFragments = append(collection.MetaFileFragments, metaFilesFile)\n\t}\n\n\t// Serialize it.\n\tdata, err := json.Marshal(collection)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"marshal MetaFileCollection: %v\", err)\n\t}\n\tdata = append(data, '\\n') // makes -x output more readable\n\n\t// Create the directory for this action's objdir and\n\t// then write out the serialized collection\n\t// to a file in the directory.\n\tif err := sh.Mkdir(a.Objdir); err != nil {\n\t\treturn err\n\t}\n\tmfpath := a.Objdir + coverage.MetaFilesFileName\n\tif err := sh.writeFile(mfpath, data); err != nil {\n\t\treturn fmt.Errorf(\"writing metafiles file: %v\", err)\n\t}\n\n\t// We're done.\n\treturn nil\n}\n","sourceCodeStart":150,"sourceCodeEnd":174,"githubUrl":"https://github.com/golang/go/blob/b6b368adc57c96c3151d224d172029f233ead2c3/src/cmd/go/internal/work/cover.go#L150-L174","documentation":"After serializing the coverage meta-files collection, WriteCoverMetaFilesFile creates the action's objdir and writes the JSON to <objdir>/<MetaFilesFileName> via sh.writeFile. If the write fails (disk full, permission denied, missing parent dir, path too long), the error is wrapped and returned.","triggerScenarios":"Running 'go test -coverpkg' where the build objdir lives on a full or read-only filesystem, or where permission to create files is missing. The earlier sh.Mkdir succeeded, so the failure is specifically in the file write step.","commonSituations":"TMPDIR/GOCACHE on a small tmpfs; CI container with read-only mounted volume; SELinux denying writes; concurrent build evicting the objdir mid-write; path length limits on Windows.","solutions":["Check disk space and write permissions on TMPDIR and GOCACHE: 'df -h', 'touch <tmp>/x'.","Move GOCACHE to a larger, writable local directory.","Run 'go clean -cache' to reset a possibly corrupted objdir tree.","On Windows, shorten module paths or enable long-path support."],"exampleFix":"// before\n$ go test -coverpkg=./... ./...\n// error: writing metafiles file: open /tmp/.../b001/metafiles: no space left on device\n\n// after\n$ export GOCACHE=$HOME/.cache/go-build\n$ export TMPDIR=$HOME/tmp\n$ go test -coverpkg=./... ./...","handlingStrategy":"validation","validationCode":"// Pre-flight: confirm TMPDIR/GOCACHE are writable with free space.\nfunc preflightCache() error {\n    for _, d := range []string{os.Getenv(\"GOCACHE\"), os.Getenv(\"TMPDIR\")} {\n        if d == \"\" { continue }\n        var stat syscall.Statfs_t\n        if err := syscall.Statfs(d, &stat); err != nil { return err }\n        if stat.Bavail*uint64(stat.Bsize) < 1<<30 {\n            return fmt.Errorf(\"%s has < 1 GiB free\", d)\n        }\n    }\n    return nil\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Provision GOCACHE with multi-GB free space.","Run coverage builds on local, not network, storage.","Watch SELinux/AppArmor denials in containerized CI."],"tags":["coverage","testing","io","build-cache"],"backgroundTag":null,"analyzedSha":"b6b368adc57c96c3151d224d172029f233ead2c3","analyzedAt":"2026-08-12T00:22:02.250Z","schemaVersion":2},"datasetVersion":"2026-08-12T12:31:55.035Z"}