apolloconfig/apollo · error · RuntimeException

Parse namespaces error, expected: %s, but actual: %s, cannot

Error message

Parse namespaces error, expected: %s, but actual: %s, cannot get those namespaces: %s

What it means

Thrown as a RuntimeException by NamespaceService.findNamespaceBOs() when the number of successfully transformed NamespaceBO objects doesn't match the number of NamespaceDTOs fetched from the cluster. The transformation runs in parallel via executorService; any thread that throws during transformNamespace2BO is caught, logged, and its namespace name added to exceptionNamespaces. After the CountDownLatch completes, if any namespaces failed, this exception reports the mismatch.

Source

Thrown at apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/NamespaceService.java:220

          namespaceBOs.add(namespaceBO);
        } catch (Exception e) {
          LOGGER.error("parse namespace error. app id:{}, env:{}, clusterName:{}, namespace:{}",
              appId, env, clusterName, namespace.getNamespaceName(), e);
          exceptionNamespaces.add(namespace.getNamespaceName());
        } finally {
          latch.countDown();
        }
      });

    }
    try {
      latch.await();
    } catch (InterruptedException e) {
      // ignore
    }

    if (namespaceBOs.size() != namespaces.size()) {
      throw new RuntimeException(String.format(
          "Parse namespaces error, expected: %s, but actual: %s, cannot get those namespaces: %s",
          namespaces.size(), namespaceBOs.size(), exceptionNamespaces));
    }

    return namespaceBOs.stream().sorted(Comparator.comparing(o -> o.getBaseInfo().getId()))
        .collect(Collectors.toList());
  }

  public List<NamespaceBO> findNamespaceBOs(String appId, Env env, String clusterName) {
    return findNamespaceBOs(appId, env, clusterName, true, true);
  }

  public List<NamespaceDTO> findNamespaces(String appId, Env env, String clusterName) {
    return namespaceAPI.findNamespaceByCluster(appId, env, clusterName);
  }

  /**
   * the returned content's size is not fixed. so please carefully used.

View on GitHub (pinned to d95fc18d11)

Solutions

  1. Check the portal logs for the preceding 'parse namespace error' lines which identify the specific failing namespaces and their exceptions.
  2. Verify all config/admin services for the environment are healthy and reachable.
  3. Investigate the specific namespace(s) listed in exceptionNamespaces for data corruption or missing dependencies.
  4. Retry the operation after resolving the underlying namespace data issue.
Defensive patterns

Strategy: try-catch

Try / catch

try {
  List<NamespaceBO> namespaceBOs = namespaceService.findNamespaceBOs(appId, env, clusterName);
} catch (RuntimeException e) {
  if (e.getMessage().contains("Parse namespaces error")) {
    log.error("Some namespaces failed to transform. Check logs for 'parse namespace error' lines.", e);
    // identify and fix the failing namespace, then retry
  }
  throw e;
}

Prevention

When it happens

Trigger: Loading all namespace BOs for a cluster where at least one namespace fails to transform — typically because the admin service returns malformed data for that namespace, items fail to deserialize, or a downstream API call (config service) errors during item detail filling.

Common situations: One namespace in the cluster has corrupted or inconsistent item data; the config service for one namespace is temporarily unreachable during parallel load; a namespace references a deleted or missing appnamespace; version mismatch between portal and admin service causing deserialization errors.

Related errors


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