apache/pulsar · error · ParameterException

Need to specify either --enable or --disable

Error message

Need to specify either --enable or --disable

What it means

CmdTopics' SetDelayedDelivery command requires exactly one of the mutually exclusive flags --enable or --disable. The command throws this ParameterException when `enable == disable`, i.e. both flags were set to the same state (both true, both false, or neither provided). It is a CLI argument-validation guard before calling setDelayedDeliveryPolicy.

Source

Thrown at pulsar-client-tools/src/main/java/org/apache/pulsar/admin/cli/CmdTopics.java:1730

        @Option(names = { "--disable", "-d" }, description = "Disable delayed delivery messages")
        private boolean disable = false;

        @Option(names = { "--time", "-t" },
                description = "The tick time for when retrying on delayed delivery messages, affecting the accuracy of "
                        + "the delivery time compared to the scheduled time. (eg: 1s, 10s, 1m, 5h, 3d)",
                converter = TimeUnitToMillisConverter.class)
        private Long delayedDeliveryTimeInMills = 1_000L;

        @Option(names = {"--maxDelay", "-md"},
                description = "The max allowed delay for delayed delivery. (eg: 1s, 10s, 1m, 5h, 3d)",
                converter = TimeUnitToMillisConverter.class)
        private Long delayedDeliveryMaxDelayInMillis = 0L;

        @Override
        void run() throws PulsarAdminException {
            String topic = validateTopicName(topicName);
            if (enable == disable) {
                throw new ParameterException("Need to specify either --enable or --disable");
            }

            getTopics().setDelayedDeliveryPolicy(topic, DelayedDeliveryPolicies.builder()
                    .tickTime(delayedDeliveryTimeInMills)
                    .active(enable)
                    .maxDeliveryDelayInMillis(delayedDeliveryMaxDelayInMillis)
                    .build());
        }
    }

    @Command(description = "Remove the delayed delivery policy on a topic", hidden = true)
    private class RemoveDelayedDelivery extends CliCommand {
        @Parameters(description = "persistent://tenant/namespace/topic", arity = "1")
        private String topic;

        @Override
        void run() throws PulsarAdminException {
            String topicName = validateTopicName(topic);

View on GitHub (pinned to 820761864e)

Solutions

  1. Pass exactly one of --enable or --disable, e.g. `pulsar-admin topics set-delayed-delivery <topic> --enable`.
  2. If scripting, ensure the flag variable expands to exactly one value and is not empty.
  3. Use `pulsar-admin topics get-delayed-delivery <topic>` first to check the current policy before toggling.

Example fix

// before (no flag)
bin/pulsar-admin topics set-delayed-delivery persistent://public/default/my-topic
// after
bin/pulsar-admin topics set-delayed-delivery persistent://public/default/my-topic --enable
Defensive patterns

Strategy: validation

Validate before calling

// shell validation before invoking the CLI
if [ "$ENABLE_FLAG" != "--enable" ] && [ "$ENABLE_FLAG" != "--disable" ]; then
  echo "must pass exactly one of --enable or --disable"; exit 1;
fi
bin/pulsar-admin topics set-delayed-delivery "$TOPIC" "$ENABLE_FLAG"

Prevention

When it happens

Trigger: Running `pulsar-admin topics set-delayed-delivery <topic>` with neither --enable nor --disable, or with both flags supplied, or with `--enable=false --disable=false` such that the parsed booleans are equal.

Common situations: Scripting the command from a variable that expands to an empty flag; copying an old command line where the flag was renamed; assuming delayed delivery is enabled by default and omitting the flag.

Related errors


AI-assisted analysis of apache/pulsar@820761864e (2026-09-06). Data as JSON: /api/errors/9c92d31d3cb46427. Report an issue: GitHub.