{"record":{"id":"290dd0310e45efdb","repo":"hyperledger/fabric","slug":"the-required-parameter-channelid-is-empty-rerun-290dd0","errorCode":null,"errorMessage":"The required parameter 'channelID' is empty. Rerun the command with -C flag","messagePattern":"The required parameter 'channelID' is empty\\. Rerun the command with -C flag","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/peer/chaincode/query.go","lineNumber":50,"sourceCode":"\t\t\"name\",\n\t\t\"channelID\",\n\t\t\"peerAddresses\",\n\t\t\"tlsRootCertFiles\",\n\t\t\"connectionProfile\",\n\t}\n\tattachFlags(chaincodeQueryCmd, flagList)\n\n\tchaincodeQueryCmd.Flags().BoolVarP(&chaincodeQueryRaw, \"raw\", \"r\", false,\n\t\t\"If true, output the query value as raw bytes, otherwise format as a printable string\")\n\tchaincodeQueryCmd.Flags().BoolVarP(&chaincodeQueryHex, \"hex\", \"x\", false,\n\t\t\"If true, output the query value byte array in hexadecimal. Incompatible with --raw\")\n\n\treturn chaincodeQueryCmd\n}\n\nfunc chaincodeQuery(cmd *cobra.Command, cf *ChaincodeCmdFactory, cryptoProvider bccsp.BCCSP) error {\n\tif channelID == \"\" {\n\t\treturn errors.New(\"The required parameter 'channelID' is empty. Rerun the command with -C flag\")\n\t}\n\t// Parsing of the command line is done so silence cmd usage\n\tcmd.SilenceUsage = true\n\n\tvar err error\n\tif cf == nil {\n\t\tcf, err = InitCmdFactory(cmd.Name(), true, false, cryptoProvider)\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\t}\n\n\treturn chaincodeInvokeOrQuery(cmd, false, cf)\n}\n","sourceCodeStart":32,"sourceCodeEnd":65,"githubUrl":"https://github.com/hyperledger/fabric/blob/2736b63f8fd5932511d56fe68b7039d15977f7f6/internal/peer/chaincode/query.go#L32-L65","documentation":"The peer CLI chaincode query command requires a target channel via the -C (or --channelID) flag. chaincodeQuery validates the global channelID before building the proposal; a query is always channel-scoped, so an empty channel makes the request meaningless and it aborts early.","triggerScenarios":"Running `peer chaincode query` without -C/--channelID, or with -C set to an empty string.","commonSituations":"Forgetting the flag in shell scripts or CI jobs; confusing the -n (chaincode name) flag with -C (channel); copying examples that omitted the flag; channel name resolved from an unset variable.","solutions":["Re-run with the channel: peer chaincode query -C <channel-name> -n <cc> -c '<args>'","Export/define the channel variable in your environment or script before invoking.","Validate the channel argument in wrapper scripts before calling the peer CLI."],"exampleFix":"// before\npeer chaincode query -n mycc -c '{\"Args\":[\"get\",\"a\"]}'\n// after\npeer chaincode query -C mychannel -n mycc -c '{\"Args\":[\"get\",\"a\"]}'","handlingStrategy":"validation","validationCode":"if [ -z \"$CHANNEL_NAME\" ]; then echo \"error: -C channelID required\" >&2; exit 1; fi\npeer chaincode query -C \"$CHANNEL_NAME\" -n mycc -c '{\"Args\":[\"get\",\"a\"]}'","typeGuard":"function hasChannelID(args) { return typeof args.C === 'string' && args.C.length > 0; }","tryCatchPattern":null,"preventionTips":["Always pass -C with chaincode query.","Distinguish -n (chaincode) from -C (channel) in documentation.","Centralize peer CLI calls in wrapper scripts with arg validation."],"tags":["cli","fabric","chaincode","missing-flag"],"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"}