File tree Expand file tree Collapse file tree 2 files changed +15
-8
lines changed Expand file tree Collapse file tree 2 files changed +15
-8
lines changed Original file line number Diff line number Diff line change @@ -87,14 +87,19 @@ pub fn main() -> ExitCode {
87
87
Err ( err) => {
88
88
#[ allow( clippy:: print_stderr) ]
89
89
{
90
+ use std:: io:: Write ;
91
+
92
+ // Use `writeln` instead of `eprintln` to avoid panicking when the stderr pipe is broken.
93
+ let mut stderr = std:: io:: stderr ( ) . lock ( ) ;
94
+
90
95
// This communicates that this isn't a linter error but ruff itself hard-errored for
91
96
// some reason (e.g. failed to resolve the configuration)
92
- eprintln ! ( "{}" , "ruff failed" . red( ) . bold( ) ) ;
97
+ writeln ! ( stderr , "{}" , "ruff failed" . red( ) . bold( ) ) . ok ( ) ;
93
98
// Currently we generally only see one error, but e.g. with io errors when resolving
94
99
// the configuration it is help to chain errors ("resolving configuration failed" ->
95
100
// "failed to read file: subdir/pyproject.toml")
96
101
for cause in err. chain ( ) {
97
- eprintln ! ( " {} {cause}" , "Cause:" . bold( ) ) ;
102
+ writeln ! ( stderr , " {} {cause}" , "Cause:" . bold( ) ) . ok ( ) ;
98
103
}
99
104
}
100
105
ExitStatus :: Error . into ( )
Original file line number Diff line number Diff line change @@ -16,6 +16,8 @@ pub(crate) fn init_messenger(client_sender: ClientSender) {
16
16
17
17
// When we panic, try to notify the client.
18
18
std:: panic:: set_hook ( Box :: new ( move |panic_info| {
19
+ use std:: io:: Write ;
20
+
19
21
if let Some ( messenger) = MESSENGER . get ( ) {
20
22
let _ = messenger. send ( lsp_server:: Message :: Notification (
21
23
lsp_server:: Notification {
@@ -33,12 +35,12 @@ pub(crate) fn init_messenger(client_sender: ClientSender) {
33
35
34
36
let backtrace = std:: backtrace:: Backtrace :: force_capture ( ) ;
35
37
tracing:: error!( "{panic_info}\n {backtrace}" ) ;
36
- # [ allow ( clippy :: print_stderr ) ]
37
- {
38
- // we also need to print to stderr directly in case tracing hasn't
39
- // been initialized .
40
- eprintln ! ( "{panic_info} \n {backtrace}" ) ;
41
- }
38
+
39
+ // we also need to print to stderr directly in case tracing hasn't
40
+ // been initialized.
41
+ // But use `writeln` instead of `eprintln` to avoid panicking when the stderr pipe is broken .
42
+ let mut stderr = std :: io :: stderr ( ) . lock ( ) ;
43
+ writeln ! ( stderr , "{panic_info} \n {backtrace}" ) . ok ( ) ;
42
44
} ) ) ;
43
45
}
44
46
You can’t perform that action at this time.
0 commit comments