{"record":{"id":"669dc2c951f863c9","repo":"golang/go","slug":"marshal-metafilecollection-v","errorCode":null,"errorMessage":"marshal MetaFileCollection: %v","messagePattern":"marshal MetaFileCollection: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/cmd/go/internal/work/cover.go","lineNumber":156,"sourceCode":"\t\t\t// No coverage data for this package.\n\t\t\tcontinue\n\t\t}\n\t\tmetaFilesFile := coverAction.Provider.(*coverProvider).covMetaFileName\n\t\t// Check to make sure the meta-data file fragment exists\n\t\t//  and has content (may be empty if package has no functions).\n\t\tif fi, err := os.Stat(metaFilesFile); err != nil {\n\t\t\tcontinue\n\t\t} else if fi.Size() == 0 {\n\t\t\tcontinue\n\t\t}\n\t\tcollection.ImportPaths = append(collection.ImportPaths, dep.Package.ImportPath)\n\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":138,"sourceCodeEnd":174,"githubUrl":"https://github.com/golang/go/blob/b6b368adc57c96c3151d224d172029f233ead2c3/src/cmd/go/internal/work/cover.go#L138-L174","documentation":"WriteCoverMetaFilesFile serializes a coverage.MetaFileCollection (two []string fields) with json.Marshal. A marshal error here is practically impossible with string slices unless a custom type intercepts — included for defense-in-depth. If it fires, it signals memory corruption or a nil-pointer in the struct fields producing a MarshalerError.","triggerScenarios":"During 'go test -coverpkg' when building the meta-files collection, json.Marshal returns a non-nil error. Realistically only reproducible with a corrupted runtime or a regression in the coverage.MetaFileCollection type.","commonSituations":"A Go toolchain regression; running a patched go command with broken coverage types; extremely rare.","solutions":["Update to the latest Go release.","Run 'go clean -cache' and retry the coverage run.","If reproducing, file a Go issue with the full 'go test -coverpkg' invocation.","As a workaround, drop -coverpkg and use plain -cover."],"exampleFix":"// before\n$ go test -coverpkg=./... ./...\n// error: marshal MetaFileCollection: json: unsupported type...\n\n// after\n$ go clean -cache\n$ go test -cover ./...   # drop -coverpkg as workaround\n# report bug if it persists on a released toolchain","handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":["Treat marshaling internal errors as toolchain bugs; update Go.","Run 'go clean -cache' and retry before assuming a real bug.","Drop -coverpkg as a workaround to confirm it's coverage-specific."],"tags":["coverage","testing","serialization","internal"],"backgroundTag":null,"analyzedSha":"b6b368adc57c96c3151d224d172029f233ead2c3","analyzedAt":"2026-08-12T00:22:02.250Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}