hyperledger/fabric · error

chaincode interest must contain at least one chaincode

Error message

chaincode interest must contain at least one chaincode

What it means

This error comes from the Hyperledger Fabric discovery service's chaincode query validation. A chaincode interest (discovery.ChaincodeInterest) groups chaincode call collections the client wants to endorse; each interest must name at least one chaincode. The service rejects the request before doing any discovery work because an empty interest cannot be resolved to endorsers.

Source

Thrown at discovery/service.go:271

	}
	if !bytes.Equal(computedHash, req.Authentication.ClientTlsCertHash) {
		claimed := hex.EncodeToString(req.Authentication.ClientTlsCertHash)
		logger.Warningf("client claimed TLS hash %s doesn't match computed TLS hash from gRPC stream %s", claimed, hex.EncodeToString(computedHash))
		return nil, errors.New("client claimed TLS hash doesn't match computed TLS hash from gRPC stream")
	}
	return req, nil
}

func validateCCQuery(ccQuery *discovery.ChaincodeQuery) error {
	if len(ccQuery.Interests) == 0 {
		return errors.New("chaincode query must have at least one chaincode interest")
	}
	for _, interest := range ccQuery.Interests {
		if interest == nil {
			return errors.New("chaincode interest is nil")
		}
		if len(interest.Chaincodes) == 0 {
			return errors.New("chaincode interest must contain at least one chaincode")
		}
		for _, cc := range interest.Chaincodes {
			if cc.Name == "" {
				return errors.New("chaincode name in interest cannot be empty")
			}
		}
	}
	return nil
}

func wrapError(err error) *discovery.QueryResult {
	return &discovery.QueryResult{
		Result: &discovery.QueryResult_Error{
			Error: &discovery.Error{
				Content: err.Error(),
			},
		},
	}

View on GitHub (pinned to 2736b63f8f)

Solutions

  1. Populate at least one entry in interest.Chaincodes with a valid chaincode Name before sending the query
  2. If the interest is optional for your flow, omit it from Interests instead of appending an empty one
  3. Validate client-side: iterate Interests and skip or error on entries with len(Chaincodes)==0 before invoking discovery

Example fix

// before
interest := &discovery.ChaincodeInterest{}
query := discovery.ChaincodeQuery{Interests: []*discovery.ChaincodeInterest{interest}}
// after
interest := &discovery.ChaincodeInterest{Chaincodes: []*discovery.ChaincodeCall{{Name: "mycc"}}}
query := discovery.ChaincodeQuery{Interests: []*discovery.ChaincodeInterest{interest}}
Defensive patterns

Strategy: validation

Validate before calling

for _, interest := range ccQuery.Interests {
    if interest == nil || len(interest.Chaincodes) == 0 {
        return errors.New("each chaincode interest must contain at least one chaincode")
    }
}

Type guard

func validInterest(i *discovery.ChaincodeInterest) bool {
    return i != nil && len(i.Chaincodes) > 0
}

Try / catch

res, err := client.Send(ctx, req)
if err != nil {
    if strings.Contains(err.Error(), "must contain at least one chaincode") {
        // rebuild interests with valid chaincode calls
    }
    return err
}

Prevention

When it happens

Trigger: Calling the discovery service with a chaincode query whose Interests slice contains an entry created with no Chaincodes appended, e.g. discovery.ChaincodeInterest{} passed through discovery.NewQuery.Chaincode(...) or a raw ChaincodeQueryRequest built by hand.

Common situations: Building ChaincodeInterest programmatically and forgetting to append a ChaincodeCall; conditionally populating chaincode names from user input/config that ended up empty; serializing an interest struct before filling it.

Related errors


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