{"record":{"id":"8520e0828cd34340","repo":"hyperledger/fabric","slug":"fetch-target-illegal-s","errorCode":null,"errorMessage":"fetch target illegal: %s","messagePattern":"fetch target illegal: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/peer/channel/fetch.go","lineNumber":88,"sourceCode":"\tcase \"oldest\":\n\t\tblock, err = cf.DeliverClient.GetOldestBlock()\n\tcase \"newest\":\n\t\tblock, err = cf.DeliverClient.GetNewestBlock()\n\tcase \"config\":\n\t\tiBlock, err2 := cf.DeliverClient.GetNewestBlock()\n\t\tif err2 != nil {\n\t\t\treturn err2\n\t\t}\n\t\tlc, err2 := protoutil.GetLastConfigIndexFromBlock(iBlock)\n\t\tif err2 != nil {\n\t\t\treturn err2\n\t\t}\n\t\tlogger.Infof(\"Retrieving last config block: %d\", lc)\n\t\tblock, err = cf.DeliverClient.GetSpecifiedBlock(lc)\n\tdefault:\n\t\tnum, err2 := strconv.Atoi(args[0])\n\t\tif err2 != nil {\n\t\t\treturn fmt.Errorf(\"fetch target illegal: %s\", args[0])\n\t\t}\n\t\tblock, err = cf.DeliverClient.GetSpecifiedBlock(uint64(num))\n\t}\n\tif err != nil {\n\t\treturn err\n\t}\n\n\tif block == nil {\n\t\treturn errors.New(\"proto: Marshal called with nil\")\n\t}\n\tb, err := proto.Marshal(block)\n\tif err != nil {\n\t\treturn err\n\t}\n\n\tvar file string\n\tif len(args) == 1 {\n\t\tfile = channelID + \"_\" + args[0] + \".block\"","sourceCodeStart":70,"sourceCodeEnd":106,"githubUrl":"https://github.com/hyperledger/fabric/blob/2736b63f8fd5932511d56fe68b7039d15977f7f6/internal/peer/channel/fetch.go#L70-L106","documentation":"When the fetch target is neither oldest/newest/config, the command parses it as a decimal block number with strconv.Atoi. A non-numeric target falls into the default case and fails conversion, so the command reports the offending string as illegal.","triggerScenarios":"Running `peer channel fetch <something> ...` where <something> is misspelled (e.g. 'latest' instead of 'newest', '0x5', 'block-3') or contains whitespace/quotes.","commonSituations":"Typo 'latest' for 'newest'; copy-paste including a stray character; passing a hash or tx ID instead of a block number; localized digit characters.","solutions":["Use one of: oldest, newest, config, or a plain decimal number (e.g. 5).","Correct the typo (latest → newest).","Strip whitespace/quotes from the argument in scripts before invoking.","Use `peer channel getinfo -c <channel>` to find valid block numbers."],"exampleFix":"// before\npeer channel fetch latest mychannel.block -c mychannel -o orderer:7050\n// after\npeer channel fetch newest mychannel.block -c mychannel -o orderer:7050","handlingStrategy":"validation","validationCode":"TARGET=\"$1\"\nif [ \"$TARGET\" != \"oldest\" ] && [ \"$TARGET\" != \"newest\" ] && [ \"$TARGET\" != \"config\" ] && ! [[ \"$TARGET\" =~ ^[0-9]+$ ]]; then\n  echo \"error: fetch target must be oldest, newest, config, or a number\" >&2; exit 1\nfi","typeGuard":"function isValidFetchTarget(t) { return ['oldest','newest','config'].includes(t) || /^[0-9]+$/.test(t); }","tryCatchPattern":null,"preventionTips":["Use canonical keywords: oldest/newest/config (not latest).","Use plain decimal block numbers.","Validate target in wrapper scripts."],"tags":["cli","fabric","channel","invalid-argument"],"backgroundTag":"invalid-argument-value","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"}