Skip to content

Commit 2263537

Browse files
filipdutescuwes-adams
authored andcommitted
fix(dap): validate key and index exist when requesting vars (helix-editor#5628)
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: helix-editor#5625 Signed-off-by: Filip Dutescu <filip.dutescu@gmail.com>
1 parent 1b846fb commit 2263537

1 file changed

Lines changed: 20 additions & 3 deletions

File tree

helix-term/src/commands/dap.rs

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -475,19 +475,36 @@ pub fn dap_variables(cx: &mut Context) {
475475

476476
if debugger.thread_id.is_none() {
477477
cx.editor
478-
.set_status("Cannot access variables while target is running");
478+
.set_status("Cannot access variables while target is running.");
479479
return;
480480
}
481481
let (frame, thread_id) = match (debugger.active_frame, debugger.thread_id) {
482482
(Some(frame), Some(thread_id)) => (frame, thread_id),
483483
_ => {
484484
cx.editor
485-
.set_status("Cannot find current stack frame to access variables");
485+
.set_status("Cannot find current stack frame to access variables.");
486486
return;
487487
}
488488
};
489489

490-
let frame_id = debugger.stack_frames[&thread_id][frame].id;
490+
let thread_frame = match debugger.stack_frames.get(&thread_id) {
491+
Some(thread_frame) => thread_frame,
492+
None => {
493+
cx.editor
494+
.set_error("Failed to get stack frame for thread: {thread_id}");
495+
return;
496+
}
497+
};
498+
let stack_frame = match thread_frame.get(frame) {
499+
Some(stack_frame) => stack_frame,
500+
None => {
501+
cx.editor
502+
.set_error("Failed to get stack frame for thread {thread_id} and frame {frame}.");
503+
return;
504+
}
505+
};
506+
507+
let frame_id = stack_frame.id;
491508
let scopes = match block_on(debugger.scopes(frame_id)) {
492509
Ok(s) => s,
493510
Err(e) => {

0 commit comments

Comments
 (0)