{"record":{"id":"8b14c7e430f52517","repo":"apache/iceberg","slug":"nosuchnamespaceexception-wrapped-in-runtimeexcept","errorCode":null,"errorMessage":"NoSuchNamespaceException (wrapped in RuntimeException)","messagePattern":"NoSuchNamespaceException \\(wrapped in RuntimeException\\)","errorType":"exception","errorClass":"RuntimeException","httpStatus":404,"severity":"warning","filePath":"spark/v4.2/spark/src/main/java/org/apache/iceberg/spark/SparkSessionCatalog.java","lineNumber":527,"sourceCode":"  }\n\n  @Override\n  public Identifier[] listViews(String... namespace) {\n    Set<Identifier> views = sessionViews(namespace);\n    views.addAll(icebergViews(namespace));\n    return views.toArray(new Identifier[0]);\n  }\n\n  private Set<Identifier> sessionViews(String[] namespace) {\n    Set<Identifier> views = Sets.newLinkedHashSet();\n    try {\n      if (isViewCatalog()) {\n        views.addAll(Arrays.asList(getSessionCatalog().listViews(namespace)));\n      } else {\n        getSessionCatalog().listTables(namespace);\n      }\n    } catch (NoSuchNamespaceException e) {\n      throw new RuntimeException(e);\n    }\n\n    return views;\n  }\n\n  private Set<Identifier> icebergViews(String[] namespace) {\n    Set<Identifier> views = Sets.newLinkedHashSet();\n    if (null != asViewCatalog) {\n      try {\n        views.addAll(Arrays.asList(asViewCatalog.listViews(namespace)));\n      } catch (NoSuchNamespaceException e) {\n        // The session catalog owns namespaces, so a valid namespace may not exist in Iceberg.\n      }\n    }\n\n    return views;\n  }\n","sourceCodeStart":509,"sourceCodeEnd":545,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/spark/v4.2/spark/src/main/java/org/apache/iceberg/spark/SparkSessionCatalog.java#L509-L545","documentation":"sessionViews lists views (and validates the namespace by listing tables when the delegate is not a view catalog) for a given namespace. If the delegated session catalog throws NoSuchNamespaceException, meaning the namespace does not exist, it is wrapped and rethrown as a RuntimeException rather than propagated as the checked catalog exception.","triggerScenarios":"Calling viewIdentifiers/views (e.g. SHOW VIEWS) for a namespace that does not exist in the delegated session catalog; getSessionCatalog().listViews(namespace) or listTables(namespace) throws NoSuchNamespaceException.","commonSituations":"Listing views in a namespace that was never created; typo in namespace parts; catalogs whose listViews enforces namespace existence while callers assume empty results.","solutions":["Verify the namespace exists (listNamespaces or SupportsNamespaces.namespaceExists) before listing views","Catch NoSuchNamespaceException at the call site (it is wrapped, so catch RuntimeException and inspect the cause)","Create the namespace first with CREATE NAMESPACE"],"exampleFix":"// before\nsparkCatalog.views(namespace); // wraps NoSuchNamespaceException in RuntimeException\n// after\nif (catalog.namespaceExists(namespace)) { views = sparkCatalog.views(namespace); }","handlingStrategy":"try-catch","validationCode":"// confirm the namespace exists before listing views\nif (!catalog.namespaceExists(namespace)) {\n  return Set.of();\n}","typeGuard":null,"tryCatchPattern":"try {\n  views = sparkCatalog.views(namespace);\n} catch (RuntimeException e) {\n  if (e.getCause() instanceof NoSuchNamespaceException) {\n    views = Set.of(); // namespace absent\n  } else {\n    throw e;\n  }\n}","preventionTips":["Create namespaces before listing or creating views in them","Validate namespace spelling and depth (multi-part names)","Remember sessionViews wraps the checked exception, so inspect getCause()"],"tags":["spark","namespace","view"],"backgroundTag":"resource-not-found","analyzedSha":"86d9c8fc543e7c56c9f624eb725f76c9baff9570","analyzedAt":"2026-09-12T00:46:39.097Z","contentChangedAt":"2026-09-12T00:46:39.097Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}