hyperledger/fabric · error

error in handling register chaincode, chaincodeID name is em

Error message

error in handling register chaincode, chaincodeID name is empty

What it means

HandleRegister in Hyperledger Fabric's chaincode handler registers a chaincode peer-side using the chaincodeID.Name supplied in the ChaincodeMessage REGISTER payload. If the name field is empty there is no handle to track the chaincode by, so the handler notifies the registry of the failure and drops the registration. This indicates a malformed/corrupt registration message from the chaincode side, not a ledger or channel problem.

Source

Thrown at core/chaincode/handler.go:546

func (h *Handler) HandleRegister(msg *pb.ChaincodeMessage) {
	h.stateLock.RLock()
	state := h.state
	h.stateLock.RUnlock()

	chaincodeLogger.Debugf("Received %s in state %s", msg.Type, state)
	chaincodeID := &pb.ChaincodeID{}
	err := proto.Unmarshal(msg.Payload, chaincodeID)
	if err != nil {
		chaincodeLogger.Errorf("Error in received %s, could NOT unmarshal registration info: %s", pb.ChaincodeMessage_REGISTER, err)
		return
	}

	// Now register with the chaincodeSupport
	// Note: chaincodeID.Name is actually of the form name:version for older chaincodes, and
	// of the form label:hash for newer chaincodes.  Either way, it is the handle by which
	// we track the chaincode's registration.
	if chaincodeID.Name == "" {
		h.notifyRegistry(errors.New("error in handling register chaincode, chaincodeID name is empty"))
		return
	}
	h.chaincodeID = chaincodeID.Name
	err = h.Registry.Register(h)
	if err != nil {
		h.notifyRegistry(err)
		return
	}

	chaincodeLogger.Debugf("Got %s for chaincodeID = %s, sending back %s", pb.ChaincodeMessage_REGISTER, h.chaincodeID, pb.ChaincodeMessage_REGISTERED)
	if err = h.serialSend(&pb.ChaincodeMessage{Type: pb.ChaincodeMessage_REGISTERED}); err != nil {
		chaincodeLogger.Errorf("error sending %s: %s", pb.ChaincodeMessage_REGISTERED, err)
		h.notifyRegistry(err)
		return
	}

	h.stateLock.Lock()
	h.state = Established

View on GitHub (pinned to 2736b63f8f)

Solutions

  1. Rebuild and redeploy the chaincode so the shim sends a properly populated ChaincodeID (name:version / label:hash)
  2. Restart the chaincode container (docker restart or reinstall the chaincode) to clear stale state
  3. Verify chaincode shim version compatibility with the peer (lifecycle install path)
  4. Inspect chaincode container logs for shim-side serialization failures before REGISTER

Example fix

// before (custom launcher sends empty id)
msg := &pb.ChaincodeMessage{Type: pb.ChaincodeMessage_REGISTER, Payload: marshal(&pb.ChaincodeID{})}
// after
msg := &pb.ChaincodeMessage{Type: pb.ChaincodeMessage_REGISTER, Payload: marshal(&pb.ChaincodeID{Name: "mycc:1.0"})}
Defensive patterns

Strategy: validation

Validate before calling

if chaincodeID == nil || chaincodeID.Name == "" {
    return fmt.Errorf("cannot register chaincode: ChaincodeID.Name is empty")
}
// proceed to send REGISTER with chaincodeID.Name set (e.g. "mycc:1.0")

Type guard

func validChaincodeID(id *pb.ChaincodeID) bool { return id != nil && strings.TrimSpace(id.Name) != "" }

Prevention

When it happens

Trigger: A chaincode sidecar/container sends a pb.ChaincodeMessage of type REGISTER whose payload's ChaincodeID.Name is an empty string; this can happen with a broken chaincode runtime, a corrupted build, or a custom/legacy chaincode launcher that does not populate the name (which is of the form name:version or label:hash).

Common situations: Damaged chaincode images or stale containers after upgrades; custom external builders/launchers that mis-serialize ChaincodeID; intercepted or modified chaincode-to-peer traffic; chaincode packages built with incompatible shim versions.

Related errors


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