hyperledger/fabric · error

chaincode name in interest cannot be empty

Error message

chaincode name in interest cannot be empty

What it means

A chaincode entry inside a discovery ChaincodeInterest has an empty Name field. The discovery service requires every chaincode call it validates to identify the chaincode by name; an unnamed entry cannot be mapped to endorsers, so validation fails.

Solutions

  1. Set the Name field on every ChaincodeCall in the interest to the chaincode instantiated on the channel
  2. Check the config/source of the chaincode name — an empty env var or config key is being read
  3. Filter out ChaincodeCall entries with empty Name before building the query

Example fix

// before
call := &discovery.ChaincodeCall{CollectionNames: []string{"col1"}}
// after
call := &discovery.ChaincodeCall{Name: "mycc", CollectionNames: []string{"col1"}}
Defensive patterns

Strategy: validation

Validate before calling

for _, interest := range ccQuery.Interests {
    for _, cc := range interest.Chaincodes {
        if cc.Name == "" {
            return errors.New("chaincode name required")
        }
    }
}

Type guard

func validChaincodeCall(cc *discovery.ChaincodeCall) bool {
    return cc != nil && cc.Name != ""
}

Try / catch

res, err := client.Send(ctx, req)
if err != nil {
    if strings.Contains(err.Error(), "name in interest cannot be empty") {
        // inspect request chaincode names before resending
    }
    return err
}

Prevention

When it happens

Trigger: Constructing discovery.ChaincodeCall without setting Name (e.g. only setting CollectionNames or NoPrivateReads), or populating names from an empty config/env variable.

Common situations: Private-data collection queries where the developer set CollectionNames but left Name blank; templated request builders where the chaincode name placeholder was never substituted; typos in YAML/JSON config keys for the chaincode name.

Understand the failure class

Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.

Related errors


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

Appendix: source

Thrown at discovery/service.go:275

		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)