{"record":{"id":"eb310b6a789ed568","repo":"apache/iceberg","slug":"nosuchnamespaceexception-namespace-eb310b","errorCode":null,"errorMessage":"NoSuchNamespaceException(namespace)","messagePattern":"NoSuchNamespaceException\\(namespace\\)","errorType":"exception","errorClass":"NoSuchNamespaceException","httpStatus":null,"severity":"error","filePath":"spark/v4.0/spark/src/main/java/org/apache/iceberg/spark/SparkCatalog.java","lineNumber":478,"sourceCode":"  public String[][] listNamespaces() {\n    if (asNamespaceCatalog != null) {\n      return asNamespaceCatalog.listNamespaces().stream()\n          .map(Namespace::levels)\n          .toArray(String[][]::new);\n    }\n\n    return new String[0][];\n  }\n\n  @Override\n  public String[][] listNamespaces(String[] namespace) throws NoSuchNamespaceException {\n    if (asNamespaceCatalog != null) {\n      try {\n        return asNamespaceCatalog.listNamespaces(Namespace.of(namespace)).stream()\n            .map(Namespace::levels)\n            .toArray(String[][]::new);\n      } catch (org.apache.iceberg.exceptions.NoSuchNamespaceException e) {\n        throw new NoSuchNamespaceException(namespace);\n      }\n    }\n\n    throw new NoSuchNamespaceException(namespace);\n  }\n\n  @Override\n  public boolean namespaceExists(String[] namespace) {\n    return asNamespaceCatalog != null\n        && asNamespaceCatalog.namespaceExists(Namespace.of(namespace));\n  }\n\n  @Override\n  public Map<String, String> loadNamespaceMetadata(String[] namespace)\n      throws NoSuchNamespaceException {\n    if (asNamespaceCatalog != null) {\n      try {\n        return asNamespaceCatalog.loadNamespaceMetadata(Namespace.of(namespace));","sourceCodeStart":460,"sourceCodeEnd":496,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/spark/v4.0/spark/src/main/java/org/apache/iceberg/spark/SparkCatalog.java#L460-L496","documentation":"listNamespaces was called with a parent namespace that does not exist in the underlying Iceberg SupportsNamespaces catalog, so the Iceberg NoSuchNamespaceException was rethrown as Spark's NoSuchNamespaceException. There is also a fallback throw when the catalog does not implement SupportsNamespaces at all. Listing child namespaces requires the parent namespace itself to exist.","triggerScenarios":"Calling catalog.listNamespaces(namespace) where namespace (as String[]) is not a registered namespace; using SHOW NAMESPACES IN catalog under a nonexistent parent; the catalog is not a SupportsNamespaces (e.g. a flat path-based catalog) so any listNamespaces call throws.","commonSituations":"Discovering namespace hierarchy in metadata tools; HadoopCatalog users listing under a prefix that was never created; catalogs backed by stores without namespace support (listNamespaces always throws).","solutions":["Check namespaceExists(namespace) before calling listNamespaces with a parent.","Call listNamespaces() with no arguments to list top-level namespaces first.","Create the parent namespace with createNamespace before listing children.","If the catalog lacks namespace support, switch to a catalog implementing SupportsNamespaces (e.g. Hive, Hadoop, Nessie)."],"exampleFix":"// before\nString[][] children = catalog.listNamespaces(new String[] {\"analytics\"}); // throws\n\n// after\nif (catalog.namespaceExists(new String[] {\"analytics\"})) {\n  String[][] children = catalog.listNamespaces(new String[] {\"analytics\"});\n}","handlingStrategy":"try-catch","validationCode":"if (catalog.namespaceExists(new String[] {\"analytics\"})) {\n  // safe to list children\n}","typeGuard":"boolean isNamespaceCatalog(Object c) {\n  return c instanceof org.apache.spark.sql.connector.catalog.SupportsNamespaces;\n}","tryCatchPattern":"try {\n  String[][] children = catalog.listNamespaces(ns);\n} catch (NoSuchNamespaceException e) {\n  // parent absent: create it or return empty result\n}","preventionTips":["List top-level namespaces first before descending","Create parent namespaces explicitly in bootstrap scripts","Confirm catalog supports SupportsNamespaces before namespace APIs","Treat missing parents as empty in discovery tooling"],"tags":["spark","catalog","namespace-not-found"],"backgroundTag":"entity-not-found","analyzedSha":"86d9c8fc543e7c56c9f624eb725f76c9baff9570","analyzedAt":"2026-09-12T00:46:39.097Z","contentChangedAt":"2026-09-12T00:46:39.097Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}