hyperledger/fabric · error

Specifying parameter 'sequence' is invalid without parameter

Error message

Specifying parameter 'sequence' is invalid without parameter 'name'. Rerun the command with -n flag

What it means

ApprovedQuerier.validateInput rejects specifying a sequence number without a chaincode name. Sequence alone is ambiguous because sequence numbers are scoped per chaincode name; the peer's QueryApprovedChaincodeDefinitions request requires a name when filtering by sequence. The message directs the user to add the -n flag.

Source

Thrown at internal/peer/lifecycle/chaincode/queryapproved.go:208

func (a *ApprovedQuerier) printSingleApprovedChaincodeDefinition(acd ApprovedChaincodeDefinition) {
	var packageID string
	if acd.GetSource() != nil {
		switch source := acd.GetSource().Type.(type) {
		case *lb.ChaincodeSource_LocalPackage:
			packageID = source.LocalPackage.PackageId
		case *lb.ChaincodeSource_Unavailable_:
		}
	}
	fmt.Fprintf(a.Writer, "sequence: %d, version: %s, init-required: %t, package-id: %s, endorsement plugin: %s, validation plugin: %s",
		acd.GetSequence(), acd.GetVersion(), acd.GetInitRequired(), packageID, acd.GetEndorsementPlugin(), acd.GetValidationPlugin())
}

func (a *ApprovedQuerier) validateInput() error {
	if a.Input.ChannelID == "" {
		return errors.New("The required parameter 'channelID' is empty. Rerun the command with -C flag")
	}
	if a.Input.Name == "" && a.Input.Sequence != 0 {
		return errors.New("Specifying parameter 'sequence' is invalid without parameter 'name'. Rerun the command with -n flag")
	}

	return nil
}

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

	if a.Input.Name != "" {
		function = "QueryApprovedChaincodeDefinition"
		args = &lb.QueryApprovedChaincodeDefinitionArgs{
			Name:     a.Input.Name,
			Sequence: a.Input.Sequence,
		}
	} else {
		function = "QueryApprovedChaincodeDefinitions"
		args = &lb.QueryApprovedChaincodeDefinitionsArgs{}

View on GitHub (pinned to 2736b63f8f)

Solutions

  1. Add the -n flag: `peer lifecycle chaincode queryapproved -C mychannel -n mycc -s 1`
  2. Or drop the -s flag to list all approved definitions on the channel
  3. In client code, only set Input.Sequence when Input.Name is also set

Example fix

// before
peer lifecycle chaincode queryapproved -C mychannel -s 1
// after
peer lifecycle chaincode queryapproved -C mychannel -n mycc -s 1
Defensive patterns

Strategy: validation

Validate before calling

if name == "" && sequence != 0 {
	return errors.New("Specifying parameter 'sequence' is invalid without parameter 'name'. Rerun the command with -n flag")
}

Try / catch

if err := q.Query(); err != nil {
	if strings.Contains(err.Error(), "'sequence'") {
		fmt.Fprintln(os.Stderr, "Usage: -s requires -n <chaincodeName>")
	}
	return err
}

Prevention

When it happens

Trigger: Running `peer lifecycle chaincode queryapproved -C mychannel -s 1` (sequence set) while Input.Name is empty.

Common situations: Copying a command that also queried committed definitions (where sequence alone is valid) instead of queryapproved, or building Input programmatically and setting Sequence without Name.

Understand the failure class

Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.

Related errors


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