hyperledger/fabric · error
invocation chain should not be empty
Error message
invocation chain should not be empty
What it means
ValidateInvocationChain on the discovery client's InvocationChain type checks structural validity before the chain is used to build endorsement queries. If the slice itself is empty (no chaincode calls were appended), there is nothing to query the discovery service about, so the library rejects it upfront with this error. It is a fail-fast guard against sending a meaningless request to the peer's discovery service.
Source
Thrown at discovery/client/client.go:630
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)
return string(s)
}
// ValidateInvocationChain validates the InvocationChain's structure
func (ic InvocationChain) ValidateInvocationChain() error {
if len(ic) == 0 {
return errors.New("invocation chain should not be empty")
}
for _, cc := range ic {
if cc.Name == "" {
return errors.New("chaincode name should not be empty")
}
}
return nil
}
View on GitHub (pinned to 2736b63f8f)
Solutions
- Append at least one ChaincodeCall to the InvocationChain (e.g. chain = chain.Append(discovery.ChaincodeCall{Name: "mycc"})) before validating
- Check that the slice/flags feeding the chain construction actually contain entries
- Skip the explicit ValidateInvocationChain call only if you construct the chain via the client API which enforces non-empty input
Example fix
// before
var chain discovery.InvocationChain
err := chain.ValidateInvocationChain()
// after
chain := discovery.NewInvocationChain("mycc", discovery.ChaincodeCall{Name: "mycc"})
err := chain.ValidateInvocationChain() Defensive patterns
Strategy: validation
Validate before calling
if len(chain) == 0 {
return errors.New("refusing to query discovery: invocation chain is empty")
}
for _, cc := range chain {
if cc.Name == "" {
return fmt.Errorf("invocation chain entry %q has empty name", cc)
}
} Type guard
func chainIsValid(chain discovery.InvocationChain) bool {
return len(chain) > 0
} Try / catch
if err := chain.ValidateInvocationChain(); err != nil {
log.Printf("invalid invocation chain: %v", err)
return err
} Prevention
- Always build the chain via Append/NewInvocationChain helpers instead of raw literals
- Validate config-sourced chaincode lists before constructing the chain
- Unit-test chain construction for empty-input paths
When it happens
Trigger: Calling InvocationChain.ValidateInvocationChain() on an InvocationChain that was never populated — e.g. `var chain discovery.InvocationChain; chain.ValidateInvocationChain()` or `discovery.InvocationChain{}.ValidateInvocationChain()`.
Common situations: Building endorsement-selection code where chaincode calls are appended conditionally and all branches were skipped; refactoring that dropped the Append call; loading chaincode lists from empty config or CLI flag slices.
Related errors
- chaincode name should not be empty
- config ID illegal, cannot be empty
- config ID illegal, cannot be longer than %d
- name '%s' for config ID is not allowed
- config ID '%s' contains illegal characters
AI-assisted analysis of hyperledger/fabric@2736b63f8f (2026-09-04).
Data as JSON: /api/errors/909ad76cd7019c5b.
Report an issue: GitHub.