{"record":{"id":"22321747925105f9","repo":"apache/pulsar","slug":"subscription-name-is-not-provided","errorCode":null,"errorMessage":"Subscription name is not provided.","messagePattern":"Subscription name is not provided\\.","errorType":"validation","errorClass":"CommandLine.ParameterException","httpStatus":null,"severity":"error","filePath":"pulsar-client-tools/src/main/java/org/apache/pulsar/client/cli/CmdConsume.java","lineNumber":160,"sourceCode":"    @Option(names = { \"-etp\", \"--end-timestamp\" }, description = \"End timestamp for consuming messages\")\n    private long endTimestamp = Long.MAX_VALUE;\n\n    public CmdConsume() {\n        // Do nothing\n        super();\n    }\n\n    @Spec\n    private CommandSpec commandSpec;\n\n    /**\n     * Run the consume command.\n     *\n     * @return 0 for success, < 0 otherwise\n     */\n    public int run() throws IOException {\n        if (this.subscriptionName == null || this.subscriptionName.isEmpty()) {\n            throw new CommandLine.ParameterException(commandSpec.commandLine(), \"Subscription name is not provided.\");\n        }\n        if (this.numMessagesToConsume < 0) {\n            throw new CommandLine.ParameterException(commandSpec.commandLine(),\n                    \"Number of messages should be zero or positive.\");\n        }\n        if (this.endTimestamp < 0) {\n            throw new CommandLine.ParameterException(commandSpec.commandLine(),\n                    \"end timestamp should be positive.\");\n        }\n\n        if (this.serviceURL.startsWith(\"ws\")) {\n            return consumeFromWebSocket(topic);\n        } else {\n            return consume(topic);\n        }\n    }\n\n    private int consume(String topic) {","sourceCodeStart":142,"sourceCodeEnd":178,"githubUrl":"https://github.com/apache/pulsar/blob/820761864ed8e2a7d2e52dd9763ad2ae117c1395/pulsar-client-tools/src/main/java/org/apache/pulsar/client/cli/CmdConsume.java#L142-L178","documentation":"CmdConsume.run validates command-line state before connecting and throws a picocli CommandLine.ParameterException if the subscription name is null or empty. A Pulsar consumer must be attached to a subscription, so the CLI refuses to proceed without one.","triggerScenarios":"Running the consume command without --subscription (or with -s '' ), so this.subscriptionName ends up null/empty when run() executes.","commonSituations":"Forgotten -s flag in scripts/CI; config template where the subscription variable expands to empty string; renaming the flag in a newer CLI version while old scripts still omit it.","solutions":["Pass a subscription name: --subscription my-sub (or -s my-sub)","Fix shell/config interpolation so the variable holding the subscription is not empty","Wrap the invocation to fail fast: check the argument before calling the CLI"],"exampleFix":"// before\npulsar-client consume persistent://public/default/topic --num-messages 10\n// after\npulsar-client consume persistent://public/default/topic -s my-sub --num-messages 10","handlingStrategy":"validation","validationCode":"if [ -z \"$SUB\" ]; then echo \"subscription (-s) is required\" >&2; exit 2; fi\npulsar-client consume ... -s \"$SUB\"","typeGuard":null,"tryCatchPattern":"try (PulsarClient cli = ...) {\n    int rc = cmdConsume.run();\n} catch (CommandLine.ParameterException e) {\n    System.err.println(\"Usage error: \" + e.getMessage());\n    System.exit(2);\n}","preventionTips":["Always pass -s/--subscription explicitly; never rely on defaults in scripts","Fail fast in wrappers: check that the subscription variable is non-empty before invoking","Keep a canonical script/template for consume commands so required flags are never dropped","Watch CLI release notes for flag renames that might silently drop the argument"],"tags":["cli","validation","arguments","picocli"],"backgroundTag":"missing-required-argument","analyzedSha":"820761864ed8e2a7d2e52dd9763ad2ae117c1395","analyzedAt":"2026-09-06T00:14:20.138Z","contentChangedAt":"2026-09-06T00:14:20.138Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}