{"record":{"id":"43613ad749c9c346","repo":"hyperledger/fabric","slug":"error-while-marshelling-snapshot-metadata-to-json","errorCode":null,"errorMessage":"error while marshelling snapshot metadata to JSON","messagePattern":"error while marshelling snapshot metadata to JSON","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/ledger/kvledger/snapshot.go","lineNumber":193,"sourceCode":"\t\treturn err\n\t}\n\n\tstateDBType := l.config.StateDBConfig.StateDatabase\n\tif stateDBType != ledger.CouchDB {\n\t\tstateDBType = simpleKeyValueDB\n\t}\n\tsignableMetadata := &SnapshotSignableMetadata{\n\t\tChannelName:            l.ledgerID,\n\t\tLastBlockNumber:        bcInfo.Height - 1,\n\t\tLastBlockHashInHex:     hex.EncodeToString(bcInfo.CurrentBlockHash),\n\t\tPreviousBlockHashInHex: hex.EncodeToString(bcInfo.PreviousBlockHash),\n\t\tFilesAndHashes:         filesAndHashes,\n\t\tStateDBType:            stateDBType,\n\t}\n\n\tsignableMetadataBytes, err := signableMetadata.ToJSON()\n\tif err != nil {\n\t\treturn errors.Wrap(err, \"error while marshelling snapshot metadata to JSON\")\n\t}\n\tif err := fileutil.CreateAndSyncFile(filepath.Join(dir, SnapshotSignableMetadataFileName), signableMetadataBytes, 0o444); err != nil {\n\t\treturn err\n\t}\n\n\t// generate metadata hash file\n\thash, err := l.hashProvider.GetHash(snapshotHashOpts)\n\tif err != nil {\n\t\treturn err\n\t}\n\tif _, err := hash.Write(signableMetadataBytes); err != nil {\n\t\treturn err\n\t}\n\n\tadditionalMetadata := &snapshotAdditionalMetadata{\n\t\tSnapshotHashInHex:        hex.EncodeToString(hash.Sum(nil)),\n\t\tLastBlockCommitHashInHex: hex.EncodeToString(l.commitHash),\n\t}","sourceCodeStart":175,"sourceCodeEnd":211,"githubUrl":"https://github.com/hyperledger/fabric/blob/2736b63f8fd5932511d56fe68b7039d15977f7f6/core/ledger/kvledger/snapshot.go#L175-L211","documentation":"generateSnapshotMetadataFiles serializes the snapshot's signable metadata (channel name, files and hashes, stateDB type) to JSON via SnapshotSignableMetadata.ToJSON before writing the metadata file. This error wraps a marshalling failure, which is practically only caused by an unsupported field type in the metadata struct.","triggerScenarios":"Called from generateSnapshot during GenerateSnapshot() when SignableMetadata.ToJSON() fails — e.g. non-serializable content slipped into the metadata struct (rare; typically indicates an internal bug or a customization that added unmarshalable fields).","commonSituations":"Custom/patched Fabric builds adding non-JSON-serializable fields to snapshot metadata; Go json package constraints (channels, funcs, cyclic data) if metadata struct was modified.","solutions":["If running stock Fabric, capture peer logs and file a bug — this should never fail on unmodified code","If you patched snapshot metadata structs, ensure all added fields are JSON-serializable (no channels, funcs, cycles)","Verify no unsupported stateDB type or metadata field is being injected via custom builds"],"exampleFix":"// before (custom field not serializable)\ntype SnapshotSignableMetadata struct {\n    StateDBType string `json:\"stateDBType\"`\n    Extra func `json:\"extra\"` // unmarshalable\n}\n// after\ntype SnapshotSignableMetadata struct {\n    StateDBType string `json:\"stateDBType\"`\n    Extra string `json:\"extra\"`","handlingStrategy":"try-catch","validationCode":"b, err := json.Marshal(signableMetadata)\nif err != nil { return fmt.Errorf(\"snapshot metadata not serializable: %w\", err) }","typeGuard":null,"tryCatchPattern":"err := ledger.GenerateSnapshot()\nif err != nil {\n    if strings.Contains(err.Error(), \"marshelling snapshot metadata\") {\n        log.Error(\"snapshot metadata marshalling failed; verify stock Fabric build / struct customizations\")\n    }\n    return err\n}","preventionTips":["Run unmodified, supported Fabric releases for snapshotting","Keep all snapshot metadata fields JSON-serializable in custom builds","Test GenerateSnapshot() in CI after any ledger-related patches"],"tags":["json","marshal","snapshot","serialization"],"backgroundTag":"json-marshal-failed","analyzedSha":"2736b63f8fd5932511d56fe68b7039d15977f7f6","analyzedAt":"2026-09-04T08:52:36.465Z","contentChangedAt":"2026-09-04T08:52:36.465Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}