{"record":{"id":"5933b9a73545daeb","repo":"hyperledger/fabric","slug":"a-collection-specified-chaincode-s-but-it-wasn-t","errorCode":null,"errorMessage":"a collection specified chaincode %s but it wasn't specified with a chaincode flag","messagePattern":"a collection specified chaincode (.+?) but it wasn't specified with a chaincode flag","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"discovery/cmd/endorsers.go","lineNumber":187,"sourceCode":"\tif ec.Collections == nil {\n\t\tec.Collections = &emptyCollections\n\t}\n\n\tres := make(map[string][]string)\n\n\tfor _, cc := range *ec.Chaincodes {\n\t\tres[cc] = nil\n\t}\n\n\tfor _, cc := range *ec.NoPrivReads {\n\t\tif !ec.existsInChaincodes(cc) {\n\t\t\treturn nil, errors.Errorf(\"chaincode %s is specified as not containing private data reads but should be explicitly defined via a chaincode flag\", cc)\n\t\t}\n\t}\n\n\tfor cc, collections := range *ec.Collections {\n\t\tif !ec.existsInChaincodes(cc) {\n\t\t\treturn nil, errors.Errorf(\"a collection specified chaincode %s but it wasn't specified with a chaincode flag\", cc)\n\t\t}\n\t\tres[cc] = strings.Split(collections, \",\")\n\t}\n\n\treturn res, nil\n}\n\nfunc parseEndorsementDescriptors(descriptors []*discovery.EndorsementDescriptor) []endorsermentDescriptor {\n\tvar res []endorsermentDescriptor\n\tfor _, desc := range descriptors {\n\t\tendorsersByGroups := make(map[string][]endorser)\n\t\tfor grp, endorsers := range desc.EndorsersByGroups {\n\t\t\tfor _, p := range endorsers.Peers {\n\t\t\t\tendorsersByGroups[grp] = append(endorsersByGroups[grp], endorserFromRaw(p))\n\t\t\t}\n\t\t}\n\t\tres = append(res, endorsermentDescriptor{\n\t\t\tChaincode:         desc.Chaincode,","sourceCodeStart":169,"sourceCodeEnd":205,"githubUrl":"https://github.com/hyperledger/fabric/blob/2736b63f8fd5932511d56fe68b7039d15977f7f6/discovery/cmd/endorsers.go#L169-L205","documentation":"parseInput validates that every chaincode named in a --collection flag (Collections map) is also present in the chaincode selection. Collections only exist within a chaincode's definition, so referencing a collection for a chaincode that was never selected gives discovery nothing to resolve against and the request is rejected.","triggerScenarios":"Running `discover endorsers --collection CC:coll1` without also passing `--chaincode CC`, or the chaincode name before the colon in --collection not matching any --chaincode flag value.","commonSituations":"Forgetting the --chaincode flag when only interested in a collection; renaming a chaincode and updating --collection but not --chaincode; shell scripts building flags where the collection list references old chaincode names.","solutions":["Pass --chaincode CC for the chaincode that owns the collection","Correct the chaincode name in the --collection flag to match an existing --chaincode value","Remove the --collection flag if the chaincode is not being queried"],"exampleFix":"// before\ndiscover endorsers --server peer:7051 --collection mycc:coll1\n\n// after\ndiscover endorsers --server peer:7051 --chaincode mycc --collection mycc:coll1","handlingStrategy":"validation","validationCode":"const chaincodes = flags.chaincode || [];\nconst collCCs = (flags.collection || []).map(c => c.split(':')[0]);\nconst missing = collCCs.filter(cc => !chaincodes.includes(cc));\nif (missing.length > 0) {\n  throw new Error(`collections reference chaincodes not in --chaincode: ${missing.join(',')}`);\n}","typeGuard":"function allCollectionsBelongToChaincodes(chaincodes, collections) {\n  return collections.every(c => chaincodes.includes(c.split(':')[0]));\n}","tryCatchPattern":"try {\n  await discoverEndorsers(args);\n} catch (e) {\n  if (/wasn't specified with a chaincode flag/.test(e.message)) {\n    const cc = e.message.match(/chaincode (\\S+)/)?.[1];\n    args.chaincode.push(cc); // or abort\n  }\n}","preventionTips":["Always pair --collection with a --chaincode flag for the same chaincode","Derive collection flags from the chaincode definition's collection config","Validate the collection prefix matches a chaincode before running"],"tags":["cli","configuration","discovery","collections"],"backgroundTag":"chaincode-flag-mismatch","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"}