Skip to content

BevyError should include error severity to allow for customizable handling #20561

@alice-i-cecile

Description

@alice-i-cecile

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.

Related to #15979, #5617 and #17271.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-ECSEntities, components, systems, and eventsC-FeatureA new feature, making something new possibleD-ModestA "normal" level of difficulty; suitable for simple features or challenging fixesM-Release-NoteWork that should be called out in the blog due to impactS-Ready-For-ImplementationThis issue is ready for an implementation PR. Go for it!

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions