hyperledger/fabric · error
fetch target illegal: %s
Error message
fetch target illegal: %s
What it means
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.
Source
Thrown at internal/peer/channel/fetch.go:88
case "oldest":
block, err = cf.DeliverClient.GetOldestBlock()
case "newest":
block, err = cf.DeliverClient.GetNewestBlock()
case "config":
iBlock, err2 := cf.DeliverClient.GetNewestBlock()
if err2 != nil {
return err2
}
lc, err2 := protoutil.GetLastConfigIndexFromBlock(iBlock)
if err2 != nil {
return err2
}
logger.Infof("Retrieving last config block: %d", lc)
block, err = cf.DeliverClient.GetSpecifiedBlock(lc)
default:
num, err2 := strconv.Atoi(args[0])
if err2 != nil {
return fmt.Errorf("fetch target illegal: %s", args[0])
}
block, err = cf.DeliverClient.GetSpecifiedBlock(uint64(num))
}
if err != nil {
return err
}
if block == nil {
return errors.New("proto: Marshal called with nil")
}
b, err := proto.Marshal(block)
if err != nil {
return err
}
var file string
if len(args) == 1 {
file = channelID + "_" + args[0] + ".block"View on GitHub (pinned to 2736b63f8f)
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.
Example fix
// before peer channel fetch latest mychannel.block -c mychannel -o orderer:7050 // after peer channel fetch newest mychannel.block -c mychannel -o orderer:7050
Defensive patterns
Strategy: validation
Validate before calling
TARGET="$1" if [ "$TARGET" != "oldest" ] && [ "$TARGET" != "newest" ] && [ "$TARGET" != "config" ] && ! [[ "$TARGET" =~ ^[0-9]+$ ]]; then echo "error: fetch target must be oldest, newest, config, or a number" >&2; exit 1 fi
Type guard
function isValidFetchTarget(t) { return ['oldest','newest','config'].includes(t) || /^[0-9]+$/.test(t); } Prevention
- Use canonical keywords: oldest/newest/config (not latest).
- Use plain decimal block numbers.
- Validate target in wrapper scripts.
When it happens
Trigger: Running `peer channel fetch <something> ...` where <something> is misspelled (e.g. 'latest' instead of 'newest', '0x5', 'block-3') or contains whitespace/quotes.
Common situations: Typo 'latest' for 'newest'; copy-paste including a stray character; passing a hash or tx ID instead of a block number; localized digit characters.
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
- must supply channel ID
- fetch target required, oldest, newest, config, or a number
- trailing args detected
- channel ID illegal, cannot be empty
- channel ID illegal, cannot be longer than %d
AI-assisted analysis of hyperledger/fabric@2736b63f8f (2026-09-04).
Data as JSON: /api/errors/8520e0828cd34340.
Report an issue: GitHub.