{"record":{"id":"a745a230e8c99202","repo":"apache/cassandra","slug":"keyspace-s-doesn-t-exist-a745a2","errorCode":null,"errorMessage":"Keyspace '%s' doesn't exist","messagePattern":"Keyspace '(.+?)' doesn't exist","errorType":"validation","errorClass":"InvalidRequestException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/cql3/statements/schema/SchemaDescriptionStatement.java","lineNumber":77,"sourceCode":"            throw new InvalidRequestException(String.format(\"Cannot set %s to empty string\", descriptionType.value));\n        }\n\n        if (description.length() > descriptionType.maxLength)\n        {\n            String msg = String.format(\"%s length (%d) exceeds maximum allowed length (%d)\",\n                                       descriptionType.value,\n                                       description.length(),\n                                       descriptionType.maxLength);\n            throw new InvalidRequestException(msg);\n        }\n    }\n\n    protected KeyspaceMetadata validateAndGetKeyspace(Keyspaces schema)\n    {\n        KeyspaceMetadata keyspace = schema.getNullable(keyspaceName);\n\n        if (null == keyspace)\n            throw ire(\"Keyspace '%s' doesn't exist\", keyspaceName);\n\n        return keyspace;\n    }\n\n    protected TableMetadata validateAndGetTable(Keyspaces schema, String tableName)\n    {\n        KeyspaceMetadata keyspaceMetadata = validateAndGetKeyspace(schema);\n\n        TableMetadata tableMetadata = keyspaceMetadata.getTableOrViewNullable(tableName);\n        if (null == tableMetadata)\n            throw ire(\"Table '%s.%s' doesn't exist\", keyspaceName, tableName);\n\n        if (tableMetadata.kind != REGULAR)\n            throw ire(\"Cannot set %s on non-regular table '%s.%s'\",descriptionType.value, keyspaceName, tableName);\n\n        return tableMetadata;\n    }\n","sourceCodeStart":59,"sourceCodeEnd":95,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/cql3/statements/schema/SchemaDescriptionStatement.java#L59-L95","documentation":"A schema-description statement (e.g. DESCRIBE-style/DDL validation in SchemaDescriptionStatement) tried to fetch metadata for a keyspace that does not exist in the current schema snapshot. validateAndGetKeyspace is the shared guard for all such statements and fails fast on a null lookup.","triggerScenarios":"Running a description/validation statement against a keyspace name not present in the cluster; typo in the keyspace; not issuing USE <ks> so an unset or wrong keyspace name is used; querying a keyspace that was dropped.","commonSituations":"Typos; connecting to the wrong cluster/environment; quoting keyspace names with different case; scripts assuming a keyspace exists after migration.","solutions":["Verify the keyspace exists: SELECT keyspace_name FROM system_schema.keyspaces;","Correct the keyspace name in the statement or USE clause","Connect to the intended cluster/environment before running DDL inspection"],"exampleFix":"// before\nDESCRIBE KEYSPACE ksmetrics;   // typo\n// after\nDESCRIBE KEYSPACE ks_metrics;","handlingStrategy":"validation","validationCode":"var exists = session.execute(\"SELECT keyspace_name FROM system_schema.keyspaces WHERE keyspace_name=?\", ks).iterator().hasNext();\nif (!exists) throw new IllegalArgumentException(\"Keyspace \" + ks + \" does not exist\");","typeGuard":null,"tryCatchPattern":"try { runDescription(); } catch (InvalidRequest e) { if (e.getMessage().startsWith(\"Keyspace\") && e.getMessage().contains(\"doesn't exist\")) promptForCorrectKeyspace(); else throw e; }","preventionTips":["List keyspaces (DESCRIBE KEYSPACES / system_schema.keyspaces) before referencing one","Set the keyspace explicitly with USE or fully qualify names","Verify you are connected to the intended cluster/environment"],"tags":["cassandra","cql","keyspace","not-found"],"backgroundTag":"resource-not-found","analyzedSha":"88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1","analyzedAt":"2026-09-10T07:29:22.284Z","contentChangedAt":"2026-09-10T07:29:22.284Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}