Skip to content

Pass command panics to the fallback error handler#24911

Merged
alice-i-cecile merged 12 commits into
bevyengine:mainfrom
chescock:command-panics
Jul 14, 2026
Merged

Pass command panics to the fallback error handler#24911
alice-i-cecile merged 12 commits into
bevyengine:mainfrom
chescock:command-panics

Conversation

@chescock

@chescock chescock commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

Objective

Improve the handling of commands that panic.

Currently, if a command panics, any unapplied commands are left in the command queue. This means they will get run, but at an unpredictable time in the future.

And when running in no_std, cleanup is not run at all and the commands simply leak.

Solution

Catch panics from commands and pass them to the fallback error handler, just as we now do for systems from #24240. This means if the error handler is set to something non-panicking like warn, then flush_commands() will never panic and all commands in the queue will be applied.

Introduce a RAII guard during command application that will drop any commands still in the queue and perform cleanup during unwinding, even on no_std.

To make the command's type name available in the error handler, add a field to the RAII guard that gets written by consume_command_and_get_size before applying the command.

@chescock chescock added A-ECS Entities, components, systems, and events S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Jul 7, 2026
@github-project-automation github-project-automation Bot moved this to Needs SME Triage in ECS Jul 7, 2026

@SpecificProtagonist SpecificProtagonist left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great; recovering as early as possible when the fallback error handler is set to swallow the panic is the right thing to do.

Comment thread crates/bevy_ecs/src/world/command_queue.rs Outdated
Comment thread crates/bevy_ecs/src/world/command_queue.rs Outdated
Comment thread crates/bevy_ecs/src/world/command_queue.rs Outdated
chescock added 3 commits July 7, 2026 17:53
This reverts commit ae39893.

Revert "Expose the type name for type-erased commands."

This reverts commit 25ecdc7.

@urben1680 urben1680 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR just moves some code, I just kinda squinted on these parts and did not check too attentive that these not have changed.

I would only like one more test to be added.

runner.local_cursor += size_of::<C>();
#[cfg(all(feature = "debug", feature = "std"))]
{
runner.current_command_name = core::any::type_name::<C>();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I kinda wish DebugName worked like MaybeLocation where it is generic with a good default type but you could change it, like to &'static str in this case.

Comment thread crates/bevy_ecs/src/world/command_queue.rs Outdated
chescock added 4 commits July 11, 2026 09:08
…unt of code generated."

This reverts commit e674899.

Revert "Provide the command's type name to the error context by writing to a field in the `CommandRunner`."

This reverts commit 1a653b4.
…ble,

but move all the handling code into a `#[cold]` function so that it is not monomorphized.
Comment thread crates/bevy_ecs/src/world/command_queue.rs
@chescock chescock added S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it and removed S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Jul 12, 2026
@alice-i-cecile
alice-i-cecile added this pull request to the merge queue Jul 14, 2026
Merged via the queue into bevyengine:main with commit 3ac3096 Jul 14, 2026
40 checks passed
@github-project-automation github-project-automation Bot moved this from Needs SME Triage to Done in ECS Jul 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-ECS Entities, components, systems, and events S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

4 participants