hyperledger/fabric · error

execute failed

Error message

execute failed

What it means

Wraps any error returned by h.Invoker.Invoke during a chaincode-to-chaincode (or user) transaction execution in the peer's handler. It indicates the target chaincode's Invoke failed to execute at all — the wrapped cause carries the real reason (shim error, transaction failure, internal error).

Source

Thrown at core/chaincode/handler.go:1407

		sim, err := lgr.NewTxSimulator(msg.Txid)
		if err != nil {
			return nil, errors.WithStack(err)
		}
		defer sim.Done()

		hqe, err := lgr.NewHistoryQueryExecutor()
		if err != nil {
			return nil, errors.WithStack(err)
		}

		txParams.TXSimulator = sim
		txParams.HistoryQueryExecutor = hqe
	}

	// Execute the chaincode... this CANNOT be an init at least for now
	responseMessage, err := h.Invoker.Invoke(txParams, targetInstance.ChaincodeName, chaincodeSpec.Input)
	if err != nil {
		return nil, errors.Wrap(err, "execute failed")
	}
	if responseMessage == nil {
		return nil, errors.New("marshal failed: proto: Marshal called with nil")
	}

	// payload is marshalled and sent to the calling chaincode's shim which unmarshals and
	// sends it to chaincode
	res, err := proto.Marshal(responseMessage)
	if err != nil {
		return nil, errors.Wrap(err, "marshal failed")
	}

	return &pb.ChaincodeMessage{Type: pb.ChaincodeMessage_RESPONSE, Payload: res, Txid: msg.Txid, ChannelId: msg.ChannelId}, nil
}

func (h *Handler) Execute(txParams *ccprovider.TransactionParams, namespace string, msg *pb.ChaincodeMessage, timeout time.Duration) (*pb.ChaincodeMessage, error) {
	chaincodeLogger.Debugf("Entry")
	defer chaincodeLogger.Debugf("Exit")

View on GitHub (pinned to 2736b63f8f)

Solutions

  1. Inspect the wrapped (inner) error in the chain for the root cause.
  2. Check the target chaincode's logs for the failure during the invocation.
  3. Validate the ChaincodeSpec.Input arguments and chaincode name in the calling code.
  4. Confirm the target chaincode container is running and healthy (peer chaincode list, docker ps / kubectl).

Example fix

// Go caller-side handling
if err != nil {
    if strings.Contains(err.Error(), "execute failed") {
        log.Printf("chaincode invoke failed: %v", errors.Unwrap(err))
    }
}
// fix usually lives in the target chaincode: return a proper error message
return shim.Error("invalid key")
Defensive patterns

Strategy: try-catch

Validate before calling

// validate target chaincode name and args before invoking
if ccName == "" || len(args) == 0 {
    return shim.Error("invalid invoke target")
}

Try / catch

if err != nil {
    return shim.Error(fmt.Sprintf("chaincode invoke failed: %v", errors.Unwrap(err)))
}

Prevention

When it happens

Trigger: h.Invoker.Invoke(txParams, targetInstance.ChaincodeName, chaincodeSpec.Input) returns a non-nil error during ExecuteChaincode / Execute processing of a transaction message.

Common situations: Target chaincode returns an error from its Invoke path; chaincode container crashed mid-invocation; invalid invocation arguments; internal state/ledger errors during simulation.

Related errors


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