Warn if App::run() or App::update() are not called#5395
Warn if App::run() or App::update() are not called#5395arnavc52 wants to merge 0 commit intobevyengine:mainfrom arnavc52:main
App::run() or App::update() are not called#5395Conversation
|
This only warns on the code |
|
adding The following code snippet will complain but shouldn't let mut app = App::new();
app.add_plugins(DefaultPlugins);
app.run(); |
|
As @mockersf just mentioned, the |
|
Hmm. A custom drop impl would be interesting. I'm curious to see what that looks like. |
|
Clever! Can you add a test to verify that this keeps working? |
App::run() is not calledApp::run() or App::update() are not called
Does "this keeps working" mean that the message is printed, or does it mean that it doesn't panic? |
|
That the message is printed in the cases where it should be, and not when the app is run or updated. |
Thanks! |
|
Afraid I don't have anything more useful to add, but...wow, you all are awesome. Didn't expect filing my first Bevy issue would get a PR with multiple (clever!) iterations in about half a day. You rock, Bevy rocks, and Rust rocks. |
|
I found two issues:
|
That might be troublesome. I'm pretty sure the Bevy log plugin has to be added or you won't get the warning. Maybe this isn't a big deal because most people will have added the @Nilirad did you add any plugins in your test where you didn't get the warning? |
|
Maybe a
No, I just stripped the |
|
Maybe we can check if there's already a tracing subscriber, and if there isn't, we println, but if there is, we log. |
Great idea! |
|
The error message does appear in the hello world example, but it comes even when the |
|
Is it possible to remove the flag for the release profile? It's essentially a debug check and not a soundness one. |
Also a great idea! |
|
I would rather not have a check for logger, and a fallback to |
It only does that if the |
Then it's wrong... logging doesn't depend on the |
|
|
The Logs are using the |
|
@mockersf Thanks for clarifying it for me! |
mockersf
left a comment
There was a problem hiding this comment.
I don't like that it's behind debug_assertions, and I don't like the fallback to println, but the PR does what it says
Do you really want to ship 8 bytes of bloat to production? 🙃 |
alice-i-cecile
left a comment
There was a problem hiding this comment.
I like the println fallback (this is an important error message for beginners), but could go either way on the debug_assertions flag. Leaning against it; I'd probably cut it if it was my PR.
Won't block on that though.
|
That's a good point. If we want users to actually see the message, we should have that enabled even for release mode. Almost nobody can actually play games without optimizations I think. |
|
EDIT 2: Actually, the Cargo book shows that debug assertions are always enabled by default in the dev profile, independently from optimization level. A developer should really not debug in release profile though, but just tweak the dev profile... |
|
I got rid of the |
|
bors r+ |
|
bors r- (Waiting on reviews; this isn't urgent and it'll mess up the change log a bit). |
|
Canceled. |
# Objective - Fixes #5386 - Display a warning if `App::run()` is not called - Why? Because people can accidentally delete the `.run()` (as mentioned in the issue). By displaying a warning, people can fix their code in seconds, instead of painstakingly debugging their entire codebase. ## Solution - ~Added a `#[must_use]` to `App` with a helpful warning message~ - Print a helpful warning to the console (using either `LogPlugin` or good old `println!`) if the `App` is dropped without being run in a debug build.
|
I get no warning message in |
|
it just occurred to me that if this PR worked, the message would be logged twice as there are two apps created (and dropped): the main app and the renderer app. With that, I don't think implementing drop for app is the correct solution |
|
I got rid of the part that checked if there was a logger. It didn't work and it wasn't very popular to begin with.
That does happen, but I don't think it's really a problem. It's mostly just a cosmetic issue. |
|
This will always throw a warning as neither |
|
the proper way to fix this would to use the |
Objective
App::run()is not called.run()(as mentioned in the issue). By displaying a warning, people can fix their code in seconds, instead of painstakingly debugging their entire codebase.Solution
Added a#[must_use]toAppwith a helpful warning messageLogPluginor good oldprintln!) if theAppis dropped without being run in a debug build.