Skip to content

handle panics in required component constructors#20933

Draft
janis-bhm wants to merge 4 commits intobevyengine:mainfrom
janis-bhm:panic-required-components
Draft

handle panics in required component constructors#20933
janis-bhm wants to merge 4 commits intobevyengine:mainfrom
janis-bhm:panic-required-components

Conversation

@janis-bhm
Copy link
Copy Markdown
Contributor

@janis-bhm janis-bhm commented Sep 8, 2025

Objective

fix #20368

Solution

catch panics in required component constructors, then move archetypes if necessary.
this is a PoC kind of PR because I want to know if this is even the right approach to the issue.

Testing

skifire's example works for inserting components and passes miri. still need to fix spawn_non_existent and consider hooks/observers, clean up code, double check safety.

@janis-bhm janis-bhm changed the title Panic required components handle panics in required component constructors Sep 8, 2025
@james7132 james7132 self-requested a review September 8, 2025 18:35
@alice-i-cecile alice-i-cecile added C-Bug An unexpected or incorrect behavior A-ECS Entities, components, systems, and events X-Contentious There are nontrivial implications that should be thought through S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Sep 8, 2025
@SpecificProtagonist
Copy link
Copy Markdown
Contributor

The approach of the resulting entity containing all components except the ones that panicked seems correct to me. That said, the bundle insertion should then re-throw the panic or call the default error handler instead of silently swallowing the error.

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 C-Bug An unexpected or incorrect behavior S-Needs-Review Needs reviewer attention (from anyone!) to move forward X-Contentious There are nontrivial implications that should be thought through

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Inserting components is not panic-safe

3 participants