{"record":{"id":"60b5a7026439d9f6","repo":"apache/pulsar","slug":"please-supply-message-content-with-either-messag","errorCode":null,"errorMessage":"Please supply message content with either --messages or --files","messagePattern":"Please supply message content with either --messages or --files","errorType":"validation","errorClass":"CommandLine.ParameterException","httpStatus":null,"severity":"error","filePath":"pulsar-client-tools/src/main/java/org/apache/pulsar/client/cli/CmdProduce.java","lineNumber":256,"sourceCode":"    /**\n     * Run the producer.\n     *\n     * @return 0 for success, < 0 otherwise\n     * @throws Exception\n     */\n    @SuppressWarnings({\"rawtypes\", \"unchecked\"})\n    public int run() throws PulsarClientException {\n        if (this.numTimesProduce <= 0) {\n            throw new CommandLine.ParameterException(commandSpec.commandLine(),\n                    \"Number of times need to be positive number.\");\n        }\n\n        if (messages.size() > 0) {\n            messages = messages.stream().map(str -> str.split(separator)).flatMap(Stream::of).toList();\n        }\n\n        if (messages.size() == 0 && messageFileNames.size() == 0) {\n            throw new CommandLine.ParameterException(commandSpec.commandLine(),\n                    \"Please supply message content with either --messages or --files\");\n        }\n\n        if (keyValueEncodingType == null) {\n            keyValueEncodingType = KEY_VALUE_ENCODING_TYPE_NOT_SET;\n        } else if (!KEY_VALUE_ENCODING_TYPE_NOT_SET.equals(keyValueEncodingType)) {\n            // KeyValue schemas are not yet supported by the V5-based pulsar-client.\n            throw new IllegalArgumentException(\"KeyValue schemas (--key-value-encoding-type) are not \"\n                    + \"supported by this version of pulsar-client; produce with a plain value schema \"\n                    + \"(-vs bytes|string|avro:<def>|json:<def>) instead.\");\n        }\n\n        int totalMessages = (messages.size() + messageFileNames.size()) * numTimesProduce;\n        if (totalMessages > MAX_MESSAGES) {\n            String msg = \"Attempting to send \" + totalMessages + \" messages. Please do not send more than \"\n                    + MAX_MESSAGES + \" messages\";\n            throw new IllegalArgumentException(msg);\n        }","sourceCodeStart":238,"sourceCodeEnd":274,"githubUrl":"https://github.com/apache/pulsar/blob/820761864ed8e2a7d2e52dd9763ad2ae117c1395/pulsar-client-tools/src/main/java/org/apache/pulsar/client/cli/CmdProduce.java#L238-L274","documentation":"CmdProduce.run() validates that the producer was given content before creating a client. picocli option parsing allows invoking `pulsar-client produce` with neither --messages (-m) nor --files (-f); because that would silently send nothing, the command throws a CommandLine.ParameterException, which picocli prints as a usage error.","triggerScenarios":"Running `pulsar-client produce <topic>` with neither --messages nor --files, or with options whose values are empty (e.g. -m '' resolves to an empty list after splitting on the separator).","commonSituations":"Scripted/CI invocations where message content comes from a variable that is empty; forgetting -m/-f because the shell command was copied from a WebSocket or producer-args variant; quoting bugs that make the shell drop the argument.","solutions":["Pass message content: add --messages/-m with one or more strings, e.g. -m 'hello' -m 'world'.","Pass file content instead: add --files/-f pointing to file(s) whose bytes become the message body.","Check that the variable feeding -m is non-empty in your script (e.g. : \"${MSG:?empty}\" in bash).","If you intended multiple values, keep them separated by the configured separator so the split produces a non-empty list."],"exampleFix":"// before\npulsar-client produce my-topic --url ...\n// after\npulsar-client produce my-topic --url ... -m 'hello'","handlingStrategy":"validation","validationCode":"// bash: fail fast before invoking the CLI\n: \"${MSG:?MSG must be non-empty}\"\n[ -n \"$MSG\" ] || { echo 'provide --messages or --files'; exit 1; }","typeGuard":"function hasProduceContent(msgs, files) { return (Array.isArray(msgs) && msgs.length > 0) || (Array.isArray(files) && files.length > 0); }","tryCatchPattern":null,"preventionTips":["Always pass either -m or -f when scripting `pulsar-client produce`.","Validate variables for emptiness before interpolating into CLI arguments.","Quote arguments to avoid shell word-splitting dropping empty values."],"tags":["cli","picocli","validation","pulsar-client"],"backgroundTag":"missing-required-cli-option","analyzedSha":"820761864ed8e2a7d2e52dd9763ad2ae117c1395","analyzedAt":"2026-09-06T00:14:20.138Z","contentChangedAt":"2026-09-06T00:14:20.138Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}