hyperledger/fabric · error

channel name must be specified

Error message

channel name must be specified

What it means

validateInput rejects the query before any network call when the --channelID flag is empty. A committed-definition query is channel-scoped, so a channel name is mandatory. This is a client-side preflight error, thrown by the CLI itself.

Source

Thrown at internal/peer/lifecycle/chaincode/querycommitted.go:213

	orgs := []string{}
	approved := qcdr.GetApprovals()
	for org := range approved {
		orgs = append(orgs, org)
	}
	sort.Strings(orgs)

	approvals := ""
	for _, org := range orgs {
		approvals += fmt.Sprintf("%s: %t, ", org, approved[org])
	}
	approvals = strings.TrimSuffix(approvals, ", ")

	fmt.Fprintf(c.Writer, ", Approvals: [%s]\n", approvals)
}

func (c *CommittedQuerier) validateInput() error {
	if c.Input.ChannelID == "" {
		return errors.New("channel name must be specified")
	}

	return nil
}

func (c *CommittedQuerier) createProposal() (*pb.Proposal, error) {
	var function string
	var args proto.Message

	if c.Input.Name != "" {
		function = "QueryChaincodeDefinition"
		args = &lb.QueryChaincodeDefinitionArgs{
			Name: c.Input.Name,
		}
	} else {
		function = "QueryChaincodeDefinitions"
		args = &lb.QueryChaincodeDefinitionsArgs{}
	}

View on GitHub (pinned to 2736b63f8f)

Solutions

  1. Pass --channelID <channel-name> explicitly
  2. Verify the variable feeding the flag is non-empty in scripts (e.g. ${CHANNEL_ID:?unset})
  3. Check flag spelling; --channelID is case-sensitive
  4. Use --outputFormat json if needed for scripts once the flag is fixed

Example fix

// before
peer lifecycle chaincode querycommitted --name mycc
// error: channel name must be specified
// after
peer lifecycle chaincode querycommitted --channelID mychannel --name mycc
Defensive patterns

Strategy: validation

Validate before calling

channelID := os.Getenv("CHANNEL_ID")
if channelID == "" {
    return fmt.Errorf("--channelID is required: set CHANNEL_ID")
}
args = append(args, "--channelID", channelID)

Prevention

When it happens

Trigger: Running 'peer lifecycle chaincode querycommitted' without --channelID (or with an empty value, e.g. from an unset shell variable).

Common situations: Scripting the CLI with CHANNEL_ID unset/empty; forgetting the flag in CI pipelines; typo'd flag name so it never binds.

Understand the failure class

Background: "--flag is required" and "must specify" CLI errors: how missing-required-flag validation works and how to fix it — this error's family across 20 libraries.

Related errors


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