apolloconfig/apollo · error · BadRequestException

Namespace's branch not exist. AppId = %s, ClusterName = %s,

Error message

Namespace's branch not exist. AppId = %s, ClusterName = %s, NamespaceName = %s, BranchName = %s

What it means

A BadRequestException (HTTP 400) thrown from NamespaceBranchController.checkBranch() when a gray-release branch (child namespace) is not found. The check first validates the parent namespace exists, then looks up the child namespace by appId + branchName + namespaceName via namespaceService.findOne(). A null result means the specified branch does not exist for the given parent. The message includes all four identifiers for diagnostics.

Source

Thrown at apollo-adminservice/src/main/java/com/ctrip/framework/apollo/adminservice/controller/NamespaceBranchController.java:152

    checkNamespace(appId, clusterName, namespaceName);

    Namespace childNamespace = namespaceBranchService.findBranch(appId, clusterName, namespaceName);
    if (childNamespace == null) {
      return null;
    }

    return BeanUtils.transform(NamespaceDTO.class, childNamespace);
  }

  private void checkBranch(String appId, String clusterName, String namespaceName,
      String branchName) {
    // 1. check parent namespace
    checkNamespace(appId, clusterName, namespaceName);

    // 2. check child namespace
    Namespace childNamespace = namespaceService.findOne(appId, branchName, namespaceName);
    if (childNamespace == null) {
      throw new BadRequestException(
          "Namespace's branch not exist. AppId = %s, ClusterName = %s, NamespaceName = %s, BranchName = %s",
          appId, clusterName, namespaceName, branchName);
    }

  }

  private void checkNamespace(String appId, String clusterName, String namespaceName) {
    Namespace parentNamespace = namespaceService.findOne(appId, clusterName, namespaceName);
    if (parentNamespace == null) {
      throw BadRequestException.namespaceNotExists(appId, clusterName, namespaceName);
    }
  }


}

View on GitHub (pinned to d95fc18d11)

Solutions

  1. Verify the branchName exists by listing branches for the parent namespace before operating on it.
  2. Check that the branch was not deleted by another user or process.
  3. Ensure appId, clusterName, namespaceName, and branchName are all correct and correspond to the intended environment.
  4. If the branch should exist, create it via the branch-creation endpoint first.

Example fix

// before: assume branch exists
branchApi.updateBranchRules(appId, env, clusterName, namespaceName, branchName, rules);

// after: verify branch existence first
List<NamespaceDTO> branches = branchApi.findBranches(appId, env, clusterName, namespaceName);
boolean exists = branches.stream().anyMatch(b -> branchName.equals(b.getClusterName()));
if (!exists) {
    throw new IllegalStateException("Branch does not exist, create it first");
}
branchApi.updateBranchRules(appId, env, clusterName, namespaceName, branchName, rules);
Defensive patterns

Strategy: validation

Validate before calling

// Verify the branch exists before operating
List<NamespaceDTO> branches = branchApi.findBranches(appId, env, clusterName, namespaceName);
boolean branchExists = branches.stream()
    .anyMatch(b -> branchName.equals(b.getClusterName()));
if (!branchExists) {
    // create branch or abort
    throw new IllegalStateException("Branch not found: " + branchName);
}
branchApi.updateBranchRules(appId, env, clusterName, namespaceName, branchName, rules);

Try / catch

try {
    branchApi.updateBranchRules(appId, env, clusterName, namespaceName, branchName, rules);
} catch (BadRequestException e) {
    if (e.getMessage().contains("branch not exist")) {
        // Branch was deleted or never existed; recreate or abort
        handleMissingBranch(appId, clusterName, namespaceName, branchName);
    } else {
        throw e;
    }
}

Prevention

When it happens

Trigger: Any namespace-branch operation (update branch rules, merge, delete branch) that calls checkBranch() with a branchName that does not resolve to a child Namespace for the given appId/clusterName/namespaceName. For example, calling the branch-update endpoint with a stale or incorrect branchName.

Common situations: The branch was already deleted by another operator; the branchName was mistyped or copy-pasted incorrectly; the branch was never created (the gray release was initiated but the branch namespace was not persisted); cross-environment confusion where a branch name from one env is used in another.

Related errors


AI-assisted analysis of apolloconfig/apollo@d95fc18d11 (2026-08-14). Data as JSON: /api/errors/7ab979fbc0bd1cc6. Report an issue: GitHub.