{"record":{"id":"7007fc73265a7c4e","repo":"hyperledger/fabric","slug":"fetch-target-required-oldest-newest-config-or","errorCode":null,"errorMessage":"fetch target required, oldest, newest, config, or a number","messagePattern":"fetch target required, oldest, newest, config, or a number","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/peer/channel/fetch.go","lineNumber":43,"sourceCode":"\t\tUse:   \"fetch <newest|oldest|config|(number)> [outputfile]\",\n\t\tShort: \"Fetch a block\",\n\t\tLong:  \"Fetch a specified block, writing it to a file.\",\n\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)","sourceCodeStart":25,"sourceCodeEnd":61,"githubUrl":"https://github.com/hyperledger/fabric/blob/2736b63f8fd5932511d56fe68b7039d15977f7f6/internal/peer/channel/fetch.go#L25-L61","documentation":"`peer channel fetch` takes a positional target argument saying which block to fetch: 'oldest', 'newest', 'config', or a block number. If no positional argument is present, the command cannot determine what to fetch and errors immediately.","triggerScenarios":"Running `peer channel fetch` with zero positional args, e.g. `peer channel fetch -c mychannel config.block -o orderer:7050` where the target was given as a flag value instead of a positional arg.","commonSituations":"Misplaced flags swallowing the positional argument; copying an example that used a different CLI layout; shell splitting issues dropping the argument.","solutions":["Provide the target as the first positional arg: peer channel fetch config <output.block> -c <channel> -o <orderer:port>.","Check flag ordering so flags don't consume the positional argument.","Verify shell quoting so the arg isn't lost to variable expansion."],"exampleFix":"// before\npeer channel fetch -c mychannel -o orderer:7050 newest.block\n// after\npeer channel fetch newest newest.block -c mychannel -o orderer:7050","handlingStrategy":"validation","validationCode":"if [ $# -lt 1 ]; then echo \"usage: peer channel fetch <oldest|newest|config|N> <outfile> -c <channel>\" >&2; exit 1; fi\npeer channel fetch \"$@\"","typeGuard":"function isValidFetchTarget(t) { return ['oldest','newest','config'].includes(t) || /^[0-9]+$/.test(t); }","tryCatchPattern":null,"preventionTips":["Always give the fetch target as the first positional arg.","Put flags after positional args to avoid confusion.","Share a usage wrapper for peer channel fetch."],"tags":["cli","fabric","channel","missing-argument"],"backgroundTag":"missing-required-flag","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"}