tracel-ai/burn · error
Cannot add multiple attributes when single item is set.
Error message
Cannot add multiple attributes when single item is set.
What it means
Builder-state invariant violation in the module display system: a `Content` can hold either named attributes (added via `add`) or a single unnamed item (via `add_single`), but not both. This panic fires from `add` when `add_single` was already called on the same builder, i.e. the caller mixed the two mutually exclusive construction styles.
Source
Thrown at crates/burn-core/src/module/display.rs:422
single_item: None,
display_settings,
top_level_type: None,
}
}
/// Adds an attribute to the format settings. The value will be formatted and stored as a string.
///
/// # Arguments
///
/// * `name` - Name of the attribute.
/// * `value` - Value of the attribute.
///
/// # Returns
///
/// Updated `Content` instance with the new attribute added.
pub fn add<T: ModuleDisplay + ?Sized>(mut self, name: &str, value: &T) -> Self {
if self.single_item.is_some() {
panic!("Cannot add multiple attributes when single item is set.");
}
let attribute = Attribute {
name: name.to_owned(),
value: value.format(self.display_settings.clone()), // TODO level + 1
ty: any::type_name::<T>().to_string(),
};
self.attributes.push(attribute);
self
}
/// Adds an attribute using its `Debug` representation.
///
/// This is intended for fields that do not implement [`ModuleDisplay`].
///
/// # Arguments
///
/// * `name` - Name of the attribute.View on GitHub (pinned to d16f7ba2ed)
Solutions
- Build the Content either with `add` for all named attributes or with `add_single` for the one rendered item, never both.
- Create a fresh `Content` builder for the single-item case instead of reusing one that already had `add_single` called.
- Refactor `custom_content` so each content block has one consistent construction path.
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at crates/burn-core/src/module/display.rs:422 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of tracel-ai/burn@d16f7ba2ed (2026-09-05).
Data as JSON: /api/errors/3ba16f08e4fc88d4.
Report an issue: GitHub.