on master help sign in
fix(dap): validate key and index exist when requesting vars (#5628)
44729fbFilip Dutescu
helix-term/src/commands/dap.rs+20−3
@@ -475,19 +475,36 @@ pub fn dap_variables(cx: &mut Context) {
475
475
476 if debugger.thread_id.is_none() {
476 if debugger.thread_id.is_none() {
477 cx.editor
477 cx.editor
478− .set_status("Cannot access variables while target is running");
478+ .set_status("Cannot access variables while target is running.");
479 return;
479 return;
480 }
480 }
481 let (frame, thread_id) = match (debugger.active_frame, debugger.thread_id) {
481 let (frame, thread_id) = match (debugger.active_frame, debugger.thread_id) {
482 (Some(frame), Some(thread_id)) => (frame, thread_id),
482 (Some(frame), Some(thread_id)) => (frame, thread_id),
483 _ => {
483 _ => {
484 cx.editor
484 cx.editor
485− .set_status("Cannot find current stack frame to access variables");
485+ .set_status("Cannot find current stack frame to access variables.");
486 return;
486 return;
487 }
487 }
488 };
488 };
489
489
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;
491 let scopes = match block_on(debugger.scopes(frame_id)) {
508 let scopes = match block_on(debugger.scopes(frame_id)) {
492 Ok(s) => s,
509 Ok(s) => s,
493 Err(e) => {
510 Err(e) => {