influxdata/influxdb · error · DatabaseNameError

database name length must be between and characters

Error message

database name {} length must be between {} and {} characters

What it means

DatabaseNameError::LengthConstraint is thrown by influxdb3_types::database_name validation when a database name is shorter than LENGTH_CONSTRAINT.start() or longer than LENGTH_CONSTRAINT.end(). The error carries the rejected name (as TruncatedString) and formats the allowed min/max bounds from the constraint range. It enforces the documented size limit for InfluxDB 3 database identifiers.

Solutions

  1. Shorten or lengthen the database name so its character count is within the allowed range reported in the message
  2. Trim whitespace/empty prefixes and check the name is non-empty before calling the API
  3. Generate a shorter unique name (hash or prefix truncation) for programmatic names

Example fix

// before
let db = DatabaseName::parse("")?; // too short
// after
let name = if raw.is_empty() { "default" } else { raw.as_str() };
let db = DatabaseName::parse(name)?;
Defensive patterns

Strategy: validation

Validate before calling

fn valid_db_name_len(name: &str) -> bool {
    let n = name.chars().count();
    (MIN..=MAX).contains(&n) // use the bounds from LENGTH_CONSTRAINT
}

Type guard

fn is_valid_db_name(name: &str) -> bool {
    !name.is_empty() && name.chars().count() >= 1 && name.chars().count() <= 255
}

Prevention

When it happens

Trigger: Calling any API that validates a database name (e.g. DatabaseName::parse / from_str) with a name whose character count falls outside LENGTH_CONSTRAINT, such as an empty or 1-char name or a very long name.

Common situations: Auto-generating database names from user input or hostnames, template substitutions producing empty names, truncation/concatenation logic exceeding the max length, defaults not set so an empty string is passed.

Understand the failure class

Background: "value must be between 0 and 1" / "out of range" / "must not be negative" errors: fixing range-validation failures across open-source libraries — this error's family across 42 libraries.

Related errors


AI-assisted analysis of influxdata/influxdb@06200ef96b (2026-09-19). Data as JSON: /api/errors/445944adbbdd293e. Report an issue: GitHub.

Appendix: source

Thrown at influxdb3_types/src/database_name.rs:54

}

impl Display for TruncatedString {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        write!(f, "{}", self.inner())
    }
}

/// Allowlist of chars for a [`DatabaseName`].
fn is_allowed(c: char) -> bool {
    c.is_alphanumeric() || matches!(c, '/' | '_' | '-')
}

/// [`DatabaseName`] name validation errors.
#[derive(Debug, Error)]
pub enum DatabaseNameError {
    /// The provided database name does not fall within the valid length of a
    /// database.
    #[error(
        "database name {} length must be between {} and {} characters",
        name,
        LENGTH_CONSTRAINT.start(),
        LENGTH_CONSTRAINT.end()
    )]
    LengthConstraint {
        /// The user-provided database that failed validation.
        name: TruncatedString,
    },

    /// The provided database name contains an unacceptable character.
    #[error(
        "database name '{}' contains invalid character, character number {} \
        is not allowed",
        name,
        bad_char_offset
    )]
    BadChars {

View on GitHub (pinned to 06200ef96b)