influxdata/influxdb · error · DatabaseNameError

database name ' ' contains invalid character, character…

Error message

database name '{}' contains invalid character, character number {} is not allowed

What it means

DatabaseNameError::BadChars is thrown when a database name contains a character that is not allowed. The error reports the offending offset (character number) within the name so the caller can locate the invalid character. Database names are restricted to a safe identifier alphabet (letters, digits, and a few punctuation characters).

Solutions

  1. Remove or replace the character at the reported offset with an allowed one (e.g. '-' or '_')
  2. Sanitize the name with a regex whitelist before validation
  3. If names come from user input, validate/normalize them at the boundary before creating the database

Example fix

// before
let db = DatabaseName::parse("my db/v2")?; // space and '/' invalid
// after
let sanitized: String = raw.chars().map(|c| if c.is_ascii_alphanumeric() { c } else { '_' }).collect();
let db = DatabaseName::parse(&sanitized)?;
Defensive patterns

Strategy: validation

Validate before calling

fn sanitize_name(raw: &str) -> String {
    raw.chars().map(|c| if c.is_ascii_alphanumeric() || c == '-' || c == '_' { c } else { '_' }).collect()
}

Type guard

fn has_only_allowed_chars(name: &str) -> bool {
    name.chars().all(|c| c.is_ascii_alphanumeric() || c == '-' || c == '_')
}

Prevention

When it happens

Trigger: Calling database name validation (DatabaseName::parse / from_str) with names containing characters outside the allowed set, e.g. spaces, slashes, dots in a disallowed position, or unicode characters; the invalid character is at position bad_char_offset.

Common situations: Deriving names from URLs or file paths (containing '/'), from user input with spaces, from hostnames with underscores in disallowed spots, or passing UUIDs with hyphens when only certain punctuation is permitted.

Understand the failure class

Background: "invalid id" errors: invalid identifier format — why libraries reject IDs before lookup, and how to fix them — this error's family across 37 libraries.

Related errors


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

Appendix: source

Thrown at influxdb3_types/src/database_name.rs:66

/// [`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 {
        /// The zero-indexed (multi-byte) character position that failed
        /// validation.
        bad_char_offset: usize,
        /// The user-provided database that failed validation.
        name: TruncatedString,
    },
}

/// A correctly formed database name.
///
/// Using this wrapper type allows the consuming code to enforce the invariant
/// that only valid names are provided.

View on GitHub (pinned to 06200ef96b)