Repository: microsoft/terminal (language: cpp)

Issue:
Deleting all profiles crashes Windows Terminal
### Windows Terminal version

1.13.11373.0

### Windows build number

_No response_

### Other Software

_No response_

### Steps to reproduce

1. Delete all profiles

### Expected Behavior

* Shouldn't crash

### Actual Behavior

* Crash


Discussion / hints:
A few quick thoughts...
1. this is probably relatively new behavior now that you're allowed to delete _any_ profile (instead of just the custom ones, since we blocked deleting CMD before state.json got added)
2. back in the JSON-only days, we would throw a warning/error and (I believe) fallback to the default settings
3. Wouldn't this be a case of "play stupid games..."? 100% agree we shouldn't crash, but I feel like solution would be that we fallback to the default settings (like before) until you fix it, but then that might cause a weird state with the SUI. I'm just concerned we'd need major changes to fix a crash that presumably very few (if any) people are accidentally hitting.
Is this perhaps the same thing as #13017?
No those are separate issues as far as I can tell. #13017 occurred when you saved your settings and you deleted a profile afterwards. Due to a bug in the UI code it crashed.

But I noticed that we also crash if you simply delete all profiles.

Fix patch:
diff --git a/src/cascadia/TerminalSettingsEditor/MainPage.cpp b/src/cascadia/TerminalSettingsEditor/MainPage.cpp
index 5bb04d603de..2009502c569 100644
--- a/src/cascadia/TerminalSettingsEditor/MainPage.cpp
+++ b/src/cascadia/TerminalSettingsEditor/MainPage.cpp
@@ -594,7 +594,15 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
         // navigate to the profile next to this one
         const auto newSelectedItem{ menuItems.GetAt(index < menuItems.Size() - 1 ? index : index - 1) };
         SettingsNav().SelectedItem(newSelectedItem);
-        _Navigate(newSelectedItem.try_as<MUX::Controls::NavigationViewItem>().Tag().try_as<Editor::ProfileViewModel>(), BreadcrumbSubPage::None, true);
+        const auto newTag = newSelectedItem.as<MUX::Controls::NavigationViewItem>().Tag();
+        if (const auto profileViewModel = newTag.try_as<ProfileViewModel>())
+        {
+            _Navigate(*profileViewModel, BreadcrumbSubPage::None);
+        }
+        else
+        {
+            _Navigate(newTag.as<hstring>(), BreadcrumbSubPage::None);
+        }
     }
 
     IObservableVector<IInspectable> MainPage::Breadcrumbs() noexcept


Test patch: