hyperledger/fabric · error

failed to marshal dataformatInfo [%#v]

Error message

failed to marshal dataformatInfo [%#v]

What it means

encodeDataformatInfo marshals a dataformatInfo document holding the state database's data format version. If json.Marshal fails, the error is wrapped with 'failed to marshal dataformatInfo [%#v]'. In stock Fabric this cannot realistically fail since the struct holds a single string field.

Source

Thrown at core/ledger/kvledger/txmgmt/statedb/statecouchdb/couchdoc_conv.go:261

		err = errors.Wrap(err, "failed to unmarshal channel metadata")
		logger.Errorf("%+v", err)
		return nil, err
	}
	return metadataDoc, nil
}

type dataformatInfo struct {
	Version string `json:"Version"`
}

func encodeDataformatInfo(dataFormatVersion string) (*couchDoc, error) {
	var err error
	dataformatInfo := &dataformatInfo{
		Version: dataFormatVersion,
	}
	dataformatInfoJSON, err := json.Marshal(dataformatInfo)
	if err != nil {
		err = errors.Wrapf(err, "failed to marshal dataformatInfo [%#v]", dataformatInfo)
		logger.Errorf("%+v", err)
		return nil, err
	}
	return &couchDoc{jsonValue: dataformatInfoJSON, attachments: nil}, nil
}

func decodeDataformatInfo(couchDoc *couchDoc) (string, error) {
	dataformatInfo := &dataformatInfo{}
	if err := json.Unmarshal(couchDoc.jsonValue, dataformatInfo); err != nil {
		err = errors.Wrapf(err, "failed to unmarshal json [%#v] into dataformatInfo", couchDoc.jsonValue)
		logger.Errorf("%+v", err)
		return "", err
	}
	return dataformatInfo.Version, nil
}

func validateValue(value []byte) error {
	isJSON, jsonVal := tryCastingToJSON(value)

View on GitHub (pinned to 2736b63f8f)

Solutions

  1. Check the logged wrapped cause to find the offending field
  2. Ensure dataformatInfo contains only JSON-serializable fields such as the Version string
  3. Rebuild the peer from unmodified Fabric sources and retry
Defensive patterns

Strategy: try-catch

Validate before calling

if _, err := json.Marshal(&dataformatInfo{Version: dataFormatVersion}); err != nil {
    return fmt.Errorf("dataformatInfo not serializable: %w", err)
}

Try / catch

doc, err := encodeDataformatInfo()
if err != nil {
    logger.Errorf("dataformatInfo encode failed: %+v", err)
    return nil, err
}

Prevention

When it happens

Trigger: writeDataFormatVersion calls encodeDataformatInfo and json.Marshal errors while building the dataformatInfo couchDoc for the current dataFormatVersion constant.

Common situations: Custom builds where dataformatInfo acquired non-serializable fields; JSON library or dependency corruption.

Related errors


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