{"record":{"id":"640dd5a49b70c994","repo":"tracel-ai/burn","slug":"window-size-must-be-non-zero","errorCode":null,"errorMessage":"window size must be non-zero","messagePattern":"window size must be non-zero","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/burn-dataset/src/transform/window.rs","lineNumber":56,"sourceCode":"    /// Panics if `size` is 0.    \n    ///\n    /// # Examples\n    ///\n    /// ```\n    /// use crate::burn_dataset::{\n    ///    transform::{Windows, WindowsDataset},\n    ///    Dataset, InMemDataset,\n    /// };\n    ///\n    /// let items = [1, 2, 3, 4].to_vec();\n    /// let dataset = InMemDataset::new(items.clone());\n    ///\n    /// for window in dataset.windows(2) {\n    ///  // window is a Result<Vec<I>, DatasetError>\n    /// }\n    /// ```\n    fn windows(&self, size: usize) -> WindowsIterator<'_, I> {\n        let size = NonZeroUsize::new(size).expect(\"window size must be non-zero\");\n        WindowsIterator::new(self, size)\n    }\n}\n\n/// Overlapping windows iterator.\npub struct WindowsIterator<'a, I> {\n    /// The size of the windows.\n    pub size: NonZeroUsize,\n    current: usize,\n    len: usize,\n    dataset: &'a dyn Dataset<I>,\n}\n\nimpl<'a, I> WindowsIterator<'a, I> {\n    /// Creates a new `WindowsIterator` instance. The windows overlap.\n    /// Is empty if the input `Dataset` is shorter than `size`.\n    ///\n    /// # Parameters","sourceCodeStart":38,"sourceCodeEnd":74,"githubUrl":"https://github.com/tracel-ai/burn/blob/d16f7ba2ed0d41408189384044cc886fb4c8f957/crates/burn-dataset/src/transform/window.rs#L38-L74","documentation":"Dataset::windows(size) converts the requested window size into a NonZeroUsize and panics when size is 0, because zero-sized overlapping windows are mathematically undefined. The library enforces this eagerly at iterator construction rather than producing an empty iterator.","triggerScenarios":"Calling dataset.windows(0) on any implementor of the Dataset trait.","commonSituations":"Window size read from CLI/config defaulting to 0 before a value is set; computing size as len - k where k >= len; off-by-one in parameter parsing.","solutions":["Pass a window size >= 1; clamp with size.max(1) if the value is dynamic.","Validate configuration before constructing the dataset.","Use NonZeroUsize in your own config type so 0 is unrepresentable."],"exampleFix":"// before\nlet windows = dataset.windows(config.window_size);\n// after\nassert!(config.window_size > 0, \"window_size must be > 0\");\nlet windows = dataset.windows(config.window_size.max(1));","handlingStrategy":"validation","validationCode":"fn safe_windows<'a, I: Clone>(ds: &'a dyn Dataset<I>, size: usize) -> WindowsIterator<'a, I> {\n    assert!(size >= 1, \"window size must be >= 1, got {size}\");\n    ds.windows(size)\n}","typeGuard":"fn is_valid_window_size(size: usize) -> bool { size > 0 }","tryCatchPattern":null,"preventionTips":["Validate window_size at config load time","Use NonZeroUsize in your config types","Clamp computed sizes with .max(1)"],"tags":["rust","dataset","argument-validation","panic"],"backgroundTag":"must-be-non-zero","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"}