t8y2/dbx · error

TDengine database is required

Error message

TDengine database is required

What it means

effective_database resolves which TDengine database an operation targets: it prefers the explicitly requested name, otherwise falls back to the connection's current database. If both are empty, there is no database context and the driver errors, because list_tables/list_objects/get_columns/get_object_source/get_create_sql all need a database scope.

Source

Thrown at agents/drivers/tdengine/src/driver.rs:823

                .await
                .map_err(|_| anyhow!("TDengine operation timed out after {timeout_secs} seconds"))?
                .map_err(anyhow::Error::from)
        }
    };
    tokio::select! {
        _ = token.cancelled() => bail!("TDengine operation was cancelled"),
        result = operation => result,
    }
}

fn effective_database<'a>(requested: &'a str, current: &'a str) -> Result<&'a str> {
    let requested = requested.trim();
    if !requested.is_empty() {
        return validate_database_name(requested);
    }
    let current = current.trim();
    if current.is_empty() {
        bail!("TDengine database is required");
    }
    validate_database_name(current)
}

fn validate_database_name(value: &str) -> Result<&str> {
    let value = value.trim();
    let mut chars = value.chars();
    let valid_start = chars.next().is_some_and(|char| char == '_' || char.is_ascii_alphabetic());
    if !valid_start || !chars.all(|char| char == '_' || char.is_ascii_alphanumeric()) {
        bail!("invalid TDengine database name: {value}");
    }
    Ok(value)
}

fn table_from_show_row(row: Vec<Value>, table_type: &str, includes_stable_name: bool) -> Option<TableInfo> {
    let name = row.first().and_then(json_text)?.to_string();
    let parent_name = includes_stable_name
        .then(|| row.get(3).and_then(json_text).map(str::trim).filter(|value| !value.is_empty()).map(str::to_string))

View on GitHub (pinned to c0390bff16)

Solutions

  1. Call use_database on the connection first, or pass the database name explicitly to the metadata API
  2. Specify a default database in the connection params when connecting
  3. Verify the requested name passes validate_database_name (no stray whitespace/invalid characters)

Example fix

// before
driver.list_tables(&conn, "", ...).await?; // no current db
// after
driver.use_database(&conn, "metrics", ...).await?;
driver.list_tables(&conn, "metrics", ...).await?;
Defensive patterns

Strategy: validation

Validate before calling

anyhow::ensure!(!db.trim().is_empty() || !current_db.trim().is_empty(), "TDengine database is required");

Type guard

fn resolves_database(requested: &str, current: &str) -> bool {
    !requested.trim().is_empty() || !current.trim().is_empty()
}

Prevention

When it happens

Trigger: Calling list_tables, list_objects, get_columns, get_object_source, or get_create_sql with an empty requested database on a connection that never had use_database called (or was created without a default database).

Common situations: Connecting to a TDengine server without specifying a default database, then browsing tables/metadata; or passing an empty string instead of a database name.

Understand the failure class

Background: Missing required parameter errors: what 'X is required' and 'the required X param is missing' mean, and how to fix them — this error's family across 27 libraries.

Related errors


AI-assisted analysis of t8y2/dbx@c0390bff16 (2026-09-05). Data as JSON: /api/errors/87417ecace5626e9. Report an issue: GitHub.