{"record":{"id":"b15e51474440a4cd","repo":"apache/pulsar","slug":"need-to-specify-either-enable-delete-while-inactiv","errorCode":null,"errorMessage":"Need to specify either enable-delete-while-inactive or disable-delete-while-inactive","messagePattern":"Need to specify either enable-delete-while-inactive or disable-delete-while-inactive","errorType":"validation","errorClass":"ParameterException","httpStatus":null,"severity":"error","filePath":"pulsar-client-tools/src/main/java/org/apache/pulsar/admin/cli/CmdNamespaces.java","lineNumber":1594,"sourceCode":"\n        @Option(names = { \"--disable-delete-while-inactive\", \"-d\" }, description = \"Disable delete while inactive\")\n        private boolean disableDeleteWhileInactive = false;\n\n        @Option(names = {\"--max-inactive-duration\", \"-t\"}, description = \"Max duration of topic inactivity in \"\n                + \"seconds, topics that are inactive for longer than this value will be deleted \"\n                + \"(eg: 1s, 10s, 1m, 5h, 3d)\", required = true,\n                converter = TimeUnitToSecondsConverter.class)\n        private Long maxInactiveDurationInSeconds;\n\n        @Option(names = { \"--delete-mode\", \"-m\" }, description = \"Mode of delete inactive topic, Valid options are: \"\n                + \"[delete_when_no_subscriptions, delete_when_subscriptions_caught_up]\", required = true)\n        private String inactiveTopicDeleteMode;\n\n        @Override\n        void run() throws PulsarAdminException {\n            String namespace = validateNamespace(namespaceName);\n            if (enableDeleteWhileInactive == disableDeleteWhileInactive) {\n                throw new ParameterException(\"Need to specify either enable-delete-while-inactive or \"\n                        + \"disable-delete-while-inactive\");\n            }\n            InactiveTopicDeleteMode deleteMode = null;\n            try {\n                deleteMode = InactiveTopicDeleteMode.valueOf(inactiveTopicDeleteMode);\n            } catch (IllegalArgumentException e) {\n                throw new ParameterException(\"delete mode can only be set to delete_when_no_subscriptions or \"\n                        + \"delete_when_subscriptions_caught_up\");\n            }\n            getAdmin().namespaces().setInactiveTopicPolicies(namespace, new InactiveTopicPolicies(deleteMode,\n                    maxInactiveDurationInSeconds.intValue(), enableDeleteWhileInactive));\n        }\n    }\n\n    @Command(description = \"Set the delayed delivery policy on a namespace\")\n    private class SetDelayedDelivery extends CliCommand {\n        @Parameters(description = \"tenant/namespace\", arity = \"1\")\n        private String namespaceName;","sourceCodeStart":1576,"sourceCodeEnd":1612,"githubUrl":"https://github.com/apache/pulsar/blob/820761864ed8e2a7d2e52dd9763ad2ae117c1395/pulsar-client-tools/src/main/java/org/apache/pulsar/admin/cli/CmdNamespaces.java#L1576-L1612","documentation":"Thrown by the 'set-inactive-topic-policies' namespace command when the flags controlling delete-while-inactive are ambiguous: enableDeleteWhileInactive == disableDeleteWhileInactive, i.e. neither flag was set or both were set. The command requires exactly one so it knows whether delete-while-inactive is switched on, and the error message names the two flags without the leading dashes. The command aborts before calling the admin API.","triggerScenarios":"Running 'pulsar-admin namespaces set-inactive-topic-policies <ns> --delete-when-no-subscriptions ...' without exactly one of the enable/disable-delete-while-inactive flags, or passing both at once.","commonSituations":"Omitting the toggle flag because the delete mode value was supplied (assuming mode alone implies enable); template merging adding both flags; older script examples predating the flag rename that drop the toggle.","solutions":["Pass exactly one of the delete-while-inactive enable/disable flags together with --max-inactive-duration and the delete mode.","If enabling, include the enable flag explicitly plus a valid --inactive-topic-delete-mode value (delete_when_no_subscriptions or delete_when_subscriptions_caught_up).","Audit generated command lines to ensure the toggle flag is always present exactly once."],"exampleFix":"// before\npulsar-admin namespaces set-inactive-topic-policies public/default --delete-when-no-subscriptions --max-inactive-duration 30\n// after\npulsar-admin namespaces set-inactive-topic-policies public/default --enable-delete-while-inactive --delete-when-no-subscriptions --max-inactive-duration 30","handlingStrategy":"validation","validationCode":"MODE=\"delete_when_no_subscriptions\"\nif [[ \"$MODE\" != \"delete_when_no_subscriptions\" && \"$MODE\" != \"delete_when_subscriptions_caught_up\" ]]; then echo \"invalid delete mode: $MODE\"; exit 1; fi\npulsar-admin namespaces set-inactive-topic-policies public/default --enable-delete-while-inactive \"$MODE\" --max-inactive-duration 30","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always include the enable/disable-delete-while-inactive toggle exactly once.","Validate the delete mode string against the two accepted enum values before running.","Keep toggle and mode flags in the same script block to avoid partial invocations."],"tags":["cli","parameter-validation","pulsar-admin"],"backgroundTag":"missing-required-cli-flag","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"}