{"record":{"id":"04fa9646ee813bbc","repo":"apolloconfig/apollo","slug":"parse-namespaces-error-expected-s-but-actual","errorCode":null,"errorMessage":"Parse namespaces error, expected: %s, but actual: %s, cannot get those namespaces: %s","messagePattern":"Parse namespaces error, expected: (.+?), but actual: (.+?), cannot get those namespaces: (.+?)","errorType":"exception","errorClass":"RuntimeException","httpStatus":500,"severity":"error","filePath":"apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/NamespaceService.java","lineNumber":220,"sourceCode":"          namespaceBOs.add(namespaceBO);\n        } catch (Exception e) {\n          LOGGER.error(\"parse namespace error. app id:{}, env:{}, clusterName:{}, namespace:{}\",\n              appId, env, clusterName, namespace.getNamespaceName(), e);\n          exceptionNamespaces.add(namespace.getNamespaceName());\n        } finally {\n          latch.countDown();\n        }\n      });\n\n    }\n    try {\n      latch.await();\n    } catch (InterruptedException e) {\n      // ignore\n    }\n\n    if (namespaceBOs.size() != namespaces.size()) {\n      throw new RuntimeException(String.format(\n          \"Parse namespaces error, expected: %s, but actual: %s, cannot get those namespaces: %s\",\n          namespaces.size(), namespaceBOs.size(), exceptionNamespaces));\n    }\n\n    return namespaceBOs.stream().sorted(Comparator.comparing(o -> o.getBaseInfo().getId()))\n        .collect(Collectors.toList());\n  }\n\n  public List<NamespaceBO> findNamespaceBOs(String appId, Env env, String clusterName) {\n    return findNamespaceBOs(appId, env, clusterName, true, true);\n  }\n\n  public List<NamespaceDTO> findNamespaces(String appId, Env env, String clusterName) {\n    return namespaceAPI.findNamespaceByCluster(appId, env, clusterName);\n  }\n\n  /**\n   * the returned content's size is not fixed. so please carefully used.","sourceCodeStart":202,"sourceCodeEnd":238,"githubUrl":"https://github.com/apolloconfig/apollo/blob/d95fc18d112589efc09ddcbe1507047584d55251/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/NamespaceService.java#L202-L238","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Check the portal logs for the preceding 'parse namespace error' lines which identify the specific failing namespaces and their exceptions.","Verify all config/admin services for the environment are healthy and reachable.","Investigate the specific namespace(s) listed in exceptionNamespaces for data corruption or missing dependencies.","Retry the operation after resolving the underlying namespace data issue."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  List<NamespaceBO> namespaceBOs = namespaceService.findNamespaceBOs(appId, env, clusterName);\n} catch (RuntimeException e) {\n  if (e.getMessage().contains(\"Parse namespaces error\")) {\n    log.error(\"Some namespaces failed to transform. Check logs for 'parse namespace error' lines.\", e);\n    // identify and fix the failing namespace, then retry\n  }\n  throw e;\n}","preventionTips":["Monitor portal and admin service health to catch transient failures during parallel namespace loading.","Investigate and fix any namespace with corrupted or inconsistent item data promptly.","Ensure portal and admin service versions are compatible to avoid deserialization errors.","Check that all referenced appnamespaces exist before loading namespace BOs."],"tags":["apollo-portal","namespace","parallel","runtime-exception","transform"],"backgroundTag":null,"analyzedSha":"d95fc18d112589efc09ddcbe1507047584d55251","analyzedAt":"2026-08-14T04:00:05.477Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}