tracel-ai/burn · error

This should never be called since next_key_seed always retur

Error message

This should never be called since next_key_seed always returns None

What it means

This panic is a defensive invariant check, not a real deserialization path. The map access implementation in burn-store's nested de always returns None from next_key_seed, so next_value_seed should never be invoked; if it is, the runtime state is inconsistent and the code deliberately panics.

Source

Thrown at crates/burn-store/src/nested/de.rs:1008

        DefaultMapAccess
    }
}

impl<'de> MapAccess<'de> for DefaultMapAccess {
    type Error = Error;

    fn next_key_seed<T>(&mut self, _seed: T) -> Result<Option<T::Value>, Self::Error>
    where
        T: DeserializeSeed<'de>,
    {
        Ok(None)
    }

    fn next_value_seed<T>(&mut self, _seed: T) -> Result<T::Value, Self::Error>
    where
        T: DeserializeSeed<'de>,
    {
        unimplemented!("This should never be called since next_key_seed always returns None")
    }

    fn size_hint(&self) -> Option<usize> {
        None
    }
}

#[cfg(test)]
mod tests {
    use super::*;
    use crate::nested::adapter::DefaultAdapter;
    use serde::Deserialize;

    #[derive(Debug, Deserialize, PartialEq)]
    struct AllScalars {
        b: bool,
        i16_val: i16,
        i32_val: i32,

View on GitHub (pinned to d16f7ba2ed)

Solutions

  1. Fix the custom Deserialize/seed logic to stop when next_key_seed returns None
  2. Only call next_value_seed after next_key_seed returned Some
  3. Update burn-store to a version with corrected map access logic
  4. Report the mismatch if it comes from the library's own deserializer

Example fix

// before
while map.next_key_seed(k)? .is_some() || true {
    map.next_value_seed(v)?;
}

// after
while let Some(_) = map.next_key_seed(k)? {
    map.next_value_seed(v)?;
}
Defensive patterns

Strategy: try-catch

Try / catch

let r = std::panic::catch_unwind(|| T::deserialize(nested));
if r.is_err() {
    // invariant broken: check map-access loop stops at next_key_seed == None
    return Err(Error::MalformedNestedValue);
}

Prevention

When it happens

Trigger: A Deserialize implementation manually drives map access and calls next_value_seed after next_key_seed returned None, or an adapter bug causes value extraction without a key.

Common situations: Custom Deserialize/DeserializeSeed implementations that ignore next_key_seed's None and unconditionally call next_value_seed; rarely hit by end users directly.

Related errors


AI-assisted analysis of tracel-ai/burn@d16f7ba2ed (2026-09-05). Data as JSON: /api/errors/b82e600086703ba6. Report an issue: GitHub.