golang/go · error

marshal MetaFileCollection: %v

Error message

marshal MetaFileCollection: %v

What it means

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.

Source

Thrown at src/cmd/go/internal/work/cover.go:156

			// No coverage data for this package.
			continue
		}
		metaFilesFile := coverAction.Provider.(*coverProvider).covMetaFileName
		// Check to make sure the meta-data file fragment exists
		//  and has content (may be empty if package has no functions).
		if fi, err := os.Stat(metaFilesFile); err != nil {
			continue
		} else if fi.Size() == 0 {
			continue
		}
		collection.ImportPaths = append(collection.ImportPaths, dep.Package.ImportPath)
		collection.MetaFileFragments = append(collection.MetaFileFragments, metaFilesFile)
	}

	// Serialize it.
	data, err := json.Marshal(collection)
	if err != nil {
		return fmt.Errorf("marshal MetaFileCollection: %v", err)
	}
	data = append(data, '\n') // makes -x output more readable

	// Create the directory for this action's objdir and
	// then write out the serialized collection
	// to a file in the directory.
	if err := sh.Mkdir(a.Objdir); err != nil {
		return err
	}
	mfpath := a.Objdir + coverage.MetaFilesFileName
	if err := sh.writeFile(mfpath, data); err != nil {
		return fmt.Errorf("writing metafiles file: %v", err)
	}

	// We're done.
	return nil
}

View on GitHub (pinned to b6b368adc5)

Solutions

  1. Update to the latest Go release.
  2. Run 'go clean -cache' and retry the coverage run.
  3. If reproducing, file a Go issue with the full 'go test -coverpkg' invocation.
  4. As a workaround, drop -coverpkg and use plain -cover.

Example fix

// before
$ go test -coverpkg=./... ./...
// error: marshal MetaFileCollection: json: unsupported type...

// after
$ go clean -cache
$ go test -cover ./...   # drop -coverpkg as workaround
# report bug if it persists on a released toolchain
Defensive patterns

Strategy: retry

Prevention

When it happens

Trigger: 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.

Common situations: A Go toolchain regression; running a patched go command with broken coverage types; extremely rare.

Related errors


AI-assisted analysis of golang/go@b6b368adc5 (2026-08-12). Data as JSON: /api/errors/669dc2c951f863c9. Report an issue: GitHub.