hyperledger/fabric · error

failed creating request

Error message

failed creating request

What it means

While building the endorsers query, the library calls discoveryclient.NewRequest().OfChannel(...).AddEndorsersQuery(...). AddEndorsersQuery returns an error (e.g. a chaincode call has no name, or protobuf marshalling of ChaincodeInterest fails), which Execute wraps with "failed creating request" via errors.Wrap. The original cause is preserved in the wrapped error chain.

Source

Thrown at discovery/cmd/endorsers.go:107

	}
	cc2collections, err := ccAndCol.parseInput()
	if err != nil {
		return err
	}

	var ccCalls []*peer.ChaincodeCall

	for _, cc := range *ccAndCol.Chaincodes {
		ccCalls = append(ccCalls, &peer.ChaincodeCall{
			Name:            cc,
			CollectionNames: cc2collections[cc],
			NoPrivateReads:  ccAndCol.noPrivateReads(cc),
		})
	}

	req, err := discoveryclient.NewRequest().OfChannel(channel).AddEndorsersQuery(&peer.ChaincodeInterest{Chaincodes: ccCalls})
	if err != nil {
		return errors.Wrap(err, "failed creating request")
	}

	res, err := pc.stub.Send(server, conf, req)
	if err != nil {
		return err
	}

	return pc.parser.ParseResponse(channel, res)
}

// EndorserResponseParser parses endorsement responses from the peer
type EndorserResponseParser struct {
	io.Writer
}

// ParseResponse parses the given response for the given channel
func (parser *EndorserResponseParser) ParseResponse(channel string, res ServiceResponse) error {
	rawResponse := res.Raw()

View on GitHub (pinned to 2736b63f8f)

Solutions

  1. Inspect err.Unwrap()/cause of the wrapped error to see the underlying reason
  2. Ensure every ChaincodeCall added has a non-empty Name and valid collection names
  3. Validate the chaincode/collection inputs before building the request

Example fix

// before
ccCalls = append(ccCalls, &discovery.ChaincodeCall{Name: ccName}) // ccName may be ""
// after
if ccName == "" {
    return errors.New("chaincode name required")
}
ccCalls = append(ccCalls, &discovery.ChaincodeCall{Name: ccName})
Defensive patterns

Strategy: try-catch

Validate before calling

if ccName == "" || len(collections) == 0 {
    return errors.New("chaincode name and collections must be set before AddEndorsersQuery")
}

Type guard

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

Try / catch

req, err := discoveryclient.NewRequest().OfChannel(channel).AddEndorsersQuery(interest)
if err != nil {
    var cause error
    for errors.Unwrap(err) != nil {
        err = errors.Unwrap(err)
    }
    cause = err
    return fmt.Errorf("request construction failed, cause: %v", cause)
}

Prevention

When it happens

Trigger: Adding an endorsers query with a ChaincodeInterest containing ChaincodeCalls with empty names or invalid data, or proto serialization failure of the interest structure.

Common situations: Chaincode names/collections sourced from empty flags or config; malformed chaincodesAndCollections input (empty cc name, missing collection names); constructing interest lists programmatically with partially filled structs.

Related errors


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