You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add new and severity based constructors to BevyError (#23684)
# Objective
Add constructors for making `BevyError`s with a specific severity.
Closes#23676.
## Solution
Add a `new` constructor plus 1 constructor for every possible
`Severity`.
## Testing
My eyes and a simple test case that constructs an error and tests if the
downcasting works.
---
## Showcase
A `BevyError` now has multiple constructor to create one with an
expected severity
```rust
use bevy::ecs::error::{BevyError, Severity};
let debug_error = BevyError::new(Severity::Debug, "This works with strings");
let warn_error = BevyError::warn("There's a constructor for each severity level");
```
---------
Co-authored-by: Alice Cecile <alice.i.cecile@gmail.com>
Co-authored-by: Ben Frankel <ben.frankel7@gmail.com>
let full_backtrace = std::env::var("BEVY_BACKTRACE").is_ok_and(|val| val == "full");
69
176
70
177
let backtrace_str = alloc::string::ToString::to_string(backtrace);
@@ -268,6 +375,7 @@ pub fn bevy_error_panic_hook(
268
375
269
376
#[cfg(test)]
270
377
mod tests {
378
+
usecrate::error::BevyError;
271
379
272
380
#[test]
273
381
#[cfg(not(miri))]// miri backtraces are weird
@@ -278,11 +386,11 @@ mod tests {
278
386
Ok(())
279
387
}
280
388
281
-
// SAFETY: this is not safe ... this test could run in parallel with another test
282
-
// that writes the environment variable. We either accept that so we can write this test,
283
-
// or we don't.
389
+
let capture_backtrace = std::env::var_os("RUST_BACKTRACE");
284
390
285
-
unsafe{ std::env::set_var("RUST_BACKTRACE","1")};
391
+
if capture_backtrace.is_none() || capture_backtrace.clone().is_some_and(|s| s == "0"){
392
+
panic!("This test only works if rust backtraces are enabled. Value set was {capture_backtrace:?}. Please set RUST_BACKTRACE to any value other than 0 and run again.")
0 commit comments