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

  1. Use one of: oldest, newest, config, or a plain decimal number (e.g. 5).
  2. Correct the typo (latest → newest).
  3. Strip whitespace/quotes from the argument in scripts before invoking.
  4. 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

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


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