hyperledger/fabric · error

trailing args detected

Error message

trailing args detected

What it means

The 'peer version' command takes no positional arguments. Its cobra RunE checks len(args) != 0 and returns 'trailing args detected' when anything follows the subcommand, preventing users from unknowingly passing ignored arguments.

Source

Thrown at internal/peer/version/version.go:31

	"github.com/hyperledger/fabric/common/metadata"
	"github.com/spf13/cobra"
)

// Program name
const ProgramName = "peer"

// Cmd returns the Cobra Command for Version
func Cmd() *cobra.Command {
	return cobraCommand
}

var cobraCommand = &cobra.Command{
	Use:   "version",
	Short: "Print fabric peer version.",
	Long:  `Print current version of the fabric peer server.`,
	RunE: func(cmd *cobra.Command, args []string) error {
		if len(args) != 0 {
			return fmt.Errorf("trailing args detected")
		}
		// Parsing of the command line is done so silence cmd usage
		cmd.SilenceUsage = true
		fmt.Print(GetInfo())
		return nil
	},
}

// GetInfo returns version information for the peer
func GetInfo() string {
	ccinfo := fmt.Sprintf("  Base Docker Label: %s\n"+
		"  Docker Namespace: %s\n",
		metadata.BaseDockerLabel,
		metadata.DockerNamespace)

	return fmt.Sprintf("%s:\n Version: %s\n Commit SHA: %s\n Go version: %s\n"+
		" OS/Arch: %s\n"+
		" Chaincode:\n%s\n",

View on GitHub (pinned to 2736b63f8f)

Solutions

  1. Run the command bare: peer version (no extra args).
  2. Use the built-in -s/--short or -o/--output flags instead of positional arguments.
  3. Fix scripts that append tokens after 'peer version'.

Example fix

// before
peer version extra-arg
// after
peer version
Defensive patterns

Strategy: validation

Validate before calling

// in scripts invoking version programmatically
args := []string{"version"}
if len(extraArgs) > 0 { return fmt.Errorf("peer version takes no positional args") }
cmd := exec.Command("peer", append(args, extraArgs...)...)

Prevention

When it happens

Trigger: Running 'peer version <anything>' such as 'peer version --short extra', 'peer version 1.0', or pasting extra tokens after 'version'.

Common situations: Confusing 'peer version' with 'peer chaincode version'-style subcommands; shell scripts appending flags meant for other commands; typos leaving stray tokens in the command line.

Related errors


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