{"record":{"id":"dd7fc39c394b7604","repo":"apache/iceberg","slug":"failed-to-check-if-schema-s-exists","errorCode":null,"errorMessage":"Failed to check if schema '%s' exists","messagePattern":"Failed to check if schema '(.+?)' exists","errorType":"exception","errorClass":"UncheckedSQLException","httpStatus":null,"severity":"error","filePath":"snowflake/src/main/java/org/apache/iceberg/snowflake/JdbcSnowflakeClient.java","lineNumber":203,"sourceCode":"        \"schemaExists requires a SCHEMA identifier, got '%s'\",\n        schema);\n\n    if (!databaseExists(SnowflakeIdentifier.ofDatabase(schema.databaseName()))) {\n      return false;\n    }\n\n    final String finalQuery = \"SHOW TABLES IN SCHEMA IDENTIFIER(?) LIMIT 1\";\n\n    try {\n      connectionPool.run(\n          conn ->\n              queryHarness.query(\n                  conn, finalQuery, TABLE_RESULT_SET_HANDLER, schema.toIdentifierString()));\n    } catch (SQLException e) {\n      if (SCHEMA_NOT_FOUND_ERROR_CODES.contains(e.getErrorCode())) {\n        return false;\n      }\n      throw new UncheckedSQLException(e, \"Failed to check if schema '%s' exists\", schema);\n    } catch (InterruptedException e) {\n      throw new UncheckedInterruptedException(\n          e, \"Interrupted while checking if schema '%s' exists\", schema);\n    }\n\n    return true;\n  }\n\n  @Override\n  public List<SnowflakeIdentifier> listDatabases() {\n    List<SnowflakeIdentifier> databases;\n    try {\n      databases =\n          connectionPool.run(\n              conn ->\n                  queryHarness.query(\n                      conn, \"SHOW DATABASES IN ACCOUNT\", DATABASE_RESULT_SET_HANDLER));\n    } catch (SQLException e) {","sourceCodeStart":185,"sourceCodeEnd":221,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/snowflake/src/main/java/org/apache/iceberg/snowflake/JdbcSnowflakeClient.java#L185-L221","documentation":"JdbcSnowflakeClient.schemaExists wraps unexpected SQLExceptions from the schema existence check into UncheckedSQLException. Known 'schema does not exist' error codes return false instead; this error means the check itself failed — connection, driver, or permission problem. It propagates unchecked to the catalog caller.","triggerScenarios":"Calling schemaExists on a SnowflakeCatalog when the JDBC query checking the schema throws a SQLException whose error code is not in SCHEMA_NOT_FOUND_ERROR_CODES — e.g. invalid connection, missing privileges, or driver-level failure.","commonSituations":"Expired or invalid Snowflake session credentials, the role lacks USAGE on the database so SHOW SCHEMAS fails, network issues, or an unsupported JDBC driver version.","solutions":["Validate Snowflake connectivity and credentials with a direct JDBC test query","Grant the connecting role USAGE privileges on the parent database so schema lookups succeed","Retry on transient failures; inspect the cause SQLException for the Snowflake error code","Confirm the database identifier in the schema reference is correct to avoid scope-related SQL failures"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"try (Connection c = DriverManager.getConnection(jdbcUrl, user, pass)) {\n  ResultSet rs = c.createStatement().executeQuery(\"SHOW DATABASES LIKE '\" + db + \"'\");\n  if (!rs.next()) return; // database missing; schema check would be false anyway\n}","typeGuard":null,"tryCatchPattern":"try {\n  client.schemaExists(schemaId);\n} catch (UncheckedSQLException e) {\n  LOG.error(\"Schema existence check failed: {}\", e.getCause().getMessage());\n  throw new IcebergRuntimeException(\"Check Snowflake connectivity and role privileges\", e);\n}","preventionTips":["Ensure the connecting role has USAGE on the parent database","Test JDBC connectivity independently before catalog operations","Keep the Snowflake JDBC driver up to date","Catch and inspect the cause SQLException for actionable Snowflake error codes"],"tags":["snowflake","jdbc","sql"],"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-14T16:17:12.679Z"}