hyperledger/fabric · error

trailing args detected

Error message

trailing args detected

What it means

`peer channel fetch` accepts at most two positional arguments (the fetch target and the output file). If more than two are supplied, the command rejects the invocation as having trailing args rather than guessing intent.

Source

Thrown at internal/peer/channel/fetch.go:46

		RunE: func(cmd *cobra.Command, args []string) error {
			return fetch(cmd, args, cf)
		},
	}
	flagList := []string{
		"channelID",
		"bestEffort",
	}
	attachFlags(fetchCmd, flagList)

	return fetchCmd
}

func fetch(cmd *cobra.Command, args []string, cf *ChannelCmdFactory) error {
	if len(args) == 0 {
		return fmt.Errorf("fetch target required, oldest, newest, config, or a number")
	}
	if len(args) > 2 {
		return fmt.Errorf("trailing args detected")
	}
	// Parsing of the command line is done so silence cmd usage
	cmd.SilenceUsage = true

	// default to fetching from orderer
	ordererRequired := OrdererRequired
	peerDeliverRequired := PeerDeliverNotRequired
	if len(strings.Split(common.OrderingEndpoint, ":")) != 2 {
		// if no orderer endpoint supplied, connect to peer's deliver service
		ordererRequired = OrdererNotRequired
		peerDeliverRequired = PeerDeliverRequired
	}
	var err error
	if cf == nil {
		cf, err = InitCmdFactory(EndorserNotRequired, peerDeliverRequired, ordererRequired)
		if err != nil {
			return err
		}

View on GitHub (pinned to 2736b63f8f)

Solutions

  1. Remove the extra positional args; keep only target and output file.
  2. Quote paths containing spaces: peer channel fetch newest "/tmp/my block.block" -c mychannel.
  3. In scripts, use "$@" carefully and validate arg count before invoking.

Example fix

// before
peer channel fetch newest mychannel.block backup.block -c mychannel
// after
peer channel fetch newest mychannel.block -c mychannel
Defensive patterns

Strategy: validation

Validate before calling

if [ $# -gt 2 ]; then echo "error: expected at most target and output file" >&2; exit 1; fi
peer channel fetch "$@"

Prevention

When it happens

Trigger: Running `peer channel fetch` with 3+ positional args, e.g. `peer channel fetch newest config.block extra -c mychannel`.

Common situations: Pasting an extra filename or comment token; unquoted paths with spaces producing multiple args; concatenating two commands' args in a script.

Related errors


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