hyperledger/fabric · error
a collection specified chaincode %s but it wasn't specified
Error message
a collection specified chaincode %s but it wasn't specified with a chaincode flag
What it means
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.
Source
Thrown at discovery/cmd/endorsers.go:187
if ec.Collections == nil {
ec.Collections = &emptyCollections
}
res := make(map[string][]string)
for _, cc := range *ec.Chaincodes {
res[cc] = nil
}
for _, cc := range *ec.NoPrivReads {
if !ec.existsInChaincodes(cc) {
return nil, errors.Errorf("chaincode %s is specified as not containing private data reads but should be explicitly defined via a chaincode flag", cc)
}
}
for cc, collections := range *ec.Collections {
if !ec.existsInChaincodes(cc) {
return nil, errors.Errorf("a collection specified chaincode %s but it wasn't specified with a chaincode flag", cc)
}
res[cc] = strings.Split(collections, ",")
}
return res, nil
}
func parseEndorsementDescriptors(descriptors []*discovery.EndorsementDescriptor) []endorsermentDescriptor {
var res []endorsermentDescriptor
for _, desc := range descriptors {
endorsersByGroups := make(map[string][]endorser)
for grp, endorsers := range desc.EndorsersByGroups {
for _, p := range endorsers.Peers {
endorsersByGroups[grp] = append(endorsersByGroups[grp], endorserFromRaw(p))
}
}
res = append(res, endorsermentDescriptor{
Chaincode: desc.Chaincode,View on GitHub (pinned to 2736b63f8f)
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
Example fix
// before discover endorsers --server peer:7051 --collection mycc:coll1 // after discover endorsers --server peer:7051 --chaincode mycc --collection mycc:coll1
Defensive patterns
Strategy: validation
Validate before calling
const chaincodes = flags.chaincode || [];
const collCCs = (flags.collection || []).map(c => c.split(':')[0]);
const missing = collCCs.filter(cc => !chaincodes.includes(cc));
if (missing.length > 0) {
throw new Error(`collections reference chaincodes not in --chaincode: ${missing.join(',')}`);
} Type guard
function allCollectionsBelongToChaincodes(chaincodes, collections) {
return collections.every(c => chaincodes.includes(c.split(':')[0]));
} Try / catch
try {
await discoverEndorsers(args);
} catch (e) {
if (/wasn't specified with a chaincode flag/.test(e.message)) {
const cc = e.message.match(/chaincode (\S+)/)?.[1];
args.chaincode.push(cc); // or abort
}
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- chaincode %s is specified as not containing private data rea
- no server specified
- no server specified
- no channel specified
- no channel specified
AI-assisted analysis of hyperledger/fabric@2736b63f8f (2026-09-04).
Data as JSON: /api/errors/5933b9a73545daeb.
Report an issue: GitHub.