apache/iceberg · warning · RuntimeException

NoSuchNamespaceException (wrapped in RuntimeException)

Error message

NoSuchNamespaceException (wrapped in RuntimeException)

What it means

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.

Solutions

  1. Verify the namespace exists (listNamespaces or SupportsNamespaces.namespaceExists) before listing views
  2. Catch NoSuchNamespaceException at the call site (it is wrapped, so catch RuntimeException and inspect the cause)
  3. Create the namespace first with CREATE NAMESPACE

Example fix

// before
sparkCatalog.views(namespace); // wraps NoSuchNamespaceException in RuntimeException
// after
if (catalog.namespaceExists(namespace)) { views = sparkCatalog.views(namespace); }
Defensive patterns

Strategy: try-catch

Validate before calling

// confirm the namespace exists before listing views
if (!catalog.namespaceExists(namespace)) {
  return Set.of();
}

Try / catch

try {
  views = sparkCatalog.views(namespace);
} catch (RuntimeException e) {
  if (e.getCause() instanceof NoSuchNamespaceException) {
    views = Set.of(); // namespace absent
  } else {
    throw e;
  }
}

Prevention

When it happens

Trigger: 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.

Common situations: Listing views in a namespace that was never created; typo in namespace parts; catalogs whose listViews enforces namespace existence while callers assume empty results.

Understand the failure class

Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.

Related errors


AI-assisted analysis of apache/iceberg@86d9c8fc54 (2026-09-12). Data as JSON: /api/errors/8b14c7e430f52517. Report an issue: GitHub.

Appendix: source

Thrown at spark/v4.2/spark/src/main/java/org/apache/iceberg/spark/SparkSessionCatalog.java:527

  }

  @Override
  public Identifier[] listViews(String... namespace) {
    Set<Identifier> views = sessionViews(namespace);
    views.addAll(icebergViews(namespace));
    return views.toArray(new Identifier[0]);
  }

  private Set<Identifier> sessionViews(String[] namespace) {
    Set<Identifier> views = Sets.newLinkedHashSet();
    try {
      if (isViewCatalog()) {
        views.addAll(Arrays.asList(getSessionCatalog().listViews(namespace)));
      } else {
        getSessionCatalog().listTables(namespace);
      }
    } catch (NoSuchNamespaceException e) {
      throw new RuntimeException(e);
    }

    return views;
  }

  private Set<Identifier> icebergViews(String[] namespace) {
    Set<Identifier> views = Sets.newLinkedHashSet();
    if (null != asViewCatalog) {
      try {
        views.addAll(Arrays.asList(asViewCatalog.listViews(namespace)));
      } catch (NoSuchNamespaceException e) {
        // The session catalog owns namespaces, so a valid namespace may not exist in Iceberg.
      }
    }

    return views;
  }

View on GitHub (pinned to 86d9c8fc54)