apache/pulsar · error · ParameterException
Could not apply regex when read topics from file.
Error message
Could not apply regex when read topics from file.
What it means
In CmdTopics.DeleteCmd, --read-from-file (which reads topic names line-by-line from a file) is mutually exclusive with --regex pattern matching; combining them is ambiguous and rejected up front with this ParameterException. No topics are deleted when this fires.
Source
Thrown at pulsar-client-tools/src/main/java/org/apache/pulsar/admin/cli/CmdTopics.java:633
"--force" }, description = "Close all producer/consumer/replicator and delete topic forcefully")
private boolean force = false;
@Option(names = {"-d", "--deleteSchema"}, description = "Delete schema while deleting topic, "
+ "but the parameter is invalid and the schema is always deleted", hidden = true)
private boolean deleteSchema = false;
@Option(names = {"-r", "regex"},
description = "Use a regex expression to match multiple topics for deletion.")
boolean regex = false;
@Option(names = {"--from-file"}, description = "Read a list of topics from a file for deletion.")
boolean readFromFile;
@Override
void run() throws PulsarAdminException, IOException {
if (readFromFile && regex) {
throw new ParameterException("Could not apply regex when read topics from file.");
}
if (readFromFile) {
List<String> topicsFromFile = Files.readAllLines(Path.of(topic));
for (String t : topicsFromFile) {
try {
getTopics().delete(t, force);
} catch (Exception e) {
print("Failed to delete topic: " + t + ". Exception: " + e);
}
}
} else {
String topicName = validateTopicName(topic);
if (regex) {
String namespace = TopicName.get(topic).getNamespace();
List<String> topics = getTopics().getList(namespace);
topics = topics.stream().filter(s -> s.matches(topicName)).toList();
for (String t : topics) {
try {View on GitHub (pinned to 820761864e)
Solutions
- Remove the --regex flag and put literal topic names in the file, or
- Remove --read-from-file and pass the regex pattern directly as the topic argument
- Split the operation: filter the file first, then delete with literal names
Example fix
// before pulsar-admin topics delete --read-from-file topics.txt --regex 'my-tenant/ns/.*' // after pulsar-admin topics delete --read-from-file topics.txt // or pulsar-admin topics delete 'my-tenant/ns/.*' --regex
Defensive patterns
Strategy: validation
Validate before calling
if (readFromFile && regex) throw new IllegalArgumentException("--read-from-file and --regex are mutually exclusive"); Prevention
- Treat the two flags as mutually exclusive in wrapper scripts
- For regex bulk delete, resolve patterns to names first, then use a file of literal names
- Review accumulated flag sets in shared delete scripts
When it happens
Trigger: Running 'pulsar-admin topics delete' with both --read-from-file and --regex flags present, e.g. a script accumulated flags from two different invocation styles.
Common situations: Wrapper scripts that always append --regex while adding --read-from-file for bulk deletions; users thinking the file contents can be regex patterns; copy-paste merging of two example commands.
Related errors
- 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
- Illegal auth action '${action}'. Possible values: ${Arrays.t
- Invalid key value pair '${property}', valid format like 'a=b
AI-assisted analysis of apache/pulsar@820761864e (2026-09-06).
Data as JSON: /api/errors/a8b12034bad086b5.
Report an issue: GitHub.