-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Better error messages for IntoSystem and IntoExclusive System #1519
Comments
Ok, first: How do we detect if a parameter fails? What about missing or superfluous parameters? What "simple" suggestions could we make (e.g. look at the variables in scope and suggest one or all of a matching type)? |
The simplest start IMO is that each of the function parameters needs a valid The lowest hanging fruit is to simply tell you which parameters this failed for. This would be a huge win, because it would let users narrow down their problem and catch obvious mistakes. The next step would be to try and guess which impl they meant to use, then statically list off common fixes: see this page on the Cheatbook. From there, we could have tangible suggestions on how to fix the problem to conform to the target impl. Missing parameters are very rare so far, although see #1587 for an exception. Superfluous parameters are already caught nicely by existing "unused variable" / "unused mut" warnings and lints. |
Random thought: with specialization, we could implement SystemParam for every type by default, then override the default for "valid" params. .system() would then fail for any "default" implementations with a "T is not a valid SystemParam" error message. But of course specialization is X years away where X is 1-never. |
The benefit is that users get useful error messages. The downside is that "invalid" systems are no longer compile time errors, so it's probably not worth it. |
This is probably my number one headache with Bevy (edit "number one" may be an exaggeration, I wrote it just after a frustrating session debugging systems that weren't working, but it is definitely up there). I spend an inordinate amount of time trying to figure out why the compiler is insisting that my function doesn't implement I wonder if this would actually work OK for a "normal" type (e.g, a tuple). The compiler is normally pretty good about telling me which constraint is preventing a trait from being implemented. But that error seems to get overridden for functions with the error quoted above ("... X is a function, did you mean to call it?") I tried an experiment of adding an
(note: it appears to be a compiler quirk that the one-parameter tuple variant isn't printed here -- I did check that I could get my code to compile if the system signature was correct) I suspect that the compiler is not printing why the implementations can't be matched because there are so many candidates. I know I've seen it print more guidance in simpler cases (when there is just one candidate, for instance). Another idea: maybe it would work to use an attribute procmacro to mark functions as "intended to be System"? (probably the macro would spit out an |
Something I should have linked on this thread earlier: bevycheck a wonderful macro crate for helping you debug your systems. @concave-sphere does this line up with your attribute procmacro idea? |
@alice-i-cecile Oh, that looks great! Will definitely cut down on my debug cycles. IMO this should be the default behavior for the ECS. One note: the page says:
I wonder if this could be fixed by adding
into this:
I just checked in the playground, and while placing type bounds on concrete types is weird, it works fine (including generating sensible compile errors when they don't match). |
I've made a reproduction of the problems at https://github.com/alice-i-cecile/bevy_compiler_errors. |
This commit introduces a new feature flags that let's user opt into the nightly only `#[rustc_on_unimplemented]` attribute. This attribute can be used to improve error messages generated by missing trait implementations. This commit adds annotations to two locations in bevy to improve error messages submitted as part of weiznich/rust-foundation-community-grant#3 Addresses bevyengine#1519
This commit introduces a new feature flags that let's user opt into the nightly only `#[rustc_on_unimplemented]` attribute. This attribute can be used to improve error messages generated by missing trait implementations. This commit adds annotations to two locations in bevy to improve error messages submitted as part of weiznich/rust-foundation-community-grant#3 Addresses bevyengine#1519
This commit introduces a new feature flags that let's user opt into the nightly only `#[rustc_on_unimplemented]` attribute. This attribute can be used to improve error messages generated by missing trait implementations. This commit adds annotations to two locations in bevy to improve error messages submitted as part of weiznich/rust-foundation-community-grant#3 Addresses bevyengine#1519
What problem does this solve or what need does it fill?
The current error messages for when system parameters is wrong is very opaque. As an example:
This is particularly painful because these mistakes are a common beginner issue and there's no clear path forward.
What solution would you like?
The compiler examines each of your system's parameters, explains which one fails, and ideally makes a simple suggestion on how to correct it.
What alternative(s) have you considered?
None.
Additional context
The relevant macros would be cleaned up substantially if variadic generics ever lands.
The text was updated successfully, but these errors were encountered: