mirror of
https://github.com/astral-sh/ruff.git
synced 2025-07-24 05:25:17 +00:00
Show full error context in server messages (#13029)
## Summary Reference: https://docs.rs/anyhow/latest/anyhow/struct.Error.html#display-representations Closes: #13022 ## Test Plan ``` 2024-08-21 15:21:24.831 [info] [Trace - 3:21:24 PM] 0.017255167s ERROR ThreadId(04) ruff_server::session::index::ruff_settings: Failed to parse /Users/dhruv/playground/ruff/pyproject.toml: TOML parse error at line 1, column 1 | 1 | [tool.ruff.lint] | ^^^^^^^^^^^^^^^^ Unknown rule selector: `ME102` ``` Or, ``` 2024-08-21 15:23:47.993 [info] [Trace - 3:23:47 PM] 143.179857375s ERROR ThreadId(66) ruff_server::session::index::ruff_settings: Failed to parse /Users/dhruv/playground/ruff/pyproject.toml: TOML parse error at line 2, column 42 | 2 | select = ["ALL", "TD006", "TD007", "FIX" | ^ invalid array expected `]` ```
This commit is contained in:
parent
e5f37a8254
commit
0c98b5949c
1 changed files with 30 additions and 15 deletions
|
@ -3,6 +3,7 @@ use std::path::{Path, PathBuf};
|
|||
use std::sync::atomic::{AtomicBool, Ordering};
|
||||
use std::sync::Arc;
|
||||
|
||||
use anyhow::Context;
|
||||
use ignore::{WalkBuilder, WalkState};
|
||||
|
||||
use ruff_linter::{
|
||||
|
@ -100,7 +101,7 @@ impl RuffSettings {
|
|||
|
||||
impl RuffSettingsIndex {
|
||||
pub(super) fn new(root: &Path, editor_settings: &ResolvedEditorSettings) -> Self {
|
||||
let mut error = false;
|
||||
let mut has_error = false;
|
||||
let mut index = BTreeMap::default();
|
||||
let mut respect_gitignore = None;
|
||||
|
||||
|
@ -127,20 +128,27 @@ impl RuffSettingsIndex {
|
|||
);
|
||||
break;
|
||||
}
|
||||
Err(err) => {
|
||||
error => {
|
||||
tracing::error!(
|
||||
"Error while resolving settings from {}: {err}",
|
||||
pyproject.display()
|
||||
"{:#}",
|
||||
error
|
||||
.with_context(|| {
|
||||
format!(
|
||||
"Failed to resolve settings for {}",
|
||||
pyproject.display()
|
||||
)
|
||||
})
|
||||
.unwrap_err()
|
||||
);
|
||||
error = true;
|
||||
has_error = true;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(None) => continue,
|
||||
Err(err) => {
|
||||
tracing::error!("{err}");
|
||||
error = true;
|
||||
tracing::error!("{err:#}");
|
||||
has_error = true;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
@ -162,7 +170,7 @@ impl RuffSettingsIndex {
|
|||
let walker = builder.build_parallel();
|
||||
|
||||
let index = std::sync::RwLock::new(index);
|
||||
let error = AtomicBool::new(error);
|
||||
let has_error = AtomicBool::new(has_error);
|
||||
|
||||
walker.run(|| {
|
||||
Box::new(|result| {
|
||||
|
@ -224,19 +232,26 @@ impl RuffSettingsIndex {
|
|||
}),
|
||||
);
|
||||
}
|
||||
Err(err) => {
|
||||
error => {
|
||||
tracing::error!(
|
||||
"Error while resolving settings from {}: {err}",
|
||||
pyproject.display()
|
||||
"{:#}",
|
||||
error
|
||||
.with_context(|| {
|
||||
format!(
|
||||
"Failed to resolve settings for {}",
|
||||
pyproject.display()
|
||||
)
|
||||
})
|
||||
.unwrap_err()
|
||||
);
|
||||
error.store(true, Ordering::Relaxed);
|
||||
has_error.store(true, Ordering::Relaxed);
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(None) => {}
|
||||
Err(err) => {
|
||||
tracing::error!("{err}");
|
||||
error.store(true, Ordering::Relaxed);
|
||||
tracing::error!("{err:#}");
|
||||
has_error.store(true, Ordering::Relaxed);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -244,7 +259,7 @@ impl RuffSettingsIndex {
|
|||
})
|
||||
});
|
||||
|
||||
if error.load(Ordering::Relaxed) {
|
||||
if has_error.load(Ordering::Relaxed) {
|
||||
let root = root.display();
|
||||
show_err_msg!(
|
||||
"Error while resolving settings from workspace {root}. Please refer to the logs for more details.",
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue