{"record":{"id":"9129cb9977b99847","repo":"apache/seatunnel","slug":"unexpected-error-creating-database-db","errorCode":null,"errorMessage":"Unexpected error creating database: ${db}","messagePattern":"Unexpected error creating database: (.+?)","errorType":"exception","errorClass":"TException","httpStatus":null,"severity":"error","filePath":"seatunnel-connectors-v2/connector-hive/src/main/java/org/apache/seatunnel/connectors/seatunnel/hive/utils/HiveMetaStoreCatalog.java","lineNumber":470,"sourceCode":"        try {\n            try {\n                getClient().getDatabase(db);\n                log.debug(\"Database {} already exists\", db);\n                return;\n            } catch (org.apache.hadoop.hive.metastore.api.NoSuchObjectException ignored) {\n            }\n            Database database = new Database();\n            database.setName(db);\n            log.info(\"Creating database {}\", db);\n            getClient().createDatabase(database);\n        } catch (org.apache.hadoop.hive.metastore.api.AlreadyExistsException e) {\n            log.debug(\"Database {} already exists (race)\", db);\n        } catch (TException e) {\n            String errorMsg = String.format(\"Failed to create database [%s]\", db);\n            throw new HiveConnectorException(\n                    HiveConnectorErrorCode.CREATE_HIVE_TABLE_FAILED, errorMsg, e);\n        } catch (Exception e) {\n            throw new TException(\"Unexpected error creating database: \" + db, e);\n        }\n    }\n\n    public void createTableIfNotExists(@NonNull Table tbl) throws TException {\n        try {\n            if (getClient().tableExists(tbl.getDbName(), tbl.getTableName())) {\n                log.debug(\"Table {}.{} already exists\", tbl.getDbName(), tbl.getTableName());\n                return;\n            }\n            log.info(\"Creating table {}.{}\", tbl.getDbName(), tbl.getTableName());\n            getClient().createTable(tbl);\n        } catch (org.apache.hadoop.hive.metastore.api.AlreadyExistsException e) {\n            log.debug(\"Table {}.{} already exists (race)\", tbl.getDbName(), tbl.getTableName());\n        } catch (TException e) {\n            String errorMsg =\n                    String.format(\n                            \"Failed to create table [%s.%s]\", tbl.getDbName(), tbl.getTableName());\n            throw new HiveConnectorException(","sourceCodeStart":452,"sourceCodeEnd":488,"githubUrl":"https://github.com/apache/seatunnel/blob/cf67b549a7a6c35fa0beb12d83c62892427ea919/seatunnel-connectors-v2/connector-hive/src/main/java/org/apache/seatunnel/connectors/seatunnel/hive/utils/HiveMetaStoreCatalog.java#L452-L488","documentation":"A raw org.apache.hadoop.hive.metastore.api.TException thrown by createDatabaseIfNotExists when an unexpected non-Thrift Exception escapes the create path. Unlike the TException branch, this is a defensive catch-all indicating a bug or an unexpected runtime failure (e.g. NPE in client setup) while creating the database.","triggerScenarios":"Any RuntimeException/Error (except the handled TException/AlreadyExistsException paths) thrown during createDatabaseIfNotExists — e.g. NullPointerException from a mis-initialized metastore client, ClassCastException in config handling.","commonSituations":"Catalog not properly opened/initialized before use; bug in a custom client factory returning an incompatible client; environment issue (missing Hadoop config) causing unexpected runtime exception.","solutions":["Read the chained cause of the TException to identify the actual runtime failure.","Ensure the catalog is opened (open()) before calling createDatabase.","If using a custom client factory, verify it returns a fully functional IMetaStoreClient instance.","Report/log the full stack trace; this catch-all usually signals a bug rather than an expected condition."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n    catalog.createDatabaseIfNotExists(db);\n} catch (TException e) {\n    log.error(\"Unexpected database create failure for {}: \", db, e.getCause());\n    throw e;\n}","preventionTips":["Always call catalog.open() before catalog operations","Keep the catalog on a single thread or synchronize client access","Log full stack traces to catch client-initialization bugs early"],"tags":["hive","metastore","database","unexpected"],"backgroundTag":"internal-invariant-violation","analyzedSha":"cf67b549a7a6c35fa0beb12d83c62892427ea919","analyzedAt":"2026-09-10T21:44:55.265Z","contentChangedAt":"2026-09-10T21:44:55.265Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}