{"record":{"id":"03b6a064423d3b1c","repo":"tracel-ai/burn","slug":"cannot-add-single-item-when-attributes-are-set","errorCode":null,"errorMessage":"Cannot add single item when attributes are set.","messagePattern":"Cannot add single item when attributes are set\\.","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/burn-core/src/module/display.rs","lineNumber":469,"sourceCode":"            name: name.to_owned(),\n            value: DisplayAdapter(value).format(self.display_settings.clone()),\n            ty: any::type_name::<T>().to_string(),\n        });\n        self\n    }\n\n    /// Adds a single item.\n    ///\n    /// # Arguments\n    ///\n    /// * `value` - Rendered string of the single item.\n    ///\n    /// # Returns\n    ///\n    /// Updated `Content` instance with the single item added.\n    pub fn add_single<T: ModuleDisplay + ?Sized>(mut self, value: &T) -> Self {\n        if !self.attributes.is_empty() {\n            panic!(\"Cannot add single item when attributes are set.\");\n        }\n\n        self.single_item = Some(value.format(self.display_settings.clone()));\n\n        self\n    }\n\n    /// Adds a single item.\n    ///\n    /// # Arguments\n    ///\n    /// * `value` - Formatted display value.\n    ///\n    /// # Returns\n    ///\n    /// Updated `Content` instance with the formatted single item added.\n    pub fn add_formatted<T: Display>(mut self, value: &T) -> Self {\n        if !self.attributes.is_empty() {","sourceCodeStart":451,"sourceCodeEnd":487,"githubUrl":"https://github.com/tracel-ai/burn/blob/d16f7ba2ed0d41408189384044cc886fb4c8f957/crates/burn-core/src/module/display.rs#L451-L487","documentation":"Mirror guard of the `add`-side check: `add_single` panics when named attributes were already added via `add`, because a Content serializes either a named-attribute list or one single item. The panic reports a caller bug in composing display content for a module, not a runtime data problem.","triggerScenarios":"Thrown at crates/burn-core/src/module/display.rs:469 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Call `add_single` on a fresh Content before any `add` calls, or drop the `add` calls if a single item is intended.","Convert the single item into a named attribute (`add(\"item\", value)`) when both kinds of content are needed.","Separate the content into two Content instances with different display roles."],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"d16f7ba2ed0d41408189384044cc886fb4c8f957","analyzedAt":"2026-09-05T13:19:14.260Z","contentChangedAt":"2026-09-05T13:19:14.260Z","schemaVersion":2},"datasetVersion":"2026-09-12T17:17:11.597Z"}