Skip to content

Add bevy_error! and bail! macros to BevyError#23720

Open
loreball wants to merge 1 commit intobevyengine:mainfrom
loreball:bevy_error_actual_macros
Open

Add bevy_error! and bail! macros to BevyError#23720
loreball wants to merge 1 commit intobevyengine:mainfrom
loreball:bevy_error_actual_macros

Conversation

@loreball
Copy link
Copy Markdown
Contributor

@loreball loreball commented Apr 8, 2026

Objective

These macros were originally part of #23684 but were removed to help the pr cross the finish line.

Solution

Reintroduce and discuss them here.

Testing

2 testcases to prove the expanded code compiles.


bevy_ecs has been expanded with 2 macros to simplify creation of BevyErrors.

// Now instead of this.
let error = BevyError::new(Severity::Panic, "hello error");
// You can do this. It even support `format!` syntax
let error = bevy_error!("{} bottles of beer on the wall.", 99);

// Quickly return from a fallible system using bail.
bail!("{} bottles of beer.", 99);
// Expands to something like this
return Err(BevyError::panic("Take on down, pass it around,");

// You can even specify the severity by passing it in as the first argument
bevy_error!(Severity::Debug, "{} bottles of beer on the wall.", 98);

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 8, 2026

Your PR caused a change in the graphical output of an example or rendering test. This might be intentional, but it could also mean that something broke!
You can review it at https://pixel-eagle.com/project/B04F67C0-C054-4A6F-92EC-F599FEC2FD1D?filter=PR-23720

If it's expected, please add the M-Deliberate-Rendering-Change label.

If this change seems unrelated to your PR, you can consider updating your PR to target the latest main branch, either by rebasing or merging main into it.

@loreball
Copy link
Copy Markdown
Contributor Author

loreball commented Apr 8, 2026

I have no idea how this code could change the rendering. I'm guessing it's a false alarm since image upload failed. It's that or a miscompilation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants