apache/pulsar · error · ParameterException
Must specify num-partitions or num-partitions > 0 for partit
Error message
Must specify num-partitions or num-partitions > 0 for partitioned topic type.
What it means
Thrown when --enable --type partitioned is given but --default-num-partitions is missing, zero, or negative. Partitioned auto-creation requires a valid positive partition count, so the override is rejected before calling setAutoTopicCreation.
Source
Thrown at pulsar-client-tools/src/main/java/org/apache/pulsar/admin/cli/CmdNamespaces.java:663
private Integer defaultNumPartitions = null;
@Override
void run() throws PulsarAdminException {
String namespace = validateNamespace(namespaceName);
type = type.toLowerCase().trim();
if (enable == disable) {
throw new ParameterException("Need to specify either --enable or --disable");
}
if (enable) {
if (!TopicType.isValidTopicType(type)) {
throw new ParameterException("Must specify type of topic to be created. "
+ "Possible values: (partitioned, non-partitioned)");
}
if (TopicType.PARTITIONED.toString().equals(type)
&& (defaultNumPartitions == null || defaultNumPartitions <= 0)) {
throw new ParameterException("Must specify num-partitions or num-partitions > 0 "
+ "for partitioned topic type.");
}
}
getAdmin().namespaces().setAutoTopicCreation(namespace,
AutoTopicCreationOverride.builder()
.allowAutoTopicCreation(enable)
.topicType(type)
.defaultNumPartitions(defaultNumPartitions)
.build());
}
}
@Command(description = "Get autoTopicCreation info for a namespace")
private class GetAutoTopicCreation extends CliCommand {
@Parameters(description = "tenant/namespace", arity = "1")
private String namespaceName;
@OverrideView on GitHub (pinned to 820761864e)
Solutions
- Add a positive --default-num-partitions, e.g. --default-num-partitions 4
- Ensure the script computing partitions yields a number >= 1
- Use --type non-partitioned instead if no partition count is desired
- Verify flag name --default-num-partitions (not --num-partitions) in your CLI version
Example fix
// before pulsar-admin namespaces set-auto-topic-creation t/ns --enable --type partitioned // after pulsar-admin namespaces set-auto-topic-creation t/ns --enable --type partitioned --default-num-partitions 4
Defensive patterns
Strategy: validation
Validate before calling
if [ "$TYPE" = partitioned ]; then
[ -n "$NUM_PARTITIONS" ] && [ "$NUM_PARTITIONS" -ge 1 ] || { echo "--default-num-partitions must be >= 1 for partitioned"; exit 1; }
fi Try / catch
try { ... } catch (ParameterException e) { /* missing/invalid partitions: add positive --default-num-partitions */ } Prevention
- Always pair --type partitioned with a positive --default-num-partitions
- Validate the partitions variable is a non-empty integer >= 1
- Use --type non-partitioned when no partition count applies
When it happens
Trigger: Running `set-auto-topic-creation --enable --type partitioned` without --default-num-partitions, or with a value <= 0; non-partitioned type bypasses this check entirely.
Common situations: Assuming the broker default applies; scripting where the partitions variable is empty (parses as 0/null); copying the non-partitioned invocation and switching type without adding partitions.
Related errors
- Must specify type of topic to be created. Possible values: (
- Need to provide a persistent topic name
- Need to provide a non-persistent topic name
- Invalid message id (must be in format: ledgerId:entryId) val
- unable to parse namespaces parameter list:
AI-assisted analysis of apache/pulsar@820761864e (2026-09-06).
Data as JSON: /api/errors/8dc5d5a92cad957a.
Report an issue: GitHub.