Skip to content

Commit 33199b7

Browse files
committed
fix: don't panic if the client sends invalid request
1 parent ac25201 commit 33199b7

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

crates/rust-analyzer/src/from_proto.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use crate::{
1010
from_json,
1111
global_state::GlobalStateSnapshot,
1212
line_index::{LineIndex, OffsetEncoding},
13-
lsp_ext, Result,
13+
lsp_ext, LspError, Result,
1414
};
1515

1616
pub(crate) fn abs_path(url: &lsp_types::Url) -> Result<AbsPathBuf> {
@@ -85,7 +85,10 @@ pub(crate) fn annotation(
8585
snap: &GlobalStateSnapshot,
8686
code_lens: lsp_types::CodeLens,
8787
) -> Result<Annotation> {
88-
let data = code_lens.data.unwrap();
88+
let data = code_lens.data.ok_or_else(|| LspError {
89+
code: lsp_server::ErrorCode::InvalidParams as i32,
90+
message: "code lens without data".to_string(),
91+
});
8992
let resolve = from_json::<lsp_ext::CodeLensResolveData>("CodeLensResolveData", data)?;
9093

9194
match resolve {

crates/rust-analyzer/src/handlers.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1038,7 +1038,10 @@ pub(crate) fn handle_code_action_resolve(
10381038
let _p = profile::span("handle_code_action_resolve");
10391039
let params = match code_action.data.take() {
10401040
Some(it) => it,
1041-
None => Err("can't resolve code action without data")?,
1041+
None => Err(LspError {
1042+
code: lsp_server::ErrorCode::InvalidParams as i32,
1043+
message: format!("code action without data"),
1044+
})?,
10421045
};
10431046

10441047
let file_id = from_proto::file_id(&snap, &params.code_action_params.text_document.uri)?;

0 commit comments

Comments
 (0)