{"record":{"id":"ca26dc0ac8a967c2","repo":"influxdata/influxdb","slug":"namespace-name-contains-invalid-character-character-number","errorCode":null,"errorMessage":"namespace name '{}' contains invalid character, character number {} is not allowed","messagePattern":"namespace name '(.+?)' contains invalid character, character number (.+?) is not allowed","errorType":"validation","errorClass":"NamespaceNameError","httpStatus":null,"severity":"error","filePath":"core/data_types/src/namespace_name.rs","lineNumber":48,"sourceCode":"\n/// [`NamespaceName`] name validation errors.\n#[derive(Debug, Error)]\npub enum NamespaceNameError {\n    /// The provided namespace name does not fall within the valid length of a\n    /// namespace.\n    #[error(\n        \"namespace name {} length must be between {} and {} characters\",\n        name,\n        LENGTH_CONSTRAINT.start(),\n        LENGTH_CONSTRAINT.end()\n    )]\n    LengthConstraint {\n        /// The user-provided namespace that failed validation.\n        name: String,\n    },\n\n    /// The provided namespace name contains an unacceptable character.\n    #[error(\n        \"namespace name '{}' contains invalid character, character number {} \\\n        is not allowed\",\n        name,\n        bad_char_offset\n    )]\n    BadChars {\n        /// The zero-indexed (multi-byte) character position that failed\n        /// validation.\n        bad_char_offset: usize,\n        /// The user-provided namespace that failed validation.\n        name: String,\n    },\n}\n\n/// A correctly formed namespace name.\n///\n/// Using this wrapper type allows the consuming code to enforce the invariant\n/// that only valid names are provided.","sourceCodeStart":30,"sourceCodeEnd":66,"githubUrl":"https://github.com/influxdata/influxdb/blob/06200ef96ba82c5f6727e5038a83af8e722c6875/core/data_types/src/namespace_name.rs#L30-L66","documentation":"NamespaceNameError::BadChars is returned when a namespace name contains a character that is not permitted. The message names the offending name and the byte/character offset (bad_char_offset) of the first disallowed character. The library validates the character set to keep namespace names safe as identifiers and URL/path components.","triggerScenarios":"Calling NamespaceName::new (or try_from(&str)) with a name containing characters outside the allowed set, e.g. spaces, '/', ':', '!', or other punctuation; the offset points at the first such character.","commonSituations":"Users passing human-readable names like 'my database' or paths like 'prod/eu-west' as database names; copy-pasted names with trailing whitespace or unicode characters; v1 write paths mapping bucket names with slashes.","solutions":["Use the reported character offset to locate and remove/replace the invalid character.","Restrict names to the allowed set (typically alphanumeric, '-', '_').","Sanitize user-supplied names with a filter that strips or transliterates disallowed characters before constructing the namespace.","If the original name must be preserved, store it elsewhere and use a sanitized, valid namespace name."],"exampleFix":"// before\nlet ns = NamespaceName::new(\"my database\")?; // invalid space at offset 2\n// after\nlet ns = NamespaceName::new(\"my-database\")?;","handlingStrategy":"validation","validationCode":"fn sanitize_namespace_name(s: &str) -> String {\n    s.chars()\n        .map(|c| if c.is_ascii_alphanumeric() || c == '-' || c == '_' { c } else { '-' })\n        .collect()\n}","typeGuard":null,"tryCatchPattern":"match NamespaceName::new(user_name) {\n    Ok(ns) => use(ns),\n    Err(NamespaceNameError::BadChars { name, bad_char_offset }) => {\n        log::error!(\"invalid char at offset {bad_char_offset} in '{name}'\");\n        NamespaceName::new(&sanitize_namespace_name(user_name))\n    }\n    Err(e) => return Err(e.into()),\n}","preventionTips":["Sanitize or slugify all user-provided names before namespace creation.","Reject names with spaces, slashes, or unicode at input boundaries.","Keep an allowlist regex (e.g. ^[A-Za-z0-9_-]+$) and test it in CI."],"tags":["rust","validation","invalid-characters","influxdb"],"backgroundTag":"invalid-identifier-format","analyzedSha":"06200ef96ba82c5f6727e5038a83af8e722c6875","analyzedAt":"2026-09-19T12:55:30.003Z","contentChangedAt":"2026-09-19T12:55:30.003Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}