Skip to content

Commit

Permalink
Show full error context in server messages (#13029)
Browse files Browse the repository at this point in the history
## 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 `]`
```
  • Loading branch information
dhruvmanila authored Aug 21, 2024
1 parent e5f37a8 commit 0c98b59
Showing 1 changed file with 30 additions and 15 deletions.
45 changes: 30 additions & 15 deletions crates/ruff_server/src/session/index/ruff_settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down Expand Up @@ -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;

Expand All @@ -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;
}
}
Expand All @@ -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| {
Expand Down Expand Up @@ -224,27 +232,34 @@ 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);
}
}

WalkState::Continue
})
});

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.",
Expand Down

0 comments on commit 0c98b59

Please sign in to comment.