{"record":{"id":"048c959ddea2b0c2","repo":"bevyengine/bevy","slug":"spans-cannot-be-zero-length","errorCode":null,"errorMessage":"Spans cannot be zero length","messagePattern":"Spans cannot be zero length","errorType":"exception","errorClass":"GridPlacementError","httpStatus":null,"severity":"error","filePath":"crates/bevy_ui/src/ui_node.rs","lineNumber":2252,"sourceCode":"            tracks: SmallVec::from_buf([GridTrack::min_content()]),\n        }\n        .into()\n    }\n\n    /// Create a repeating set of grid tracks with max-content size\n    pub fn max_content<T: From<Self>>(repetition: u16) -> T {\n        Self {\n            repetition: GridTrackRepetition::Count(repetition),\n            tracks: SmallVec::from_buf([GridTrack::max_content()]),\n        }\n        .into()\n    }\n\n    /// Create a repeating set of `fit-content()` grid tracks with fixed pixel limit\n    pub fn fit_content_px<T: From<Self>>(repetition: u16, limit: f32) -> T {\n        Self {\n            repetition: GridTrackRepetition::Count(repetition),\n            tracks: SmallVec::from_buf([GridTrack::fit_content_px(limit)]),\n        }\n        .into()\n    }\n\n    /// Create a repeating set of `fit-content()` grid tracks with percentage limit\n    pub fn fit_content_percent<T: From<Self>>(repetition: u16, limit: f32) -> T {\n        Self {\n            repetition: GridTrackRepetition::Count(repetition),\n            tracks: SmallVec::from_buf([GridTrack::fit_content_percent(limit)]),\n        }\n        .into()\n    }\n\n    /// Create a repeating set of `minmax()` grid track\n    pub fn minmax<T: From<Self>>(\n        repetition: impl Into<GridTrackRepetition>,\n        min: MinTrackSizingFunction,\n        max: MaxTrackSizingFunction,","sourceCodeStart":2234,"sourceCodeEnd":2270,"githubUrl":"https://github.com/bevyengine/bevy/blob/a62cce8c05ceacd3bd102e678c83e2b42e5dfbe2/crates/bevy_ui/src/ui_node.rs#L2234-L2270","documentation":"GridPlacementError::InvalidZeroSpan is the thiserror variant produced by try_into_grid_span when a u16 span of 0 fails NonZero::new — 'Spans cannot be zero length'. The public constructors .expect() it (surfacing as the 'Invalid span value of 0.' panics), and the Display text appears when the error is propagated or formatted by fallible user code built on the enum.","triggerScenarios":"Passing span == 0 to GridPlacement::span/start_span/end_span or set_span (converted to a panic); handling or logging a GridPlacementError::InvalidZeroSpan returned from a fallible placement-validation layer.","commonSituations":"Defensive placement builders that return Result and need to distinguish bad spans from bad lines; data-validation pipelines reporting why a serialized layout was rejected; shared layout libraries reused across Bevy versions.","solutions":["Guarantee spans are >= 1 at the call site; one track is the minimum occupancy.","Map InvalidZeroSpan in fallible code to a default span of 1 (or reject the record with a precise message).","Skip creating the node when a computed span legitimately equals 0 rather than remapping silently.","Unit-test data sources (configs, save files) for zero spans before they reach GridPlacement."],"exampleFix":"// before\nfn item(span: u16) -> Result<GridPlacement, GridPlacementError> {\n    Ok(GridPlacement::span(span)) // panics on span == 0\n}\n\n// after\nfn item(span: u16) -> Result<GridPlacement, GridPlacementError> {\n    if span == 0 { return Err(GridPlacementError::InvalidZeroSpan); }\n    Ok(GridPlacement::span(span))\n}","handlingStrategy":"validation","validationCode":"use std::num::NonZero;\n\nfn checked_span(span: u16) -> Result<NonZero<u16>, GridPlacementError> {\n    NonZero::new(span).ok_or(GridPlacementError::InvalidZeroSpan)\n}","typeGuard":"fn is_valid_grid_span(span: u16) -> bool { span != 0 }","tryCatchPattern":"match checked_span(span) {\n    Ok(span) => Ok(GridPlacement::span(span.get())),\n    Err(e @ GridPlacementError::InvalidZeroSpan) => {\n        warn!(\"{e}\");\n        Ok(GridPlacement::auto()) // span defaults to 1\n    }\n    Err(e) => Err(e),\n}","preventionTips":["Store spans as NonZero<u16> in your own layout types so invalid states are unrepresentable.","Reject zero spans in serialized layout schemas with a precise message.","Add a property test asserting generated placements always have span >= 1."],"tags":["rust","bevy","bevy-ui","grid","error-enum","validation"],"backgroundTag":"grid-placement-zero-value","analyzedSha":"a62cce8c05ceacd3bd102e678c83e2b42e5dfbe2","analyzedAt":"2026-08-20T16:12:39.808Z","contentChangedAt":"2026-08-20T16:12:39.808Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}