{"record":{"id":"0be54f196e6940e8","repo":"bevyengine/bevy","slug":"zero-is-not-a-valid-grid-position","errorCode":null,"errorMessage":"Zero is not a valid grid position","messagePattern":"Zero is not a valid grid position","errorType":"exception","errorClass":"GridPlacementError","httpStatus":null,"severity":"error","filePath":"crates/bevy_ui/src/ui_node.rs","lineNumber":2250,"sourceCode":"        Self {\n            repetition: GridTrackRepetition::Count(repetition),\n            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>,","sourceCodeStart":2232,"sourceCodeEnd":2268,"githubUrl":"https://github.com/bevyengine/bevy/blob/a62cce8c05ceacd3bd102e678c83e2b42e5dfbe2/crates/bevy_ui/src/ui_node.rs#L2232-L2268","documentation":"GridPlacementError::InvalidZeroIndex is the thiserror variant behind every zero-line panic in GridPlacement: the internal try_into_grid_index helper returns it when an i16 grid line of 0 fails NonZero::new. In the public API the constructors/setters immediately .expect() this error away (panicking with 'Invalid start/end value of 0.'), so the Display text 'Zero is not a valid grid position' surfaces whenever the error itself is formatted or propagated — for example in user-written fallible wrappers that match on GridPlacementError, reflection tooling, or logging that reports the cause.","triggerScenarios":"Passing 0 as start or end to any GridPlacement constructor/setter (which converts this error into the corresponding panic); calling the conversion helpers from code copied into your crate; formatting or matching a GridPlacementError::InvalidZeroIndex produced by a fallible wrapper around GridPlacement.","commonSituations":"Writing a validate-placement layer that returns Result<GridPlacement, GridPlacementError>; upgrading Bevy versions where placement validation moved from ad-hoc checks to this enum; error reporting pipelines that Display the underlying cause chain of a layout failure.","solutions":["Never pass 0 as a grid line: use 1-based positive lines or negative lines counted from the end.","In fallible wrappers, match GridPlacementError::InvalidZeroIndex and map it to an automatic/None placement instead of propagating.","When reporting, include the field name (start vs end) so callers know which argument was 0.","Use GridPlacement::auto()/start()/end() variants that leave the offending line unset when the value is unknown."],"exampleFix":"// before\nfn place(start: i16) -> Result<GridPlacement, GridPlacementError> {\n    Ok(GridPlacement::start(start)) // panics on 0 before the Result can help\n}\n\n// after\nfn place(start: i16) -> Result<GridPlacement, GridPlacementError> {\n    if start == 0 { return Err(GridPlacementError::InvalidZeroIndex); }\n    Ok(GridPlacement::start(start))\n}","handlingStrategy":"validation","validationCode":"use std::num::NonZero;\n\n// gate every line before it reaches a GridPlacement API\nfn checked_line(line: i16) -> Result<NonZero<i16>, GridPlacementError> {\n    NonZero::new(line).ok_or(GridPlacementError::InvalidZeroIndex)\n}","typeGuard":"fn is_valid_grid_line(line: i16) -> bool { line != 0 }","tryCatchPattern":"// in fallible wrappers, match the enum and degrade to automatic placement\nmatch checked_line(line) {\n    Ok(line) => Ok(GridPlacement::start(line.get())),\n    Err(e @ GridPlacementError::InvalidZeroIndex) => {\n        warn!(\"{e}\");\n        Ok(GridPlacement::auto())\n    }\n    Err(e) => Err(e),\n}","preventionTips":["Normalize domain indices to NonZero<i16> as soon as they enter layout code.","Keep a single index-to-grid-line conversion (+1) helper shared by all call sites.","Report which field (start/end) failed when surfacing this error upstream."],"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"}