hyperledger/fabric · error

trailing args detected: %s

Error message

trailing args detected: %s

What it means

This is a CLI argument-arity error from the `peer channel list` cobra command. The list subcommand accepts no positional arguments; passing any extra arguments causes RunE to fail before the network call is attempted.

Source

Thrown at internal/peer/channel/list.go:34

	"github.com/hyperledger/fabric/core/scc/cscc"
	"github.com/hyperledger/fabric/protoutil"
	"github.com/spf13/cobra"
	"google.golang.org/protobuf/proto"
)

type endorserClient struct {
	cf *ChannelCmdFactory
}

func listCmd(cf *ChannelCmdFactory) *cobra.Command {
	// Set the flags on the channel start command.
	return &cobra.Command{
		Use:   "list",
		Short: "List of channels peer has joined.",
		Long:  "List of channels peer has joined.",
		RunE: func(cmd *cobra.Command, args []string) error {
			if len(args) != 0 {
				return fmt.Errorf("trailing args detected: %s", args)
			}
			// Parsing of the command line is done so silence cmd usage
			cmd.SilenceUsage = true
			return list(cf)
		},
	}
}

func (cc *endorserClient) getChannels() ([]*pb.ChannelInfo, error) {
	var err error

	invocation := &pb.ChaincodeInvocationSpec{
		ChaincodeSpec: &pb.ChaincodeSpec{
			Type:        pb.ChaincodeSpec_Type(pb.ChaincodeSpec_Type_value["GOLANG"]),
			ChaincodeId: &pb.ChaincodeID{Name: "cscc"},
			Input:       &pb.ChaincodeInput{Args: [][]byte{[]byte(cscc.GetChannels)}},
		},
	}

View on GitHub (pinned to 2736b63f8f)

Solutions

  1. Remove all positional arguments; pass the channel with -c/--channelID if needed (list ignores it and lists all)
  2. Use `peer channel list --help` to see the accepted flags
  3. Fix scripts to call the bare `peer channel list` command

Example fix

// before
peer channel list mychannel
// after
peer channel list -c mychannel   # or just: peer channel list
Defensive patterns

Strategy: validation

Validate before calling

// check usage before invoking
// peer channel list takes NO positional args
exec.Command("peer", "channel", "list", "-c", "mychannel") // not: "list", "mychannel"

Try / catch

RunE: func(cmd *cobra.Command, args []string) error {
    if len(args) != 0 {
        return fmt.Errorf("trailing args detected: %s", args)
    }
    ...
}

Prevention

When it happens

Trigger: Running `peer channel list` with any positional argument, e.g. `peer channel list mychannel` or `peer channel list -c mychannel extra` — len(args) != 0 in the cobra RunE handler.

Common situations: Users habitually append the channel name after the subcommand (as with other tools) instead of using the -c/--channelID flag; copy-paste from `peer channel join` examples which do take an argument; shell scripts carrying stale extra tokens.

Related errors


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