{"record":{"id":"2dccf7e43699f420","repo":"hyperledger/fabric","slug":"no-metadata-at-index-s","errorCode":null,"errorMessage":"no metadata at index [%s]","messagePattern":"no metadata at index \\[(.+?)\\]","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"protoutil/blockutils.go","lineNumber":131,"sourceCode":"\tif payload.Header == nil {\n\t\treturn \"\", errors.New(\"failed to retrieve channel id - payload header is empty\")\n\t}\n\tchdr, err := UnmarshalChannelHeader(payload.GetHeader().GetChannelHeader())\n\tif err != nil {\n\t\treturn \"\", err\n\t}\n\n\treturn chdr.ChannelId, nil\n}\n\n// GetMetadataFromBlock retrieves metadata at the specified index.\nfunc GetMetadataFromBlock(block *cb.Block, index cb.BlockMetadataIndex) (*cb.Metadata, error) {\n\tif block.Metadata == nil {\n\t\treturn nil, errors.New(\"no metadata in block\")\n\t}\n\n\tif len(block.Metadata.Metadata) <= int(index) {\n\t\treturn nil, errors.Errorf(\"no metadata at index [%s]\", index)\n\t}\n\n\tmd := &cb.Metadata{}\n\terr := proto.Unmarshal(block.Metadata.Metadata[index], md)\n\tif err != nil {\n\t\treturn nil, errors.Wrapf(err, \"error unmarshalling metadata at index [%s]\", index)\n\t}\n\treturn md, nil\n}\n\n// GetMetadataFromBlockOrPanic retrieves metadata at the specified index, or\n// panics on error\nfunc GetMetadataFromBlockOrPanic(block *cb.Block, index cb.BlockMetadataIndex) *cb.Metadata {\n\tmd, err := GetMetadataFromBlock(block, index)\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\treturn md","sourceCodeStart":113,"sourceCodeEnd":149,"githubUrl":"https://github.com/hyperledger/fabric/blob/2736b63f8fd5932511d56fe68b7039d15977f7f6/protoutil/blockutils.go#L113-L149","documentation":"GetMetadataFromBlock returns this error when the block has a Metadata section but its Metadata slice is shorter than the requested index, meaning the requested metadata entry (e.g. SIGNATURES, LAST_CONFIG, ORDERER) was never written into the block. It indicates a structurally incomplete block.","triggerScenarios":"GetMetadataFromBlock(block, index) called with index >= len(block.Metadata.Metadata) — e.g. asking for BlockMetadataIndex_ORDERER on a block that only has SIGNATURES and LAST_CONFIG entries.","commonSituations":"Blocks produced by older versions or other consensus plugins lacking the ORDERER metadata entry; hand-built test blocks; corrupted/partial writes to the block store.","solutions":["Check len(block.Metadata.Metadata) > int(index) before calling, or handle the error per index","Ensure blocks are produced by a Fabric version/consensus type that writes the requested metadata index","Re-fetch the block from a healthy orderer or restore from backup","Update test fixtures to populate all required metadata indices"],"exampleFix":"// before\nmd, err := protoutil.GetMetadataFromBlock(blk, cb.BlockMetadataIndex_ORDERER)\n// after\nif blk.Metadata != nil && len(blk.Metadata.Metadata) <= int(cb.BlockMetadataIndex_ORDERER) {\n    return errors.New(\"block lacks ORDERER metadata\")\n}\nmd, err := protoutil.GetMetadataFromBlock(blk, cb.BlockMetadataIndex_ORDERER)","handlingStrategy":"validation","validationCode":"if blk == nil || blk.Metadata == nil || len(blk.Metadata.Metadata) <= int(cb.BlockMetadataIndex_ORDERER) {\n    return errors.New(\"block missing required metadata index\")\n}\nmd, err := protoutil.GetMetadataFromBlock(blk, cb.BlockMetadataIndex_ORDERER)","typeGuard":"func hasMetadataIndex(b *cb.Block, idx cb.BlockMetadataIndex) bool {\n    return b != nil && b.Metadata != nil && len(b.Metadata.Metadata) > int(idx)\n}","tryCatchPattern":"md, err := protoutil.GetMetadataFromBlock(blk, idx)\nif err != nil {\n    var missing bool\n    if strings.HasPrefix(err.Error(), \"no metadata at index\") { missing = true }\n    if missing {\n        log.Warnf(\"block %d missing metadata index %v\", blk.Header.Number, idx)\n        return errSkipIndex\n    }\n    return err\n}","preventionTips":["Ensure the consensus plugin writes every required BlockMetadataIndex before committing","Keep ordering nodes on Fabric versions that emit the indices you read","Populate all metadata indices in test fixtures","Bounds-check the metadata slice for any index you intend to read"],"tags":["block","metadata","index-out-of-range","protoutil"],"backgroundTag":"missing-block-metadata","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"}