File tree Expand file tree Collapse file tree 1 file changed +8
-6
lines changed Expand file tree Collapse file tree 1 file changed +8
-6
lines changed 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