Skip to content

Use the #[diagnostic::on_unimplemented] attribute to improve ECS (system and query) error messages #12377

Description

@alice-i-cecile

What problem does this solve or what need does it fill?

Bevy's error messages for invalid inputs for systems and queries that take SystemParam, QueryData or QueryFilter are terrible: users get a terrible error message saying that the trait isn't implemented for the whole tuple and suggesting a bunch of irrelevant tuples with generic types.

For upstream reports of what these errors look like, please see:

What solution would you like?

Use the soon-to-be-stabilized diagnostic attribute on our key traits, and manually provide more helpful error messages.

#[diagnostic::on_unimplemented(
    message = "My Message for `ImportantTrait<{A}>` is not implemented for `{Self}`",
    label = "My Label",
    note = "Note 1",
    note = "Note 2"
)]
trait ImportantTrait<A> {}

rust-lang/rust#119888 is the stabilization PR which goes over more details of how this works: this will not be available until Rust 1.78.

What alternative(s) have you considered?

  1. Add variadic generics to upstream Rust (one day).
  2. Use a macro to determine these things that needs to be added to every system. bevy_check by @jakobhellermann does this, and is essential prior art.

Additional context

This was brought to my attention by George Semmler on Mastodon.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-ECSEntities, components, systems, and eventsC-UsabilityA targeted quality-of-life change that makes Bevy easier to useS-Needs-ReviewNeeds reviewer attention (from anyone!) to move forwardX-UncontroversialThis work is generally agreed upon

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions