Fix "Element not found" error during settings loading (#12687)

This commit fixes a stray exception during settings loading,
caused by a failure to obtain the app's extension catalog.

## PR Checklist
* [x] Closes #12305
* [x] I work here
* [x] Tests added/passed

## Validation Steps Performed
I'm unable to replicate the issue. 
However an error log was provided in #12305 with which
the function causing the exception could be determined.
This commit is contained in:
Leonard Hecker 2022-03-14 17:48:29 +01:00 committed by GitHub
parent f0c2ef361a
commit 9c6ec75082
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 4 deletions

View File

@ -2575,6 +2575,7 @@ uuidv
UVWX
UVWXY
UWA
UWAs
uwp
uxtheme
vals

View File

@ -27,6 +27,8 @@
#include "DefaultTerminal.h"
#include "FileUtils.h"
using namespace winrt::Windows::Foundation::Collections;
using namespace winrt::Windows::ApplicationModel::AppExtensions;
using namespace winrt::Microsoft::Terminal::Settings;
using namespace winrt::Microsoft::Terminal::Settings::Model::implementation;
@ -235,10 +237,29 @@ void SettingsLoader::FindFragmentsAndMergeIntoUserSettings()
}
}
// Search through app extensions
// Gets the catalog of extensions with the name "com.microsoft.windows.terminal.settings"
const auto catalog = winrt::Windows::ApplicationModel::AppExtensions::AppExtensionCatalog::Open(AppExtensionHostName);
const auto extensions = extractValueFromTaskWithoutMainThreadAwait(catalog.FindAllAsync());
// Search through app extensions.
// Gets the catalog of extensions with the name "com.microsoft.windows.terminal.settings".
//
// GH#12305: Open() can throw an 0x80070490 "Element not found.".
// It's unclear to me under which circumstances this happens as no one on the team
// was able to reproduce the user's issue, even if the application was run unpackaged.
// The error originates from `CallerIdentity::GetCallingProcessAppId` which returns E_NOT_SET.
// A comment can be found, reading:
// > Gets the "strong" AppId from the process token. This works for UWAs and Centennial apps,
// > strongly named processes where the AppId is stored securely in the process token. [...]
// > E_NOT_SET is returned for processes without strong AppIds.
IVectorView<AppExtension> extensions;
try
{
const auto catalog = AppExtensionCatalog::Open(AppExtensionHostName);
extensions = extractValueFromTaskWithoutMainThreadAwait(catalog.FindAllAsync());
}
CATCH_LOG();
if (!extensions)
{
return;
}
for (const auto& ext : extensions)
{