{"record":{"id":"fbc89d69ca66a7ec","repo":"hyperledger/fabric","slug":"trailing-args-detected","errorCode":null,"errorMessage":"trailing args detected","messagePattern":"trailing args detected","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/peer/channel/fetch.go","lineNumber":46,"sourceCode":"\t\tRunE: func(cmd *cobra.Command, args []string) error {\n\t\t\treturn fetch(cmd, args, cf)\n\t\t},\n\t}\n\tflagList := []string{\n\t\t\"channelID\",\n\t\t\"bestEffort\",\n\t}\n\tattachFlags(fetchCmd, flagList)\n\n\treturn fetchCmd\n}\n\nfunc fetch(cmd *cobra.Command, args []string, cf *ChannelCmdFactory) error {\n\tif len(args) == 0 {\n\t\treturn fmt.Errorf(\"fetch target required, oldest, newest, config, or a number\")\n\t}\n\tif len(args) > 2 {\n\t\treturn fmt.Errorf(\"trailing args detected\")\n\t}\n\t// Parsing of the command line is done so silence cmd usage\n\tcmd.SilenceUsage = true\n\n\t// default to fetching from orderer\n\tordererRequired := OrdererRequired\n\tpeerDeliverRequired := PeerDeliverNotRequired\n\tif len(strings.Split(common.OrderingEndpoint, \":\")) != 2 {\n\t\t// if no orderer endpoint supplied, connect to peer's deliver service\n\t\tordererRequired = OrdererNotRequired\n\t\tpeerDeliverRequired = PeerDeliverRequired\n\t}\n\tvar err error\n\tif cf == nil {\n\t\tcf, err = InitCmdFactory(EndorserNotRequired, peerDeliverRequired, ordererRequired)\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}","sourceCodeStart":28,"sourceCodeEnd":64,"githubUrl":"https://github.com/hyperledger/fabric/blob/2736b63f8fd5932511d56fe68b7039d15977f7f6/internal/peer/channel/fetch.go#L28-L64","documentation":"`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.","triggerScenarios":"Running `peer channel fetch` with 3+ positional args, e.g. `peer channel fetch newest config.block extra -c mychannel`.","commonSituations":"Pasting an extra filename or comment token; unquoted paths with spaces producing multiple args; concatenating two commands' args in a script.","solutions":["Remove the extra positional args; keep only target and output file.","Quote paths containing spaces: peer channel fetch newest \"/tmp/my block.block\" -c mychannel.","In scripts, use \"$@\" carefully and validate arg count before invoking."],"exampleFix":"// before\npeer channel fetch newest mychannel.block backup.block -c mychannel\n// after\npeer channel fetch newest mychannel.block -c mychannel","handlingStrategy":"validation","validationCode":"if [ $# -gt 2 ]; then echo \"error: expected at most target and output file\" >&2; exit 1; fi\npeer channel fetch \"$@\"","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Quote file paths with spaces.","Limit positional args to target + output file.","Check script arg counts before invoking."],"tags":["cli","fabric","channel","argument-count"],"backgroundTag":"invalid-argument-count","analyzedSha":"2736b63f8fd5932511d56fe68b7039d15977f7f6","analyzedAt":"2026-09-04T08:52:36.465Z","contentChangedAt":"2026-09-04T08:52:36.465Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}