Skip to content

Commit 0c98b59

Browse files
authored
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 `]` ```
1 parent e5f37a8 commit 0c98b59

File tree

1 file changed

+30
-15
lines changed

1 file changed

+30
-15
lines changed

crates/ruff_server/src/session/index/ruff_settings.rs

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use std::path::{Path, PathBuf};
33
use std::sync::atomic::{AtomicBool, Ordering};
44
use std::sync::Arc;
55

6+
use anyhow::Context;
67
use ignore::{WalkBuilder, WalkState};
78

89
use ruff_linter::{
@@ -100,7 +101,7 @@ impl RuffSettings {
100101

101102
impl RuffSettingsIndex {
102103
pub(super) fn new(root: &Path, editor_settings: &ResolvedEditorSettings) -> Self {
103-
let mut error = false;
104+
let mut has_error = false;
104105
let mut index = BTreeMap::default();
105106
let mut respect_gitignore = None;
106107

@@ -127,20 +128,27 @@ impl RuffSettingsIndex {
127128
);
128129
break;
129130
}
130-
Err(err) => {
131+
error => {
131132
tracing::error!(
132-
"Error while resolving settings from {}: {err}",
133-
pyproject.display()
133+
"{:#}",
134+
error
135+
.with_context(|| {
136+
format!(
137+
"Failed to resolve settings for {}",
138+
pyproject.display()
139+
)
140+
})
141+
.unwrap_err()
134142
);
135-
error = true;
143+
has_error = true;
136144
continue;
137145
}
138146
}
139147
}
140148
Ok(None) => continue,
141149
Err(err) => {
142-
tracing::error!("{err}");
143-
error = true;
150+
tracing::error!("{err:#}");
151+
has_error = true;
144152
continue;
145153
}
146154
}
@@ -162,7 +170,7 @@ impl RuffSettingsIndex {
162170
let walker = builder.build_parallel();
163171

164172
let index = std::sync::RwLock::new(index);
165-
let error = AtomicBool::new(error);
173+
let has_error = AtomicBool::new(has_error);
166174

167175
walker.run(|| {
168176
Box::new(|result| {
@@ -224,27 +232,34 @@ impl RuffSettingsIndex {
224232
}),
225233
);
226234
}
227-
Err(err) => {
235+
error => {
228236
tracing::error!(
229-
"Error while resolving settings from {}: {err}",
230-
pyproject.display()
237+
"{:#}",
238+
error
239+
.with_context(|| {
240+
format!(
241+
"Failed to resolve settings for {}",
242+
pyproject.display()
243+
)
244+
})
245+
.unwrap_err()
231246
);
232-
error.store(true, Ordering::Relaxed);
247+
has_error.store(true, Ordering::Relaxed);
233248
}
234249
}
235250
}
236251
Ok(None) => {}
237252
Err(err) => {
238-
tracing::error!("{err}");
239-
error.store(true, Ordering::Relaxed);
253+
tracing::error!("{err:#}");
254+
has_error.store(true, Ordering::Relaxed);
240255
}
241256
}
242257

243258
WalkState::Continue
244259
})
245260
});
246261

247-
if error.load(Ordering::Relaxed) {
262+
if has_error.load(Ordering::Relaxed) {
248263
let root = root.display();
249264
show_err_msg!(
250265
"Error while resolving settings from workspace {root}. Please refer to the logs for more details.",

0 commit comments

Comments
 (0)