debugger_ui: Don't .unwrap debug panel access (#28131)

This PR removes replaces the `.unwrap`s when accessing the debug panel
with `if let Some`s.

These `.unwrap`s are not locally verifiable, and thus are not safe.

Release Notes:

- N/A
This commit is contained in:
Marshall Bowers 2025-04-04 18:54:40 -04:00 committed by GitHub
parent 8b077f0c41
commit e3d212ac60
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -49,8 +49,7 @@ pub fn init(cx: &mut App) {
workspace.toggle_panel_focus::<DebugPanel>(window, cx); workspace.toggle_panel_focus::<DebugPanel>(window, cx);
}) })
.register_action(|workspace, _: &Pause, _, cx| { .register_action(|workspace, _: &Pause, _, cx| {
let debug_panel = workspace.panel::<DebugPanel>(cx).unwrap(); if let Some(debug_panel) = workspace.panel::<DebugPanel>(cx) {
if let Some(active_item) = debug_panel.read_with(cx, |panel, cx| { if let Some(active_item) = debug_panel.read_with(cx, |panel, cx| {
panel panel
.active_session(cx) .active_session(cx)
@ -58,10 +57,10 @@ pub fn init(cx: &mut App) {
}) { }) {
active_item.update(cx, |item, cx| item.pause_thread(cx)) active_item.update(cx, |item, cx| item.pause_thread(cx))
} }
}
}) })
.register_action(|workspace, _: &Restart, _, cx| { .register_action(|workspace, _: &Restart, _, cx| {
let debug_panel = workspace.panel::<DebugPanel>(cx).unwrap(); if let Some(debug_panel) = workspace.panel::<DebugPanel>(cx) {
if let Some(active_item) = debug_panel.read_with(cx, |panel, cx| { if let Some(active_item) = debug_panel.read_with(cx, |panel, cx| {
panel panel
.active_session(cx) .active_session(cx)
@ -69,10 +68,10 @@ pub fn init(cx: &mut App) {
}) { }) {
active_item.update(cx, |item, cx| item.restart_session(cx)) active_item.update(cx, |item, cx| item.restart_session(cx))
} }
}
}) })
.register_action(|workspace, _: &StepInto, _, cx| { .register_action(|workspace, _: &StepInto, _, cx| {
let debug_panel = workspace.panel::<DebugPanel>(cx).unwrap(); if let Some(debug_panel) = workspace.panel::<DebugPanel>(cx) {
if let Some(active_item) = debug_panel.read_with(cx, |panel, cx| { if let Some(active_item) = debug_panel.read_with(cx, |panel, cx| {
panel panel
.active_session(cx) .active_session(cx)
@ -80,10 +79,10 @@ pub fn init(cx: &mut App) {
}) { }) {
active_item.update(cx, |item, cx| item.step_in(cx)) active_item.update(cx, |item, cx| item.step_in(cx))
} }
}
}) })
.register_action(|workspace, _: &StepOver, _, cx| { .register_action(|workspace, _: &StepOver, _, cx| {
let debug_panel = workspace.panel::<DebugPanel>(cx).unwrap(); if let Some(debug_panel) = workspace.panel::<DebugPanel>(cx) {
if let Some(active_item) = debug_panel.read_with(cx, |panel, cx| { if let Some(active_item) = debug_panel.read_with(cx, |panel, cx| {
panel panel
.active_session(cx) .active_session(cx)
@ -91,10 +90,10 @@ pub fn init(cx: &mut App) {
}) { }) {
active_item.update(cx, |item, cx| item.step_over(cx)) active_item.update(cx, |item, cx| item.step_over(cx))
} }
}
}) })
.register_action(|workspace, _: &StepBack, _, cx| { .register_action(|workspace, _: &StepBack, _, cx| {
let debug_panel = workspace.panel::<DebugPanel>(cx).unwrap(); if let Some(debug_panel) = workspace.panel::<DebugPanel>(cx) {
if let Some(active_item) = debug_panel.read_with(cx, |panel, cx| { if let Some(active_item) = debug_panel.read_with(cx, |panel, cx| {
panel panel
.active_session(cx) .active_session(cx)
@ -102,10 +101,10 @@ pub fn init(cx: &mut App) {
}) { }) {
active_item.update(cx, |item, cx| item.step_back(cx)) active_item.update(cx, |item, cx| item.step_back(cx))
} }
}
}) })
.register_action(|workspace, _: &Stop, _, cx| { .register_action(|workspace, _: &Stop, _, cx| {
let debug_panel = workspace.panel::<DebugPanel>(cx).unwrap(); if let Some(debug_panel) = workspace.panel::<DebugPanel>(cx) {
if let Some(active_item) = debug_panel.read_with(cx, |panel, cx| { if let Some(active_item) = debug_panel.read_with(cx, |panel, cx| {
panel panel
.active_session(cx) .active_session(cx)
@ -113,10 +112,10 @@ pub fn init(cx: &mut App) {
}) { }) {
active_item.update(cx, |item, cx| item.stop_thread(cx)) active_item.update(cx, |item, cx| item.stop_thread(cx))
} }
}
}) })
.register_action(|workspace, _: &ToggleIgnoreBreakpoints, _, cx| { .register_action(|workspace, _: &ToggleIgnoreBreakpoints, _, cx| {
let debug_panel = workspace.panel::<DebugPanel>(cx).unwrap(); if let Some(debug_panel) = workspace.panel::<DebugPanel>(cx) {
if let Some(active_item) = debug_panel.read_with(cx, |panel, cx| { if let Some(active_item) = debug_panel.read_with(cx, |panel, cx| {
panel panel
.active_session(cx) .active_session(cx)
@ -124,6 +123,7 @@ pub fn init(cx: &mut App) {
}) { }) {
active_item.update(cx, |item, cx| item.toggle_ignore_breakpoints(cx)) active_item.update(cx, |item, cx| item.toggle_ignore_breakpoints(cx))
} }
}
}) })
.register_action( .register_action(
|workspace: &mut Workspace, _: &ShutdownDebugAdapters, _window, cx| { |workspace: &mut Workspace, _: &ShutdownDebugAdapters, _window, cx| {
@ -136,7 +136,7 @@ pub fn init(cx: &mut App) {
) )
.register_action( .register_action(
|workspace: &mut Workspace, _: &CreateDebuggingSession, window, cx| { |workspace: &mut Workspace, _: &CreateDebuggingSession, window, cx| {
let debug_panel = workspace.panel::<DebugPanel>(cx).unwrap(); if let Some(debug_panel) = workspace.panel::<DebugPanel>(cx) {
let weak_panel = debug_panel.downgrade(); let weak_panel = debug_panel.downgrade();
let weak_workspace = cx.weak_entity(); let weak_workspace = cx.weak_entity();
@ -149,6 +149,7 @@ pub fn init(cx: &mut App) {
cx, cx,
) )
}); });
}
}, },
); );
}) })