hyperledger/fabric · error
fetch target required, oldest, newest, config, or a number
Error message
fetch target required, oldest, newest, config, or a number
What it means
`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.
Source
Thrown at internal/peer/channel/fetch.go:43
Use: "fetch <newest|oldest|config|(number)> [outputfile]",
Short: "Fetch a block",
Long: "Fetch a specified block, writing it to a file.",
RunE: func(cmd *cobra.Command, args []string) error {
return fetch(cmd, args, cf)
},
}
flagList := []string{
"channelID",
"bestEffort",
}
attachFlags(fetchCmd, flagList)
return fetchCmd
}
func fetch(cmd *cobra.Command, args []string, cf *ChannelCmdFactory) error {
if len(args) == 0 {
return fmt.Errorf("fetch target required, oldest, newest, config, or a number")
}
if len(args) > 2 {
return fmt.Errorf("trailing args detected")
}
// Parsing of the command line is done so silence cmd usage
cmd.SilenceUsage = true
// default to fetching from orderer
ordererRequired := OrdererRequired
peerDeliverRequired := PeerDeliverNotRequired
if len(strings.Split(common.OrderingEndpoint, ":")) != 2 {
// if no orderer endpoint supplied, connect to peer's deliver service
ordererRequired = OrdererNotRequired
peerDeliverRequired = PeerDeliverRequired
}
var err error
if cf == nil {
cf, err = InitCmdFactory(EndorserNotRequired, peerDeliverRequired, ordererRequired)View on GitHub (pinned to 2736b63f8f)
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.
Example fix
// before peer channel fetch -c mychannel -o orderer:7050 newest.block // after peer channel fetch newest newest.block -c mychannel -o orderer:7050
Defensive patterns
Strategy: validation
Validate before calling
if [ $# -lt 1 ]; then echo "usage: peer channel fetch <oldest|newest|config|N> <outfile> -c <channel>" >&2; exit 1; fi peer channel fetch "$@"
Type guard
function isValidFetchTarget(t) { return ['oldest','newest','config'].includes(t) || /^[0-9]+$/.test(t); } Prevention
- 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.
When it happens
Trigger: 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.
Common situations: Misplaced flags swallowing the positional argument; copying an example that used a different CLI layout; shell splitting issues dropping the argument.
Understand the failure class
Background: "--flag is required" and "must specify" CLI errors: how missing-required-flag validation works and how to fix it — this error's family across 20 libraries.
Related errors
- must supply channel ID
- trailing args detected
- fetch target illegal: %s
- The required parameter 'package-id' is empty. Rerun the comm
- chaincode install package must be provided
AI-assisted analysis of hyperledger/fabric@2736b63f8f (2026-09-04).
Data as JSON: /api/errors/7007fc73265a7c4e.
Report an issue: GitHub.