apache/pulsar · error · RestException

Namespace does not exist

Error message

Namespace does not exist

What it means

After basic validation, registerSource lists the tenant's namespaces via the PulsarAdmin client and checks that the requested namespace (possibly qualified with the functions cluster) exists. If the namespace list does not contain it, it throws HTTP 400 'Namespace does not exist'. A NotAuthorizedException while listing is handled separately with a 403.

Source

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

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

        throwRestExceptionIfUnauthorizedForNamespace(tenant, namespace, sourceName, "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 != null && !namespaces.contains(qualifiedNamespaceWithCluster)) {
                    log.error().attr("tenant", tenant).attr("namespace", namespace).attr("componentName", sourceName)

                            .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", sourceName)

                    .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", sourceName)

                    .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", sourceName)

                    .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. Verify spelling and that tenant/namespace match what you passed to the API.
  3. In multi-cluster deployments, ensure the namespace is created on (or replicated to) the worker's configured pulsarFunctionsCluster.
  4. Check the worker's cluster configuration if the namespace exists but keeps failing the qualified-name check.

Example fix

// before
pulsar-admin sources create --tenant my-tenant --namespace prod_ns ... // namespace never created
// after
pulsar-admin namespaces create my-tenant/prod_ns
pulsar-admin sources create --tenant my-tenant --namespace prod_ns ...
Defensive patterns

Strategy: validation

Validate before calling

boolean exists = admin.namespaces().getNamespaces(tenant).contains(tenant + "/" + namespace);
if (!exists) throw new IllegalStateException("create it: pulsar-admin namespaces create " + tenant + "/" + namespace);

Type guard

boolean namespaceExists(PulsarAdmin admin, String tenant, String ns) {
    try { return admin.namespaces().getNamespaces(tenant).contains(tenant + "/" + ns); }
    catch (PulsarAdminException e) { return false; }
}

Try / catch

try { admin.sources().createSource(...); } catch (PulsarAdminException e) { if (e.getStatusCode() == 400 && e.getMessage().contains("Namespace does not exist")) { admin.namespaces().createNamespace(tenant + "/" + ns); /* retry */ } throw e; }

Prevention

When it happens

Trigger: registerSource with a tenant that exists but the namespace does not; the namespace exists but not in the expected form tenant/cluster/namespace when the worker's pulsarFunctionsCluster is set; PulsarAdminException other than NotAuthorized/NotFound propagating from the namespace list call.

Common situations: Typo in namespace during deploy; namespace never created; multi-cluster setups where the namespace is not hosted on/associated with the functions cluster the worker is configured for; stale worker config pointing at a different cluster.

Related errors


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