apache/seatunnel · error · CatalogException

Failed to list tables for database

Error message

Failed to list tables for database: ${databaseName}

What it means

Thrown by MongodbCatalog.listTables when listing collection names via the Mongo driver fails after the database existence check passed; wraps the driver exception and names the database whose collections could not be listed.

Solutions

  1. Check the user's privileges: it needs listCollections on the target database.
  2. Inspect e.getCause() for the MongoDB driver error code to distinguish auth vs network.
  3. Retry on transient network errors; the list is not destructive.
  4. Verify replica set health / read preference configuration.

Example fix

// before
List<String> tables = catalog.listTables(dbName);
// after
try {
    List<String> tables = catalog.listTables(dbName);
} catch (CatalogException e) {
    if (e.getCause() instanceof MongoTimeoutException) {
        tables = catalog.listTables(dbName); // retry once
    } else { throw e; }
}
Defensive patterns

Strategy: try-catch

Validate before calling

// ensure privileges first
// db.getSiblingDB(admin).runCommand({usersInfo: "user"}) shows roles

Try / catch

try {
    catalog.listTables(dbName);
} catch (CatalogException e) {
    Throwable c = e.getCause();
    if (c instanceof MongoTimeoutException) { /* retry */ }
}

Prevention

When it happens

Trigger: Calling listTables when the connection dropped after the existence check, the user lacks listCollections permission on that database, or a transient network/timeout error occurs during listing.

Common situations: User with read-only limited role missing listCollections action, network blip between existence check and listing, secondary read preference with an unavailable secondary.

Understand the failure class

Background: Database query failed: Internal Server Error 500s wrapping SQL, Prisma, and connection failures — what to check first — this error's family across 16 libraries.

Related errors


AI-assisted analysis of apache/seatunnel@cf67b549a7 (2026-09-10). Data as JSON: /api/errors/2ead5f47e67cac5d. Report an issue: GitHub.

Appendix: source

Thrown at seatunnel-connectors-v2/connector-mongodb/src/main/java/org/apache/seatunnel/connectors/seatunnel/mongodb/catalog/MongodbCatalog.java:106

                dbs.add(name);
            }
            return dbs;
        } catch (Exception e) {
            throw new CatalogException("Failed to list databases", e);
        }
    }

    @Override
    public List<String> listTables(String databaseName)
            throws CatalogException, DatabaseNotExistException {
        if (!databaseExists(databaseName)) {
            throw new DatabaseNotExistException(name(), databaseName);
        }
        try {
            MongoDatabase db = mongoClient.getDatabase(databaseName);
            return db.listCollectionNames().into(new ArrayList<>());
        } catch (Exception e) {
            throw new CatalogException("Failed to list tables for database: " + databaseName, e);
        }
    }

    @Override
    public boolean tableExists(TablePath tablePath) throws CatalogException {
        try {
            return listTables(tablePath.getDatabaseName()).contains(tablePath.getTableName());
        } catch (DatabaseNotExistException e) {
            return false;
        }
    }

    @Override
    public CatalogTable getTable(TablePath tablePath)
            throws CatalogException, TableNotExistException {
        throw CommonError.unsupportedOperation(name(), "get table with tablePath ");
    }

View on GitHub (pinned to cf67b549a7)