Skip to content

Commit bfb716a

Browse files
kinto0meta-codesync[bot]
authored andcommitted
handle anyhow exceptions in LS gracefully
Summary: when processing an event returned an error response, we would still crash. instead, we should attempt to continue this change affects any event that returns an anyhow error. however, the only 6 usages are in did_change events (the spot we are targeting to ignore errors) Reviewed By: samwgoldman Differential Revision: D87239356 fbshipit-source-id: f4a9a5866c74812a7324f16896a7788c138039f7
1 parent cde5378 commit bfb716a

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

pyrefly/lib/lsp/non_wasm/server.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ use serde::de::DeserializeOwned;
183183
use serde_json::Value;
184184
use starlark_map::small_map::SmallMap;
185185
use starlark_map::small_set::SmallSet;
186+
use tracing::error;
186187
use tracing::info;
187188

188189
use crate::ModuleInfo;
@@ -612,15 +613,19 @@ pub fn lsp_loop(
612613
&mut canceled_requests,
613614
subsequent_mutation,
614615
event,
615-
)? {
616-
ProcessEvent::Continue => {
616+
) {
617+
Ok(ProcessEvent::Continue) => {
617618
let process_duration = process_start.elapsed().as_secs_f32();
618619
info!(
619620
"Language server processed event `{}` in {:.2}s ({:.2}s waiting)",
620621
event_description, process_duration, queue_duration
621622
);
622623
}
623-
ProcessEvent::Exit => break,
624+
Ok(ProcessEvent::Exit) => break,
625+
Err(e) => {
626+
// Log the error and continue processing the next event
627+
error!("Error processing event `{}`: {:?}", event_description, e);
628+
}
624629
}
625630
}
626631
info!("waiting for connection to close");

0 commit comments

Comments
 (0)