{"record":{"id":"0c420830eb65189b","repo":"apache/pulsar","slug":"delete-mode-can-only-be-set-to-delete-when-no-subs-0c4208","errorCode":null,"errorMessage":"delete mode can only be set to delete_when_no_subscriptions or delete_when_subscriptions_caught_up","messagePattern":"delete mode can only be set to delete_when_no_subscriptions or delete_when_subscriptions_caught_up","errorType":"validation","errorClass":"ParameterException","httpStatus":null,"severity":"error","filePath":"pulsar-client-tools/src/main/java/org/apache/pulsar/admin/cli/CmdTopics.java","lineNumber":2821,"sourceCode":"                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 persistentTopic = validatePersistentTopic(topicName);\n            if (enableDeleteWhileInactive == disableDeleteWhileInactive) {\n                throw new IllegalArgumentException(\"Need to specify either enable-delete-while-inactive \"\n                        + \"or 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 \"\n                        + \"or delete_when_subscriptions_caught_up\");\n            }\n            getTopics().setInactiveTopicPolicies(persistentTopic, new InactiveTopicPolicies(deleteMode,\n                    maxInactiveDurationInSeconds.intValue(), enableDeleteWhileInactive));\n        }\n    }\n\n    @Command(description = \"Remove inactive topic policies from a topic\", hidden = true)\n    private class RemoveInactiveTopicPolicies extends CliCommand {\n        @Parameters(description = \"persistent://tenant/namespace/topic\", arity = \"1\")\n        private String topicName;\n\n        @Override\n        void run() throws PulsarAdminException {\n            String persistentTopic = validatePersistentTopic(topicName);\n            getTopics().removeInactiveTopicPolicies(persistentTopic);\n        }\n    }","sourceCodeStart":2803,"sourceCodeEnd":2839,"githubUrl":"https://github.com/apache/pulsar/blob/820761864ed8e2a7d2e52dd9763ad2ae117c1395/pulsar-client-tools/src/main/java/org/apache/pulsar/admin/cli/CmdTopics.java#L2803-L2839","documentation":"In SetInactiveTopicPolicies, the --delete-mode value is parsed with InactiveTopicDeleteMode.valueOf. If it is not exactly one of the enum constants (delete_when_no_subscriptions or delete_when_subscriptions_caught_up), the IllegalArgumentException is rethrown as this ParameterException. Note the message omits case-sensitivity warning — valueOf is exact-match.","triggerScenarios":"Running `pulsar-admin topics set-inactive-topic-policies <topic> --delete-mode <value>` with misspelled, wrong-cased, or kebab-cased values like `delete-when-no-subscriptions` or `DeleteWhenNoSubscriptions`.","commonSituations":"Converting the enum constants to kebab-case to match CLI flag style; copying mode names from broker.conf where formatting differs; typos in automation scripts.","solutions":["Use exactly `--delete-mode delete_when_no_subscriptions` or `--delete-mode delete_when_subscriptions_caught_up`.","Match the snake_case spelling with underscores, not hyphens, and all lowercase.","Check available modes via the enum InactiveTopicDeleteMode or the get-inactive-topic-policies output."],"exampleFix":"// before\nbin/pulsar-admin topics set-inactive-topic-policies my-topic --delete-mode delete-when-no-subscriptions --enable-delete-while-inactive\n// after\nbin/pulsar-admin topics set-inactive-topic-policies my-topic --delete-mode delete_when_no_subscriptions --enable-delete-while-inactive","handlingStrategy":"validation","validationCode":"// validate delete mode before invoking\ncase \"$DELETE_MODE\" in\n  delete_when_no_subscriptions|delete_when_subscriptions_caught_up) ;;\n  *) echo \"invalid --delete-mode: $DELETE_MODE\"; exit 1;;\nesac","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use exact snake_case enum values with underscores, not hyphens.","All lowercase — valueOf matching is case-sensitive.","Keep a constants file for CLI enum values reused across scripts."],"tags":["cli","argument-validation","enum"],"backgroundTag":"invalid-enum-value","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"}