Skip to content
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

Add print_stdout and print_stderr lints (#17446) #18233

Merged
merged 1 commit into from
Mar 11, 2025

Conversation

sirius94
Copy link
Contributor

Objective

Solution

  • Enable the print_stdout and print_stderr clippy lints
  • Replace all println! and eprintln! occurrences with log::* where applicable or alternatively ignore the warnings

Testing

  • Run cargo clippy --workspace to ensure that there are no warnings relating to printing to stdout or stderr

Copy link
Contributor

Welcome, new contributor!

Please make sure you've read our contributing guide and we look forward to reviewing your pull request shortly ✨

@@ -12,6 +12,7 @@
)]

use bevy_ecs::prelude::*;
use log::info;
Copy link
Member

@alice-i-cecile alice-i-cecile Mar 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In examples we should be using bevy's re-exports of this, but since this is in bevy_ecs's dedicated examples this is fine.

Copy link
Member

@alice-i-cecile alice-i-cecile left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Really thorough work. Thank you!

@alice-i-cecile alice-i-cecile added C-Code-Quality A section of code that is hard to understand or change A-Cross-Cutting Impacts the entire engine O-Embedded Weird hardware and no_std platforms D-Straightforward Simple bug fixes and API improvements, docs, test and examples S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Mar 10, 2025
@sirius94 sirius94 force-pushed the 17446-lint-stdout-stderr branch 2 times, most recently from a5138bc to c87d1d8 Compare March 10, 2025 18:22
@sirius94 sirius94 marked this pull request as draft March 10, 2025 18:32
@sirius94
Copy link
Contributor Author

I've missed some things. I'll change this back to 'ready for review' when all the automated checks pass.

@sirius94 sirius94 force-pushed the 17446-lint-stdout-stderr branch 3 times, most recently from 1d428ee to 8c32b8a Compare March 10, 2025 19:17
@sirius94 sirius94 marked this pull request as ready for review March 10, 2025 19:33
Copy link
Contributor

@bushrat011899 bushrat011899 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! Standardising the code-base (and explicitly annotating exceptions with expect) is always worth it, even ignoring the no_std benefits.

@bushrat011899 bushrat011899 added S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it and removed S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Mar 10, 2025
Copy link
Member

@mockersf mockersf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you changed a few tests where they should continue to use println. loggers are often not set for tests

@@ -37,7 +38,7 @@ fn main() {

// Simulate 10 frames in our world
for iteration in 1..=10 {
println!("Simulating frame {iteration}/10");
info!("Simulating frame {iteration}/10");
Copy link
Member

@mockersf mockersf Mar 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logger is also not set in this file so it should still use println

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this have a #[cfg(feature="std)] then?

@@ -2,6 +2,7 @@
//! If an event was send, it will be printed by the console in a receiving system.

use bevy_ecs::{event::EventRegistry, prelude::*};
use log::info;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here, this should keep using println

@@ -7,6 +7,7 @@
)]

use bevy_ecs::prelude::*;
use log::info;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here, this should keep using println

@@ -283,7 +281,7 @@ impl<'scope, 'env: 'scope, 'sys> Context<'scope, 'env, 'sys> {
.push(SystemResult { system_index })
.unwrap_or_else(|error| unreachable!("{}", error));
if let Err(payload) = res {
eprintln!("Encountered a panic in system `{}`!", &*system.name());
log::error!("Encountered a panic in system `{}`!", &*system.name());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there's no guarantee a logger is set here and this error is too important to risk to hide, it should keep using eprintln

@mockersf
Copy link
Member

very few of the existing println should be replaced for this, they should be expect. most of them have already been checked

@alice-i-cecile alice-i-cecile added S-Waiting-on-Author The author needs to make changes or address concerns before this can be merged and removed S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it labels Mar 10, 2025
@sirius94 sirius94 force-pushed the 17446-lint-stdout-stderr branch from 9dc3900 to 82fa507 Compare March 10, 2025 22:02
@alice-i-cecile alice-i-cecile requested a review from mockersf March 11, 2025 01:22
@alice-i-cecile alice-i-cecile added S-Needs-Review Needs reviewer attention (from anyone!) to move forward and removed S-Waiting-on-Author The author needs to make changes or address concerns before this can be merged labels Mar 11, 2025
@mockersf
Copy link
Member

this is still changing too many println to logs. those changes should be reverted

@mockersf mockersf added S-Waiting-on-Author The author needs to make changes or address concerns before this can be merged and removed S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Mar 11, 2025
@sirius94 sirius94 force-pushed the 17446-lint-stdout-stderr branch from 82fa507 to 3fbd313 Compare March 11, 2025 16:36
@sirius94 sirius94 force-pushed the 17446-lint-stdout-stderr branch from 3fbd313 to e5b15f2 Compare March 11, 2025 16:37
@sirius94
Copy link
Contributor Author

I reverted the changes from prints to logs and used expect instead.

@alice-i-cecile alice-i-cecile dismissed mockersf’s stale review March 11, 2025 19:35

All changes to log have been removed.

@alice-i-cecile alice-i-cecile added this pull request to the merge queue Mar 11, 2025
@alice-i-cecile alice-i-cecile added S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it and removed S-Waiting-on-Author The author needs to make changes or address concerns before this can be merged labels Mar 11, 2025
Merged via the queue into bevyengine:main with commit 8570af1 Mar 11, 2025
36 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Cross-Cutting Impacts the entire engine C-Code-Quality A section of code that is hard to understand or change D-Straightforward Simple bug fixes and API improvements, docs, test and examples O-Embedded Weird hardware and no_std platforms S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bevy should deny eprintln and println and prefer log and/or tracing
5 participants