{"record":{"id":"730631632553a2f2","repo":"apache/pulsar","slug":"namespace-does-not-exist-730631","errorCode":null,"errorMessage":"Namespace does not exist","messagePattern":"Namespace does not exist","errorType":"http","errorClass":"RestException","httpStatus":400,"severity":"error","filePath":"pulsar-functions/worker/src/main/java/org/apache/pulsar/functions/worker/rest/api/SourcesImpl.java","lineNumber":117,"sourceCode":"            throw new RestException(Response.Status.BAD_REQUEST, \"Source config is not provided\");\n        }\n\n        throwRestExceptionIfUnauthorizedForNamespace(tenant, namespace, sourceName, \"register\", authParams);\n\n        try {\n            // Check tenant exists\n            worker().getBrokerAdmin().tenants().getTenantInfo(tenant);\n\n            String qualifiedNamespace = tenant + \"/\" + namespace;\n            List<String> namespaces = worker().getBrokerAdmin().namespaces().getNamespaces(tenant);\n            if (namespaces != null && !namespaces.contains(qualifiedNamespace)) {\n                String qualifiedNamespaceWithCluster = String.format(\"%s/%s/%s\", tenant,\n                        worker().getWorkerConfig().getPulsarFunctionsCluster(), namespace);\n                if (namespaces != null && !namespaces.contains(qualifiedNamespaceWithCluster)) {\n                    log.error().attr(\"tenant\", tenant).attr(\"namespace\", namespace).attr(\"componentName\", sourceName)\n\n                            .attr(\"namespace3\", namespace).log(\"/ / Namespace does not exist\");\n                    throw new RestException(Response.Status.BAD_REQUEST, \"Namespace does not exist\");\n                }\n            }\n        } catch (PulsarAdminException.NotAuthorizedException e) {\n            log.error().attr(\"tenant\", tenant).attr(\"namespace\", namespace).attr(\"componentName\", sourceName)\n\n                    .attr(\"componentType\", ComponentTypeUtils.toString(componentType))\n\n                    .log(\"/ / Client is not authorized to operate on tenant\");\n            throw new RestException(Response.Status.UNAUTHORIZED, \"Client is not authorized to perform operation\");\n        } catch (PulsarAdminException.NotFoundException e) {\n            log.error().attr(\"tenant\", tenant).attr(\"namespace\", namespace).attr(\"componentName\", sourceName)\n\n                    .attr(\"tenant3\", tenant).log(\"/ / Tenant does not exist\");\n            throw new RestException(Response.Status.BAD_REQUEST, \"Tenant does not exist\");\n        } catch (PulsarAdminException e) {\n            log.error().attr(\"tenant\", tenant).attr(\"namespace\", namespace).attr(\"componentName\", sourceName)\n\n                    .exception(e).log(\"/ / Issues getting tenant data\");","sourceCodeStart":99,"sourceCodeEnd":135,"githubUrl":"https://github.com/apache/pulsar/blob/820761864ed8e2a7d2e52dd9763ad2ae117c1395/pulsar-functions/worker/src/main/java/org/apache/pulsar/functions/worker/rest/api/SourcesImpl.java#L99-L135","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Create the namespace: pulsar-admin namespaces create <tenant>/<namespace>.","Verify spelling and that tenant/namespace match what you passed to the API.","In multi-cluster deployments, ensure the namespace is created on (or replicated to) the worker's configured pulsarFunctionsCluster.","Check the worker's cluster configuration if the namespace exists but keeps failing the qualified-name check."],"exampleFix":"// before\npulsar-admin sources create --tenant my-tenant --namespace prod_ns ... // namespace never created\n// after\npulsar-admin namespaces create my-tenant/prod_ns\npulsar-admin sources create --tenant my-tenant --namespace prod_ns ...","handlingStrategy":"validation","validationCode":"boolean exists = admin.namespaces().getNamespaces(tenant).contains(tenant + \"/\" + namespace);\nif (!exists) throw new IllegalStateException(\"create it: pulsar-admin namespaces create \" + tenant + \"/\" + namespace);","typeGuard":"boolean namespaceExists(PulsarAdmin admin, String tenant, String ns) {\n    try { return admin.namespaces().getNamespaces(tenant).contains(tenant + \"/\" + ns); }\n    catch (PulsarAdminException e) { return false; }\n}","tryCatchPattern":"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; }","preventionTips":["Create tenant+namespace during environment bootstrap before deploying sources","Verify namespace existence with namespaces().getNamespaces before create calls","In multi-cluster setups, align worker pulsarFunctionsCluster with namespace clusters","Copy tenant/namespace values from config, avoiding manual typing"],"tags":["validation","http-400","namespace","rest-api"],"backgroundTag":"namespace-not-found","analyzedSha":"820761864ed8e2a7d2e52dd9763ad2ae117c1395","analyzedAt":"2026-09-06T00:14:20.138Z","contentChangedAt":"2026-09-06T00:14:20.138Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}