apache/cassandra · error · InvalidRequestException

Keyspace '%s' doesn't exist

Error message

Keyspace '%s' doesn't exist

What it means

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.

Source

Thrown at src/java/org/apache/cassandra/cql3/statements/schema/SchemaDescriptionStatement.java:77

            throw new InvalidRequestException(String.format("Cannot set %s to empty string", descriptionType.value));
        }

        if (description.length() > descriptionType.maxLength)
        {
            String msg = String.format("%s length (%d) exceeds maximum allowed length (%d)",
                                       descriptionType.value,
                                       description.length(),
                                       descriptionType.maxLength);
            throw new InvalidRequestException(msg);
        }
    }

    protected KeyspaceMetadata validateAndGetKeyspace(Keyspaces schema)
    {
        KeyspaceMetadata keyspace = schema.getNullable(keyspaceName);

        if (null == keyspace)
            throw ire("Keyspace '%s' doesn't exist", keyspaceName);

        return keyspace;
    }

    protected TableMetadata validateAndGetTable(Keyspaces schema, String tableName)
    {
        KeyspaceMetadata keyspaceMetadata = validateAndGetKeyspace(schema);

        TableMetadata tableMetadata = keyspaceMetadata.getTableOrViewNullable(tableName);
        if (null == tableMetadata)
            throw ire("Table '%s.%s' doesn't exist", keyspaceName, tableName);

        if (tableMetadata.kind != REGULAR)
            throw ire("Cannot set %s on non-regular table '%s.%s'",descriptionType.value, keyspaceName, tableName);

        return tableMetadata;
    }

View on GitHub (pinned to 88fd0f6a0e)

Solutions

  1. Verify the keyspace exists: SELECT keyspace_name FROM system_schema.keyspaces;
  2. Correct the keyspace name in the statement or USE clause
  3. Connect to the intended cluster/environment before running DDL inspection

Example fix

// before
DESCRIBE KEYSPACE ksmetrics;   // typo
// after
DESCRIBE KEYSPACE ks_metrics;
Defensive patterns

Strategy: validation

Validate before calling

var exists = session.execute("SELECT keyspace_name FROM system_schema.keyspaces WHERE keyspace_name=?", ks).iterator().hasNext();
if (!exists) throw new IllegalArgumentException("Keyspace " + ks + " does not exist");

Try / catch

try { runDescription(); } catch (InvalidRequest e) { if (e.getMessage().startsWith("Keyspace") && e.getMessage().contains("doesn't exist")) promptForCorrectKeyspace(); else throw e; }

Prevention

When it happens

Trigger: 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.

Common situations: Typos; connecting to the wrong cluster/environment; quoting keyspace names with different case; scripts assuming a keyspace exists after migration.

Understand the failure class

Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.

Related errors


AI-assisted analysis of apache/cassandra@88fd0f6a0e (2026-09-10). Data as JSON: /api/errors/a745a230e8c99202. Report an issue: GitHub.