Show errors for attempted fixes only when passed --verbose (#15237)

The default logging level for diagnostics includes logs written using
the `log` crate with level `error`, `warn`, and `info`. An unsuccessful
fix attached to a diagnostic via `try_set_fix` or `try_set_optional_fix`
was logged at level `error`. Note that the user would see these messages
even without passing `--fix`, and possibly also on lines with `noqa`
comments.

This PR changes the logging level here to a `debug`. We also found
ad-hoc instances of error logging in the implementations of several
rules, and have replaced those with either a `debug` or call to
`try_set{_optional}_fix`.

Closes #15229
This commit is contained in:
Dylan 2025-01-03 08:50:13 -06:00 committed by GitHub
parent 0837cdd931
commit 706d87f239
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 132 additions and 56 deletions

View file

@ -1,5 +1,5 @@
use anyhow::Result;
use log::error;
use log::debug;
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};
@ -56,7 +56,7 @@ impl Diagnostic {
pub fn try_set_fix(&mut self, func: impl FnOnce() -> Result<Fix>) {
match func() {
Ok(fix) => self.fix = Some(fix),
Err(err) => error!("Failed to create fix for {}: {}", self.kind.name, err),
Err(err) => debug!("Failed to create fix for {}: {}", self.kind.name, err),
}
}
@ -67,7 +67,7 @@ impl Diagnostic {
match func() {
Ok(None) => {}
Ok(Some(fix)) => self.fix = Some(fix),
Err(err) => error!("Failed to create fix for {}: {}", self.kind.name, err),
Err(err) => debug!("Failed to create fix for {}: {}", self.kind.name, err),
}
}