bottlerocket-os/bottlerocket · error · datastore::Error
KeyTooLongSnafu
KeyTooLongSnafu
Error message
Key name beyond maximum length {name}: {max} What it means
Key names are capped at MAX_KEY_NAME_LENGTH characters; `check_key` rejects any name longer than this during key construction. Long names would overflow filesystem filename limits or internal buffers downstream.
Solutions
- Shorten the key name before constructing the Key (hash or truncate long identifier portions)
- Increase MAX_KEY_NAME_LENGTH if the deployment's filesystem supports longer names (and verify downstream consumers)
- Split overly hierarchical keys into fewer segments
Example fix
// before
let key = Key::from_string(format!("{}.{}.{}", tenant, device, raw_blob_id))?;
// after
let short_id = sha256_hex(raw_blob_id.as_bytes())[..32].to_string();
let key = Key::from_string(format!("{}.{}.{}", tenant, device, short_id))?; Defensive patterns
Strategy: validation
Validate before calling
name.len() <= MAX_KEY_NAME_LENGTH
Prevention
- Hash long identifiers
When it happens
Trigger: Creating a Key (via parse/constructor paths that call check_key) whose name exceeds MAX_KEY_NAME_LENGTH — e.g. deeply nested dotted segments or a very long single segment from user/device IDs.
Common situations: Building keys by concatenating tenant + device + timestamp identifiers without checking length; importing legacy data with unrestricted key sizes.
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 bottlerocket-os/bottlerocket@0be31b34d2 (2026-09-10).
Data as JSON: /api/errors/91a57d3fd0b2d5f3.
Report an issue: GitHub.
Appendix: source
Thrown at sources/api/datastore/src/key.rs:200
///
/// Fails if the new key would be invalid, e.g. too long.
pub(super) fn append_key(&self, key: &Key) -> Result<Self> {
let our_segments = self.segments().iter();
let their_segments = key.segments().iter();
let new_segments: Vec<_> = our_segments.chain(their_segments).collect();
Self::from_segments(KeyType::Data, &new_segments)
}
/// Additional safety checks for parsed or generated keys.
fn check_key<S1, S2>(key_type: KeyType, name: S1, segments: &[S2]) -> Result<()>
where
S1: AsRef<str>,
S2: AsRef<str>,
{
let name = name.as_ref();
ensure!(
name.len() <= MAX_KEY_NAME_LENGTH,
error::KeyTooLongSnafu {
name,
max: MAX_KEY_NAME_LENGTH,
}
);
match key_type {
KeyType::Data => {
ensure!(
!segments.is_empty(),
error::InvalidKeySnafu {
name,
msg: "data keys must have at least one segment",
}
);
}
KeyType::Meta => {View on GitHub (pinned to 0be31b34d2)