{"record":{"id":"2b5d70641d2a6688","repo":"bevyengine/bevy","slug":"expected-before-to-exist-2b5d70","errorCode":null,"errorMessage":"Expected {before:?} to exist","messagePattern":"Expected (.+?) to exist","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/bevy_render/src/lib.rs","lineNumber":312,"sourceCode":"\nimpl RenderScheduleOrder {\n    /// Adds the given `schedule` after the `after` schedule\n    pub fn insert_after(&mut self, after: impl ScheduleLabel, schedule: impl ScheduleLabel) {\n        let index = self\n            .labels\n            .iter()\n            .position(|current| (**current).eq(&after))\n            .unwrap_or_else(|| panic!(\"Expected {after:?} to exist\"));\n        self.labels.insert(index + 1, schedule.intern());\n    }\n\n    /// Adds the given `schedule` before the `before` schedule\n    pub fn insert_before(&mut self, before: impl ScheduleLabel, schedule: impl ScheduleLabel) {\n        let index = self\n            .labels\n            .iter()\n            .position(|current| (**current).eq(&before))\n            .unwrap_or_else(|| panic!(\"Expected {before:?} to exist\"));\n        self.labels.insert(index, schedule.intern());\n    }\n}\n\n/// The main render schedule.\n///\n/// See also [`RenderGraph`] for more details.\n#[derive(ScheduleLabel, Debug, Hash, PartialEq, Eq, Clone, Default)]\npub struct Render;\n\nimpl Render {\n    /// Sets up the base structure of the rendering [`Schedule`].\n    ///\n    /// The sets defined in this enum are configured to run in order.\n    pub fn base_schedule() -> Schedule {\n        use RenderSystems::*;\n\n        let mut schedule = Schedule::new(Self);","sourceCodeStart":294,"sourceCodeEnd":330,"githubUrl":"https://github.com/bevyengine/bevy/blob/396ca727080776bd313bb892423b7d94e03b81b4/crates/bevy_render/src/lib.rs#L294-L330","documentation":"Mirror of `insert_after` on `RenderScheduleOrder`: `insert_before(before, schedule)` panics with \"Expected {before:?} to exist\" when the anchor label is absent from the ordered label list, because a relative insertion position cannot be computed.","triggerScenarios":"Calling `render_schedule_order.insert_before(MySchedule, NewSchedule)` when `MySchedule` is not among `order.labels` — never inserted, removed, or a different/renamed label type.","commonSituations":"Plugin ordering code assuming another plugin's schedule exists; enabling a plugin conditionally while another unconditionally inserts relative to it.","solutions":["Insert relative to an always-present label such as `Render` or `First`","Verify membership in `order.labels` before calling insert_before","Register the anchor schedule (or use explicit ordering constraints) instead of assuming presence"],"exampleFix":"// before\norder.insert_before(MyCustomSchedule, MyNewSchedule); // MyCustomSchedule not inserted yet\n\n// after\norder.insert_before(Render, MyNewSchedule); // or insert MyCustomSchedule first","handlingStrategy":"validation","validationCode":"let exists = order.labels.iter().any(|l| (**l).eq(&MySchedule));\nif exists {\n    order.insert_before(MySchedule, MyNewSchedule);\n} else {\n    order.insert_before(Render, MyNewSchedule); // safe anchor\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Anchor insert_before calls to always-present labels like Render","Register the anchor schedule before ordering relative to it","Watch plugin enable/disable order when schedules are inserted conditionally"],"tags":["bevy","render","schedule","ordering","panic"],"backgroundTag":"schedule-label-not-found","analyzedSha":"396ca727080776bd313bb892423b7d94e03b81b4","analyzedAt":"2026-08-20T16:12:39.808Z","contentChangedAt":"2026-08-20T16:12:39.808Z","schemaVersion":2},"datasetVersion":"2026-09-09T01:17:15.007Z"}