{"record":{"id":"81529f1b44b07962","repo":"apache/pulsar","slug":"only-one-or-neither-of-version-and-all-version","errorCode":null,"errorMessage":"Only one or neither of --version and --all-version can be specified.","messagePattern":"Only one or neither of --version and --all-version can be specified\\.","errorType":"validation","errorClass":"ParameterException","httpStatus":null,"severity":"error","filePath":"pulsar-client-tools/src/main/java/org/apache/pulsar/admin/cli/CmdSchemas.java","lineNumber":66,"sourceCode":"        addCommand(\"compatibility\", new TestCompatibility());\n    }\n\n    @Command(description = \"Get the schema for a topic\")\n    private class GetSchema extends CliCommand {\n        @Parameters(description = \"persistent://tenant/namespace/topic\", arity = \"1\")\n        private String topicName;\n\n        @Option(names = {\"-v\", \"--version\"}, description = \"version\", required = false)\n        private Long version;\n\n        @Option(names = {\"-a\", \"--all-version\"}, description = \"all version\", required = false)\n        private boolean all = false;\n\n        @Override\n        void run() throws Exception {\n            String topic = validateTopicName(topicName);\n            if (version != null && all) {\n                throw new ParameterException(\"Only one or neither of --version and --all-version can be specified.\");\n            }\n            if (version == null && !all) {\n                System.out.println(getAdmin().schemas().getSchemaInfoWithVersion(topic));\n            } else if (!all) {\n                if (version < 0) {\n                    throw new ParameterException(\"Option --version must be greater than 0, but found \" + version);\n                }\n                System.out.println(getAdmin().schemas().getSchemaInfo(topic, version));\n            } else {\n                print(getAdmin().schemas().getAllSchemas(topic));\n            }\n        }\n    }\n\n    @Command(description = \"Get the schema for a topic\")\n    private class GetSchemaMetadata extends CliCommand {\n        @Parameters(description = \"persistent://tenant/namespace/topic\", arity = \"1\")\n        private String topicName;","sourceCodeStart":48,"sourceCodeEnd":84,"githubUrl":"https://github.com/apache/pulsar/blob/820761864ed8e2a7d2e52dd9763ad2ae117c1395/pulsar-client-tools/src/main/java/org/apache/pulsar/admin/cli/CmdSchemas.java#L48-L84","documentation":"`pulsar-admin schemas get` accepts either --version <n> to fetch a specific schema version or --all-version to fetch all versions, but not both. Passing both flags is contradictory and throws this ParameterException.","triggerScenarios":"Running `pulsar-admin schemas get --version 3 --all-version <topic>` or with both flags set in a script.","commonSituations":"Script variables for both flags populated by mistake; combining two example commands; alias wrapping both options.","solutions":["Use only --version <n> for a single version","Or use only --all-version for all versions","Use neither flag to get the latest schema info with version"],"exampleFix":"// before\npulsar-admin schemas get --topic t --version 2 --all-version\n// after\npulsar-admin schemas get --topic t --version 2","handlingStrategy":"validation","validationCode":"if (version != null && allVersion) {\n    throw new IllegalArgumentException(\"--version and --all-version are mutually exclusive\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    SchemaInfo info = admin.schemas().getSchemaInfo(topic);\n} catch (org.apache.pulsar.client.admin.PulsarAdminException e) {\n    // handle bad flag combination\n}","preventionTips":["Only build one of the two flags in wrapper scripts","Never hardcode both flags in aliases","Use no flag for latest, --version n for one version, --all-version for all"],"tags":["cli","schema","validation"],"backgroundTag":"mutually-exclusive-options","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"}