diff --git a/src/cascadia/LocalTests_TerminalApp/SettingsTests.cpp b/src/cascadia/LocalTests_TerminalApp/SettingsTests.cpp index d243f7517a5..a2c2cf26d8a 100644 --- a/src/cascadia/LocalTests_TerminalApp/SettingsTests.cpp +++ b/src/cascadia/LocalTests_TerminalApp/SettingsTests.cpp @@ -1280,11 +1280,11 @@ namespace TerminalAppLocalTests "guid": "{6239a42c-6666-49a3-80bd-e8fdd045185c}" }, { - "name" : "Ubuntu", - "guid" : "{2C4DE342-38B7-51CF-B940-2309A097F518}" + "name" : "ThisProfileShouldNotThrow" }, { - "name" : "ThisProfileShouldNotCrash" + "name" : "Ubuntu", + "guid" : "{2C4DE342-38B7-51CF-B940-2309A097F518}" } ] })" }; @@ -1292,11 +1292,13 @@ namespace TerminalAppLocalTests auto name0{ L"profile0" }; auto name1{ L"profile1" }; auto name2{ L"Ubuntu" }; + auto name3{ L"ThisProfileShouldNotThrow" }; auto badName{ L"DoesNotExist" }; auto guid0{ Microsoft::Console::Utils::GuidFromString(L"{6239a42c-5555-49a3-80bd-e8fdd045185c}") }; auto guid1{ Microsoft::Console::Utils::GuidFromString(L"{6239a42c-6666-49a3-80bd-e8fdd045185c}") }; auto guid2{ Microsoft::Console::Utils::GuidFromString(L"{2C4DE342-38B7-51CF-B940-2309A097F518}") }; + auto fakeGuid{ Microsoft::Console::Utils::GuidFromString(L"{FFFFFFFF-FFFF-FFFF-FFFF-FFFFFFFFFFFF}") }; std::optional badGuid{}; VerifyParseSucceeded(settings0String); @@ -1308,22 +1310,19 @@ namespace TerminalAppLocalTests VERIFY_ARE_EQUAL(guid0, settings.FindGuid(name0)); VERIFY_ARE_EQUAL(guid1, settings.FindGuid(name1)); VERIFY_ARE_EQUAL(guid2, settings.FindGuid(name2)); + VERIFY_ARE_EQUAL(badGuid, settings.FindGuid(name3)); VERIFY_ARE_EQUAL(badGuid, settings.FindGuid(badName)); - // Following test will fail because GetGuid throws (despite being noexcept) - // VERIFY_ARE_EQUAL(badGuid, settings.FindGuid(L"ThisProfileShouldNotCrash")); - // Following lines only work because the GUID-less profile is last auto prof0{ settings.FindProfile(guid0) }; auto prof1{ settings.FindProfile(guid1) }; auto prof2{ settings.FindProfile(guid2) }; - // Following line will fail because GetGuid throws (despite being noexcept) - // auto badProf{ settings.FindProfile(badGuid) }; + + auto badProf{ settings.FindProfile(fakeGuid) }; + VERIFY_ARE_EQUAL(badProf, nullptr); VERIFY_ARE_EQUAL(name0, prof0->GetName()); VERIFY_ARE_EQUAL(name1, prof1->GetName()); VERIFY_ARE_EQUAL(name2, prof2->GetName()); - // Following test will fail because GetGuid throws (despite being noexcept) - // VERIFY_ARE_EQUAL(badName, badProf->GetName()); } void SettingsTests::TestLayerGlobalsOnRoot() diff --git a/src/cascadia/TerminalApp/CascadiaSettings.cpp b/src/cascadia/TerminalApp/CascadiaSettings.cpp index a8058267c53..629d0007c2f 100644 --- a/src/cascadia/TerminalApp/CascadiaSettings.cpp +++ b/src/cascadia/TerminalApp/CascadiaSettings.cpp @@ -78,7 +78,12 @@ std::optional CascadiaSettings::FindGuid(const std::wstring& profileName) { if (profileName == profile.GetName()) { - profileGuid = profile.GetGuid(); + try + { + profileGuid = profile.GetGuid(); + } + CATCH_LOG(); + break; } } @@ -98,10 +103,14 @@ const Profile* CascadiaSettings::FindProfile(GUID profileGuid) const noexcept { for (auto& profile : _profiles) { - if (profile.GetGuid() == profileGuid) + try { - return &profile; + if (profile.GetGuid() == profileGuid) + { + return &profile; + } } + CATCH_LOG(); } return nullptr; } diff --git a/src/cascadia/TerminalApp/Profile.cpp b/src/cascadia/TerminalApp/Profile.cpp index d689bc6c7be..788e2b6db5d 100644 --- a/src/cascadia/TerminalApp/Profile.cpp +++ b/src/cascadia/TerminalApp/Profile.cpp @@ -138,7 +138,7 @@ bool Profile::HasSource() const noexcept return _source.has_value(); } -GUID Profile::GetGuid() const noexcept +GUID Profile::GetGuid() const { // This can throw if we never had our guid set to a legitimate value. THROW_HR_IF_MSG(E_FAIL, !_guid.has_value(), "Profile._guid always expected to have a value"); diff --git a/src/cascadia/TerminalApp/Profile.h b/src/cascadia/TerminalApp/Profile.h index 7f42641cb49..ba85b977c2e 100644 --- a/src/cascadia/TerminalApp/Profile.h +++ b/src/cascadia/TerminalApp/Profile.h @@ -64,7 +64,7 @@ class TerminalApp::Profile final bool HasGuid() const noexcept; bool HasSource() const noexcept; - GUID GetGuid() const noexcept; + GUID GetGuid() const; void SetSource(std::wstring_view sourceNamespace) noexcept; std::wstring_view GetName() const noexcept; bool HasConnectionType() const noexcept;