-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
Description
What problem does this solve or what need does it fill?
As we've shifted towards error handling across the engine, the number of panics has gone down! Yay!
Unfortunately, this is only really true if you do not use the default error handler, which panics by default. Boo!
This is particularly annoying in library code, as relatively harmless problems like inserting a component into a despawned entity are escalated into sudden crashes.
Users can configure
What solution would you like?
We should have some way of annotating the severity level of various problems, plumbing those problems through to BevyError. I'm not sure of the optimal strategy for doing so, but something like this feels right to me:
trait ErrorSeverity: Error {
fn severity(&self) -> SeverityLevel {
ErrorSeverity::Critical
}
}These can then be handled by the default error handler, causing it to log at the appropriate level, rather than immediately crashing.
We should also provide a "always panics" error handler for users who want the old behavior and are particularly performance sensitive. This error handler can be used on no_std platforms as needed as well.
What alternative(s) have you considered?
We could make possibly fallible operations fail silently. This is bad, because it masks potentially serious bugs in really frustrating ways.
We could log directly in our code, and return Ok. This is bad, because it's not robust to alternate logging solutions, and lies about the status of
We could add variants like try_insert everywhere, to make ignoring errors easier. This is bad, because it results in serious API duplication, complicating maintenance, and presents users with footguns.
Additional context
Discussed in #20544 with @NthTensor and @janhohenheim.