{"record":{"id":"1a2e082309444115","repo":"apache/iceberg","slug":"failed-to-list-schemas-for-scope-s","errorCode":null,"errorMessage":"Failed to list schemas for scope '%s'","messagePattern":"Failed to list schemas for scope '(.+?)'","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"snowflake/src/main/java/org/apache/iceberg/snowflake/JdbcSnowflakeClient.java","lineNumber":265,"sourceCode":"        baseQuery.append(\" IN DATABASE IDENTIFIER(?)\");\n        queryParams = new String[] {scope.toIdentifierString()};\n        break;\n      default:\n        throw new IllegalArgumentException(\n            String.format(\"Unsupported scope type for listSchemas: %s\", scope));\n    }\n\n    final String finalQuery = baseQuery.toString();\n    final String[] finalQueryParams = queryParams;\n    List<SnowflakeIdentifier> schemas;\n    try {\n      schemas =\n          connectionPool.run(\n              conn ->\n                  queryHarness.query(\n                      conn, finalQuery, SCHEMA_RESULT_SET_HANDLER, finalQueryParams));\n    } catch (SQLException e) {\n      throw snowflakeExceptionToIcebergException(\n          scope, e, String.format(\"Failed to list schemas for scope '%s'\", scope));\n    } catch (InterruptedException e) {\n      throw new UncheckedInterruptedException(\n          e, \"Interrupted while listing schemas for scope '%s'\", scope);\n    }\n    schemas.forEach(\n        schema ->\n            Preconditions.checkState(\n                schema.type() == SnowflakeIdentifier.Type.SCHEMA,\n                \"Expected SCHEMA, got identifier '%s' for scope '%s'\",\n                schema,\n                scope));\n    return schemas;\n  }\n\n  @Override\n  public List<SnowflakeIdentifier> listIcebergTables(SnowflakeIdentifier scope) {\n    StringBuilder baseQuery = new StringBuilder(\"SHOW ICEBERG TABLES\");","sourceCodeStart":247,"sourceCodeEnd":283,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/snowflake/src/main/java/org/apache/iceberg/snowflake/JdbcSnowflakeClient.java#L247-L283","documentation":"JdbcSnowflakeClient.listSchemas runs 'SHOW SCHEMAS ... IN DATABASE IDENTIFIER(?)' and wraps any SQLException into an IcebergException 'Failed to list schemas for scope %s'. It indicates the SHOW SCHEMAS query failed - typically the database does not exist or is inaccessible, or the connection/privileges are insufficient. If the database is not found, snowflakeExceptionToIcebergException maps it to NoSuchNamespaceException instead (only when the scope identifier is DATABASE type).","triggerScenarios":"Calling listSchemas(scope) (e.g., SnowflakeCatalog.listNamespaces(database)) where the JDBC query raises SQLException: nonexistent database name, no privileges on the database, dropped database, broken connection, or bad identifier format passed to IDENTIFIER(?).","commonSituations":"Typos or wrong casing in database names (Snowflake names are case-sensitive unquoted); database dropped between listing and use; role lacks USAGE on the database; expired auth; transient network failures.","solutions":["Verify the database exists and the name matches exactly (casing/quoted identifiers): run SHOW DATABASES and compare","Check the configured role has USAGE privileges on the database, or switch roles","Catch NoSuchNamespaceException specifically when the scope may not exist (it is mapped for DATABASE scopes with known error codes)","Inspect the underlying SQLException cause for auth/network issues and retry transient errors"],"exampleFix":"// before\ncatalog.listNamespaces(Namespace.of(\"MYDB\")); // SQLException -> 'Failed to list schemas for scope'\n// after\ntry {\n  catalog.listNamespaces(Namespace.of(\"MYDB\"));\n} catch (NoSuchNamespaceException e) {\n  // handle missing database\n} catch (IcebergException e) {\n  // inspect cause: privileges, auth, or connectivity\n}","handlingStrategy":"try-catch","validationCode":"// check the database exists before listing its schemas\nboolean exists = catalog.listNamespaces().stream()\n    .anyMatch(ns -> ns.level(0).equalsIgnoreCase(dbName));\nif (!exists) {\n  throw new NoSuchNamespaceException(ns); // handle before querying\n}","typeGuard":null,"tryCatchPattern":"try {\n  catalog.listNamespaces(Namespace.of(dbName));\n} catch (NoSuchNamespaceException e) {\n  // expected missing-scope path\n} catch (IcebergException e) {\n  SQLException cause = findCause(e, SQLException.class);\n  // distinguish privilege/auth (error code) vs transient; retry transient only\n}","preventionTips":["Match Snowflake identifier casing exactly (unquoted names are uppercase)","Grant the role USAGE on parent databases before listing schemas","Catch NoSuchNamespaceException for expected missing scopes instead of generic IcebergException","Retry transient errors with backoff; treat unknown error codes as fatal and inspect the cause"],"tags":["snowflake","jdbc","schema-listing"],"backgroundTag":"database-query-failed","analyzedSha":"86d9c8fc543e7c56c9f624eb725f76c9baff9570","analyzedAt":"2026-09-12T00:46:39.097Z","contentChangedAt":"2026-09-12T00:46:39.097Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}