apache/pulsar · error · RestException

Namespace does not exist

Error message

Namespace does not exist

What it means

After the mandatory-field checks, registerFunction queries the broker for the tenant's namespaces; when the functions cluster is set and the requested namespace (or tenant/namespace/cluster triple) is not among them, it fails with HTTP 400 'Namespace does not exist'. The function must be registered into an existing namespace scoped to the Pulsar Functions cluster.

Source

Thrown at pulsar-functions/worker/src/main/java/org/apache/pulsar/functions/worker/rest/api/FunctionsImpl.java:119

            throw new RestException(Response.Status.BAD_REQUEST, "Function config is not provided");
        }

        throwRestExceptionIfUnauthorizedForNamespace(tenant, namespace, functionName, "register", authParams);

        try {
            // Check tenant exists
            worker().getBrokerAdmin().tenants().getTenantInfo(tenant);

            String qualifiedNamespace = tenant + "/" + namespace;
            List<String> namespaces = worker().getBrokerAdmin().namespaces().getNamespaces(tenant);
            if (namespaces != null && !namespaces.contains(qualifiedNamespace)) {
                String qualifiedNamespaceWithCluster = String.format("%s/%s/%s", tenant,
                        worker().getWorkerConfig().getPulsarFunctionsCluster(), namespace);
                if (!namespaces.contains(qualifiedNamespaceWithCluster)) {
                    log.error().attr("tenant", tenant).attr("namespace", namespace).attr("componentName", functionName)

                            .attr("namespace3", namespace).log("/ / Namespace does not exist");
                    throw new RestException(Response.Status.BAD_REQUEST, "Namespace does not exist");
                }
            }
        } catch (PulsarAdminException.NotAuthorizedException e) {
            log.error().attr("tenant", tenant).attr("namespace", namespace).attr("componentName", functionName)

                    .attr("componentType", ComponentTypeUtils.toString(componentType))

                    .log("/ / Client is not authorized to operate on tenant");
            throw new RestException(Response.Status.UNAUTHORIZED, "Client is not authorized to perform operation");
        } catch (PulsarAdminException.NotFoundException e) {
            log.error().attr("tenant", tenant).attr("namespace", namespace).attr("componentName", functionName)

                    .attr("tenant3", tenant).log("/ / Tenant does not exist");
            throw new RestException(Response.Status.BAD_REQUEST, "Tenant does not exist");
        } catch (PulsarAdminException e) {
            log.error().attr("tenant", tenant).attr("namespace", namespace).attr("componentName", functionName)

                    .exception(e).log("/ / Issues getting tenant data");

View on GitHub (pinned to 820761864e)

Solutions

  1. Create the namespace: 'pulsar-admin namespaces create <tenant>/<namespace>'
  2. Confirm the namespace is listed under the functions cluster: 'pulsar-admin namespaces list <tenant>' and compare with getPulsarFunctionsCluster()
  3. Fix the tenant/namespace spelling in the registration request
  4. Align workerConfig's pulsarFunctionsCluster with the cluster the namespace belongs to

Example fix

// before
// namespace 'analytics' does not exist on functions cluster
admin.functions().createFunction(tenant, "analytics", ...);
// after
admin.namespaces().createNamespace(tenant + "/analytics");
admin.functions().createFunction(tenant, "analytics", ...);
Defensive patterns

Strategy: validation

Validate before calling

try {
    boolean exists = admin.namespaces().getNamespaces(tenant).stream()
        .anyMatch(n -> n.endsWith("/" + namespace));
    if (!exists) throw new IllegalStateException("namespace " + tenant + "/" + namespace + " missing");
} catch (PulsarAdminException e) { throw new IllegalStateException("cannot verify namespace", e); }

Type guard

boolean namespaceExists(String tenant, String ns, java.util.List<String> all) {
    return all != null && all.stream().anyMatch(n -> n.equals(tenant + "/" + ns));
}

Try / catch

try { admin.functions().createFunction(...); }
catch (PulsarAdminException e) {
    if (e.getStatusCode() == 400 && String.valueOf(e.getMessage()).contains("Namespace does not exist")) {
        admin.namespaces().createNamespace(tenant + "/" + namespace); // then retry
    }
}

Prevention

When it happens

Trigger: Registering into tenant/namespace that was never created, or a namespace that exists on a different cluster than workerConfig.getPulsarFunctionsCluster(); also raised when the listing call itself finds nothing for that tenant.

Common situations: Typo in namespace name; namespace created on cluster 'local' but functions cluster configured as 'prod'; using a fresh install where 'public/default' was never provisioned; global vs per-cluster namespace replication mismatch.

Related errors


AI-assisted analysis of apache/pulsar@820761864e (2026-09-06). Data as JSON: /api/errors/3a483c500176d8e2. Report an issue: GitHub.