Skip to content

Commit

Permalink
Introduce show_err_msg! to significant error paths
Browse files Browse the repository at this point in the history
  • Loading branch information
snowsignal committed Apr 15, 2024
1 parent a5daba2 commit 6e0b6ca
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
8 changes: 8 additions & 0 deletions crates/ruff_server/src/server/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ pub(super) fn request<'a>(req: server::Request) -> Task<'a> {
}
.unwrap_or_else(|err| {
tracing::error!("Encountered error when routing request with ID {id}: {err}");
show_err_msg!("Ruff failed to handle a request from the editor. Check the error log for more details.");
let result: Result<()> = Err(err);
Task::immediate(id, result)
})
Expand Down Expand Up @@ -84,6 +85,7 @@ pub(super) fn notification<'a>(notif: server::Notification) -> Task<'a> {
}
.unwrap_or_else(|err| {
tracing::error!("Encountered error when routing notification: {err}");
show_err_msg!("Ruff failed to handle a notification from the editor. Check the error log for more details.");
Task::nothing()
})
}
Expand Down Expand Up @@ -122,6 +124,7 @@ fn local_notification_task<'a, N: traits::SyncNotificationHandler>(
Ok(Task::local(move |session, notifier, _, _| {
if let Err(err) = N::run(session, notifier, params) {
tracing::error!("An error occurred while running {id}: {err}");
show_err_msg!("Ruff encountered a problem. Check the error log for more details.");
}
}))
}
Expand All @@ -140,6 +143,7 @@ fn background_notification_thread<'a, N: traits::BackgroundDocumentNotificationH
Box::new(move |notifier, _| {
if let Err(err) = N::run_with_snapshot(snapshot, notifier, params) {
tracing::error!("An error occurred while running {id}: {err}");
show_err_msg!("Ruff encountered a problem. Check the error log for more details.");
}
})
}))
Expand Down Expand Up @@ -182,6 +186,10 @@ fn respond<Req>(
) where
Req: traits::RequestHandler,
{
if let Err(err) = &result {
tracing::error!("An error occurred with result ID {id}: {err}");
show_err_msg!("Ruff encountered a problem. Check the error log for more details.");
}
if let Err(err) = responder.respond(id, result) {
tracing::error!("Failed to send response: {err}");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,8 @@ fn apply_edit(
let reason = response
.failure_reason
.unwrap_or_else(|| String::from("unspecified reason"));
tracing::error!("Failed to apply workspace edit: {}", reason);
tracing::error!("Failed to apply workspace edit: {reason}");
show_err_msg!("Ruff was unable to apply edits: {reason}");
}
Task::nothing()
},
Expand Down
1 change: 1 addition & 0 deletions crates/ruff_server/src/session/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ impl AllSettings {
serde_json::from_value(options)
.map_err(|err| {
tracing::error!("Failed to deserialize initialization options: {err}. Falling back to default client settings...");
show_err_msg!("Ruff received invalid client settings - falling back to default client settings.");
})
.unwrap_or_default(),
)
Expand Down

0 comments on commit 6e0b6ca

Please sign in to comment.