hyperledger/fabric · error

failed to marshal chaincode package metadata into JSON

Error message

failed to marshal chaincode package metadata into JSON

What it means

Wrapping error in toJSON: json.Marshal failed on the PackageMetadata struct (path/type/label) while assembling a chaincode package. This is highly unusual since the struct is plain strings; it indicates an environment/JSON package anomaly rather than user input, and the failure aborts packaging of the .tar.gz metadata file.

Solutions

  1. Inspect the wrapped error for the specific marshal failure
  2. Verify the path/type/label strings contain valid UTF-8 (invalid bytes can fail JSON encoding)
  3. Retry the package lifecycle chaincode package command; if persistent, report as an environment bug
Defensive patterns

Strategy: fallback

When it happens

Trigger: Thrown at internal/peer/lifecycle/chaincode/package.go:231 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of hyperledger/fabric@2736b63f8f (2026-09-04). Data as JSON: /api/errors/83b2b47e1b3fab2d. Report an issue: GitHub.

Appendix: source

Thrown at internal/peer/lifecycle/chaincode/package.go:231

}

// PackageMetadata holds the path and type for a chaincode package
type PackageMetadata struct {
	Path  string `json:"path"`
	Type  string `json:"type"`
	Label string `json:"label"`
}

func toJSON(path, ccType, label string) ([]byte, error) {
	metadata := &PackageMetadata{
		Path:  path,
		Type:  ccType,
		Label: label,
	}

	metadataBytes, err := json.Marshal(metadata)
	if err != nil {
		return nil, errors.Wrap(err, "failed to marshal chaincode package metadata into JSON")
	}

	return metadataBytes, nil
}

View on GitHub (pinned to 2736b63f8f)