Skip to content

Commit

Permalink
fix(dap): validate key and index exist when requesting vars
Browse files Browse the repository at this point in the history
Check if the stack frames contain the thread id and the frame before
trying to get the frame id. If case any of the two fails to be
found, provide the user with messages to inform them of the issue and
gracefully return.

Closes #5625
Signed-off-by: Filip Dutescu <[email protected]>
  • Loading branch information
filipdutescu committed Jan 21, 2023
1 parent 2b58ff4 commit b2cf135
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions helix-term/src/commands/dap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -475,19 +475,32 @@ pub fn dap_variables(cx: &mut Context) {

if debugger.thread_id.is_none() {
cx.editor
.set_status("Cannot access variables while target is running");
.set_status("Cannot access variables while target is running.");
return;
}
let (frame, thread_id) = match (debugger.active_frame, debugger.thread_id) {
(Some(frame), Some(thread_id)) => (frame, thread_id),
_ => {
cx.editor
.set_status("Cannot find current stack frame to access variables");
.set_status("Cannot find current stack frame to access variables.");
return;
}
};

let frame_id = debugger.stack_frames[&thread_id][frame].id;
let thread_frame = debugger.stack_frames.get(&thread_id);
if let None = thread_frame {
cx.editor
.set_error("Failed to get stack frame for thread: {thread_id}");
return;
}
let stack_frame = thread_frame.unwrap().get(frame);
if let None = stack_frame {
cx.editor
.set_error("Failed to get stack frame for thread {thread_id} and frame {frame}.");
return;
}

let frame_id = stack_frame.unwrap().id;
let scopes = match block_on(debugger.scopes(frame_id)) {
Ok(s) => s,
Err(e) => {
Expand Down

0 comments on commit b2cf135

Please sign in to comment.