{"record":{"id":"e98d417ce24f7105","repo":"apache/pulsar","slug":"delete-mode-can-only-be-set-to-delete-when-no-subs-e98d41","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/CmdTopicPolicies.java","lineNumber":1487,"sourceCode":"                + \"[delete_when_no_subscriptions, delete_when_subscriptions_caught_up]\", required = true)\n        private String inactiveTopicDeleteMode;\n\n        @Option(names = { \"--global\", \"-g\" }, description = \"Whether to set this policy globally. \"\n                + \"If set to true, the policy will be replicate to other clusters asynchronously\")\n        private boolean isGlobal = false;\n\n        @Override\n        void run() throws PulsarAdminException {\n            String persistentTopic = validatePersistentTopic(topicName);\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;\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            getTopicPolicies(isGlobal).setInactiveTopicPolicies(persistentTopic, new InactiveTopicPolicies(deleteMode,\n                    maxInactiveDurationInSeconds.intValue(), enableDeleteWhileInactive));\n        }\n    }\n\n    @Command(description = \"Remove inactive topic policies from a topic\")\n    private class RemoveInactiveTopicPolicies extends CliCommand {\n        @Parameters(description = \"persistent://tenant/namespace/topic\", arity = \"1\")\n        private String topicName;\n        @Option(names = { \"--global\", \"-g\" }, description = \"Whether to remove this policy globally. \"\n                + \"If set to true, the removing operation will be replicate to other clusters asynchronously\")\n        private boolean isGlobal = false;\n        @Override\n        void run() throws PulsarAdminException {\n            String persistentTopic = validatePersistentTopic(topicName);\n            getTopicPolicies(isGlobal).removeInactiveTopicPolicies(persistentTopic);","sourceCodeStart":1469,"sourceCodeEnd":1505,"githubUrl":"https://github.com/apache/pulsar/blob/820761864ed8e2a7d2e52dd9763ad2ae117c1395/pulsar-client-tools/src/main/java/org/apache/pulsar/admin/cli/CmdTopicPolicies.java#L1469-L1505","documentation":"The --delete-mode value for set-inactive-topic-policies is parsed with InactiveTopicDeleteMode.valueOf(); any string that is not an exact enum constant throws this ParameterException naming the two legal values. The broker is never contacted.","triggerScenarios":"Running set-inactive-topic-policies with --delete-mode values like 'delete_when_no_subs', 'none', 'all', wrong casing, or hyphenated variants of the enum names.","commonSituations":"Typos or abbreviations in scripts; confusion with retention/inactive values from other messaging systems; documentation from before the 'delete_when_subscriptions_caught_up' mode existed; YAML config strings copied verbatim into CLI flags.","solutions":["Use exactly delete_when_no_subscriptions or delete_when_subscriptions_caught_up for --delete-mode","Check the enum org.apache.pulsar.common.policies.data.InactiveTopicDeleteMode for the authoritative names"],"exampleFix":"// before\npulsar-admin topics set-inactive-topic-policies my-topic --delete-mode delete_when_no_subs --enable-delete-while-inactive\n// after\npulsar-admin topics set-inactive-topic-policies my-topic --delete-mode delete_when_no_subscriptions --enable-delete-while-inactive","handlingStrategy":"validation","validationCode":"final Set<String> VALID = Set.of(\"delete_when_no_subscriptions\", \"delete_when_subscriptions_caught_up\");\nif (!VALID.contains(deleteMode)) throw new IllegalArgumentException(\"delete-mode must be one of \" + VALID);","typeGuard":"static boolean isValidInactiveDeleteMode(String s) {\n    return Arrays.stream(InactiveTopicDeleteMode.values()).anyMatch(m -> m.name().equals(s));\n}","tryCatchPattern":null,"preventionTips":["Copy enum names exactly; no abbreviations or hyphens","Check your Pulsar version's InactiveTopicDeleteMode enum","Use shell completion where available"],"tags":["cli","pulsar-admin","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"}