apolloconfig/apollo · error · BadRequestException
create namespace failed for: %s
Error message
create namespace failed for: %s
What it means
Thrown as BadRequestException (HTTP 400) by ServerNamespaceManagementOpenApiService after a multi-environment namespace creation loop where one or more (env/cluster/namespace) tuples failed. The service collects failures per env and, if failedNamespaces is non-empty, throws with the joined list; per-env exceptions are logged and Tracer-tagged, not propagated individually.
Source
Thrown at apollo-portal/src/main/java/com/ctrip/framework/apollo/openapi/server/service/ServerNamespaceManagementOpenApiService.java:192
namespace.setClusterName(model.getClusterName());
namespace.setNamespaceName(namespaceName);
namespace.setDataChangeCreatedBy(operator);
namespace.setDataChangeLastModifiedBy(operator);
try {
namespaceService.createNamespace(Env.valueOf(model.getEnv()), namespace, operator);
namespaceService.assignNamespaceRoleToOperator(appId, namespaceName, operator);
} catch (Exception e) {
logger.error("create namespace fail.", e);
Tracer.logError(String.format("create namespace fail. (env=%s namespace=%s)",
model.getEnv(), namespaceName), e);
failedNamespaces
.add(String.format("%s/%s/%s", model.getEnv(), model.getClusterName(), namespaceName));
}
}
if (!failedNamespaces.isEmpty()) {
throw new BadRequestException("create namespace failed for: %s",
String.join(", ", failedNamespaces));
}
}
@Override
public void deleteNamespace(String appId, String env, String clusterName, String namespaceName,
String operator) {
namespaceService.deleteNamespace(appId, Env.valueOf(env), clusterName, namespaceName, operator);
}
@Override
public List<OpenNamespaceUsageDTO> findNamespaceUsage(String appId, String env,
String clusterName, String namespaceName) {
NamespaceUsage usage = namespaceService.getNamespaceUsageByEnv(appId, namespaceName,
Env.valueOf(env), clusterName);
return OpenApiModelConverters.fromNamespaceUsages(Collections.singletonList(usage));
}
View on GitHub (pinned to d95fc18d11)
Solutions
- Inspect server logs / Tracer for the per-env 'create namespace fail. (env=... namespace=...)' entries to find the failing env.
- Make creation idempotent per env (skip envs where the namespace already exists).
- Retry only the failed envs listed in the message, after fixing the root cause for each.
Example fix
// before: bulk create across [DEV,FAT,UAT,PRO] throws listing only failed envs
// after: handle per-env existence before creating
for (Env env : envs) {
if (namespaceService.findOne(appId, env, cluster, name) == null) {
// create only where absent
}
} Defensive patterns
Strategy: try-catch
Validate before calling
for (Env env : envs) {
if (namespaceService.findOne(appId, env, clusterName, namespaceName) == null) {
// create only where absent to avoid per-env failures
}
} Try / catch
try {
service.createNamespace(appId, model, operator);
} catch (BadRequestException e) {
if (e.getMessage().startsWith("create namespace failed for:")) {
// parse failed envs from message, inspect logs/Tracer, retry only failed envs
} else throw e;
} Prevention
- Pre-check namespace existence per env before bulk creation.
- Log and surface per-env root causes, not just the aggregated failure list.
- Retry only the failed envs after remediation.
When it happens
Trigger: Calling createNamespace across multiple envs where at least one env fails (e.g., namespace already exists in that env, env unreachable, role assignment failure). The message lists every failed env/cluster/namespace.
Common situations: Partial multi-env provisioning where one env already has the namespace; an env's admin service down; role assignment race in one env.
Related errors
- Namespace's role does not exist. Please check whether namesp
- Create namespace permission is required
- Current user not found
- Unsupported auth type: %s
- Params(NamespaceName) can not be empty.
AI-assisted analysis of apolloconfig/apollo@d95fc18d11 (2026-08-14).
Data as JSON: /api/errors/cb1f6b0374535c1a.
Report an issue: GitHub.