hyperledger/fabric · error

no chaincode interests given

Error message

no chaincode interests given

What it means

validateInterests is called when building an endorsers query (AddEndorsersQuery). If the caller supplies zero ChaincodeInterest objects, there is nothing for discovery to resolve, so the client rejects the request before sending it to the service.

Source

Thrown at discovery/client/client.go:605

}

func validateStateInfoMessage(message *gprotoext.SignedGossipMessage) error {
	si := message.GetStateInfo()
	if si == nil {
		return errors.New("message isn't a stateInfo message")
	}
	if si.Timestamp == nil {
		return errors.New("timestamp is nil")
	}
	if si.Properties == nil {
		return errors.New("properties is nil")
	}
	return nil
}

func validateInterests(interests ...*peer.ChaincodeInterest) error {
	if len(interests) == 0 {
		return errors.New("no chaincode interests given")
	}
	for _, interest := range interests {
		if interest == nil {
			return errors.New("chaincode interest is nil")
		}
		if err := InvocationChain(interest.Chaincodes).ValidateInvocationChain(); err != nil {
			return err
		}
	}
	return nil
}

// InvocationChain aggregates ChaincodeCalls
type InvocationChain []*peer.ChaincodeCall

// String returns a string representation of this invocation chain
func (ic InvocationChain) String() string {
	s, _ := json.Marshal(ic)

View on GitHub (pinned to 2736b63f8f)

Solutions

  1. Pass at least one ChaincodeInterest built from ChaincodeInterest{Chaincodes: []*peer.ChaincodeCall{...}}
  2. Verify the chaincode name/collection list used to build the interest is non-empty before calling
  3. Guard the call site: if len(interests) == 0, return an application-level error before invoking discovery

Example fix

// before
req := discovery.NewEndorsersQuery() // empty
resp, err := client.Send(ctx, req) // error: no chaincode interests given
// after
interest := discovery.ChaincodeInterest{Chaincodes: []*peer.ChaincodeCall{
    {Name: "mycc", CollectionNames: []string{"col1"}},
}}
req := discovery.NewEndorsersQuery(interest)
resp, err := client.Send(ctx, req)
Defensive patterns

Strategy: validation

Validate before calling

func ensureInterests(interests ...*peer.ChaincodeInterest) error {
    if len(interests) == 0 {
        return errors.New("at least one ChaincodeInterest is required for endorsers query")
    }
    return nil
}

Type guard

func hasInterests(interests []*peer.ChaincodeInterest) bool { return len(interests) > 0 }

Try / catch

if err != nil && strings.Contains(err.Error(), "no chaincode interests given") {
    return fmt.Errorf("client bug: endorsers query built without interests: %w", err)
}

Prevention

When it happens

Trigger: Calling discovery.NewEndorsersQuery() with no arguments, or client.AddEndorsersQuery() (via Query) with an empty interests slice.

Common situations: Programmatically building an invocation chain from user input where the chaincodes list ended up empty; a code path that skips adding interests when no chaincode was selected.

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/ce16c00a98791b04. Report an issue: GitHub.