Skip to content

Commit

Permalink
Fix "Element not found" error during settings loading (microsoft#12687)
Browse files Browse the repository at this point in the history
This commit fixes a stray exception during settings loading,
caused by a failure to obtain the app's extension catalog.

## PR Checklist
* [x] Closes microsoft#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 microsoft#12305 with which
the function causing the exception could be determined.
  • Loading branch information
lhecker authored Mar 14, 2022
1 parent f0c2ef3 commit 9c6ec75
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
1 change: 1 addition & 0 deletions .github/actions/spelling/expect/expect.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2575,6 +2575,7 @@ uuidv
UVWX
UVWXY
UWA
UWAs
uwp
uxtheme
vals
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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)
{
Expand Down

0 comments on commit 9c6ec75

Please sign in to comment.