Skip to content
This repository was archived by the owner on Jun 5, 2025. It is now read-only.

Commit 770f6dc

Browse files
authored
Change exceptions thrown in setup tasks into task failures, and add more details to error logging (#1071)
1 parent 7196b9a commit 770f6dc

File tree

18 files changed

+101
-81
lines changed

18 files changed

+101
-81
lines changed

settings/DevHome.Settings/ViewModels/AccountsProviderViewModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public void RemoveAccount(string loginId)
4545
}
4646
catch (Exception ex)
4747
{
48-
GlobalLog.Logger?.ReportError($"RemoveAccount() failed - developerId: {loginId} Error: {ex}");
48+
GlobalLog.Logger?.ReportError($"RemoveAccount() failed - developerId: {loginId}.", ex);
4949
throw;
5050
}
5151
}

settings/DevHome.Settings/Views/AccountsPage.xaml.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ public async Task ShowLoginUIAsync(string loginEntryPoint, Page parentPage, Acco
122122
}
123123
catch (Exception ex)
124124
{
125-
GlobalLog.Logger?.ReportError($"ShowLoginUIAsync(): loginUIContentDialog failed - Error: {ex}");
125+
GlobalLog.Logger?.ReportError($"ShowLoginUIAsync(): loginUIContentDialog failed.", ex);
126126
}
127127

128128
accountProvider.RefreshLoggedInAccounts();
@@ -145,7 +145,7 @@ private async Task ConfigureLoginUIRenderer(AdaptiveCardRenderer renderer)
145145
}
146146
catch (Exception ex)
147147
{
148-
GlobalLog.Logger?.ReportError($"Failure occurred while retrieving the HostConfig file - Error: {ex} HostConfigFileName: {hostConfigFileName}");
148+
GlobalLog.Logger?.ReportError($"Failure occurred while retrieving the HostConfig file - HostConfigFileName: {hostConfigFileName}.", ex);
149149
}
150150

151151
// Add host config for current theme to renderer

tools/SetupFlow/DevHome.SetupFlow.Common/DevDriveFormatter/DevDriveFormatter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public int FormatPartitionAsDevDrive(char curDriveLetter, string driveLabel)
8484
}
8585
catch (ManagementException e)
8686
{
87-
Log.Logger?.ReportError(Log.Component.DevDrive, nameof(FormatPartitionAsDevDrive), $"A management exception occurred while formating Dev Drive Error: 0x{e.HResult:X}, error msg: {e.Message}");
87+
Log.Logger?.ReportError(Log.Component.DevDrive, nameof(FormatPartitionAsDevDrive), $"A management exception occurred while formating Dev Drive Error.", e);
8888
return e.HResult;
8989
}
9090
}

tools/SetupFlow/DevHome.SetupFlow.Common/Elevation/IPCSetup.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ public static (RemoteObject<T>, Process) CreateOutOfProcessObjectAndGetProcess<T
285285
}
286286
catch (Exception e)
287287
{
288-
Log.Logger?.ReportError(Log.Component.IPCClient, $"Error occuring while setting up elevated process: {e.Message}");
288+
Log.Logger?.ReportError(Log.Component.IPCClient, $"Error occuring while setting up elevated process.", e);
289289

290290
// Release the "mutex" if there is any error.
291291
// On success, the mutex will be released after work is done.
@@ -375,7 +375,7 @@ public static void CompleteRemoteObjectInitialization<T>(
375375
}
376376
catch (Exception e)
377377
{
378-
Log.Logger?.ReportError(Log.Component.IPCServer, $"Error occurred during setup: {e.Message}");
378+
Log.Logger?.ReportError(Log.Component.IPCServer, $"Error occurred during setup.", e);
379379
mappedMemory.HResult = e.HResult;
380380
}
381381

tools/SetupFlow/DevHome.SetupFlow.ElevatedComponent/Tasks/ElevatedConfigurationTask.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public IAsyncOperation<ElevatedConfigureTaskResult> ApplyConfiguration(StorageFi
4949
}
5050
catch (Exception e)
5151
{
52-
Log.Logger?.ReportError(Log.Component.Configuration, $"Failed to apply configuration: {e.Message}");
52+
Log.Logger?.ReportError(Log.Component.Configuration, $"Failed to apply configuration.", e);
5353
taskResult.TaskSucceeded = false;
5454
}
5555

tools/SetupFlow/DevHome.SetupFlow.ElevatedComponent/Tasks/ElevatedInstallTask.cs

Lines changed: 51 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Copyright (c) Microsoft Corporation and Contributors
22
// Licensed under the MIT license.
33

4+
using DevHome.Logging;
45
using DevHome.SetupFlow.Common.Extensions;
56
using DevHome.SetupFlow.Common.Helpers;
67
using DevHome.SetupFlow.Common.WindowsPackageManager;
@@ -38,53 +39,63 @@ public IAsyncOperation<ElevatedInstallTaskResult> InstallPackage(string packageI
3839
{
3940
return Task.Run(async () =>
4041
{
41-
Log.Logger?.ReportInfo(Log.Component.AppManagement, $"Elevated install requested for package [{packageId}] from catalog [{catalogName}]");
4242
var result = new ElevatedInstallTaskResult();
43-
44-
var packageManager = _wingetFactory.CreatePackageManager();
45-
46-
Log.Logger?.ReportInfo(Log.Component.AppManagement, $"Connecting to catalog [{catalogName}]");
47-
var catalogReference = packageManager.GetPackageCatalogByName(catalogName);
48-
var connectResult = await catalogReference.ConnectAsync();
49-
if (connectResult.Status != ConnectResultStatus.Ok)
43+
try
5044
{
51-
Log.Logger?.ReportError(Log.Component.AppManagement, $"Failed to connect to the catalog [{catalogName}] with status {connectResult.Status}");
52-
result.TaskAttempted = false;
45+
Log.Logger?.ReportInfo(Log.Component.AppManagement, $"Elevated install requested for package [{packageId}] from catalog [{catalogName}]");
46+
47+
var packageManager = _wingetFactory.CreatePackageManager();
48+
49+
Log.Logger?.ReportInfo(Log.Component.AppManagement, $"Connecting to catalog [{catalogName}]");
50+
var catalogReference = packageManager.GetPackageCatalogByName(catalogName);
51+
var connectResult = await catalogReference.ConnectAsync();
52+
if (connectResult.Status != ConnectResultStatus.Ok)
53+
{
54+
Log.Logger?.ReportError(Log.Component.AppManagement, $"Failed to connect to the catalog [{catalogName}] with status {connectResult.Status}");
55+
result.TaskAttempted = false;
56+
return result;
57+
}
58+
59+
Log.Logger?.ReportInfo(Log.Component.AppManagement, $"Finding package [{packageId}] in catalog");
60+
var findOptions = CreateFindOptionsForPackageId(packageId);
61+
var findResult = connectResult.PackageCatalog.FindPackages(findOptions);
62+
if (findResult.Status != FindPackagesResultStatus.Ok
63+
|| findResult.Matches.Count < 1
64+
|| findResult.WasLimitExceeded)
65+
{
66+
Log.Logger?.ReportError(Log.Component.AppManagement, $"Failed to find package. Status={findResult.Status}, Matches Count={findResult.Matches.Count}, LimitReached={findResult.WasLimitExceeded}");
67+
result.TaskAttempted = false;
68+
return result;
69+
}
70+
71+
var packageToInstall = findResult.Matches[0].CatalogPackage;
72+
73+
var installOptions = _wingetFactory.CreateInstallOptions();
74+
installOptions.PackageInstallMode = PackageInstallMode.Silent;
75+
76+
Log.Logger?.ReportInfo(Log.Component.AppManagement, $"Initiating install of package {packageId}");
77+
var installResult = await packageManager.InstallPackageAsync(packageToInstall, installOptions);
78+
var extendedErrorCode = installResult.ExtendedErrorCode?.HResult ?? HRESULT.S_OK;
79+
80+
// Contract version 4
81+
var installErrorCode = installResult.GetValueOrDefault(res => res.InstallerErrorCode, HRESULT.S_OK);
82+
83+
Log.Logger?.ReportInfo(Log.Component.AppManagement, $"Install finished. Status={installResult.Status}, InstallerErrorCode={installErrorCode}, ExtendedErrorCode={extendedErrorCode}, RebootRequired={installResult.RebootRequired}");
84+
result.TaskAttempted = true;
85+
result.TaskSucceeded = installResult.Status == InstallResultStatus.Ok;
86+
result.RebootRequired = installResult.RebootRequired;
87+
result.Status = (int)installResult.Status;
88+
result.ExtendedErrorCode = extendedErrorCode;
89+
result.InstallerErrorCode = installErrorCode;
90+
5391
return result;
5492
}
55-
56-
Log.Logger?.ReportInfo(Log.Component.AppManagement, $"Finding package [{packageId}] in catalog");
57-
var findOptions = CreateFindOptionsForPackageId(packageId);
58-
var findResult = connectResult.PackageCatalog.FindPackages(findOptions);
59-
if (findResult.Status != FindPackagesResultStatus.Ok
60-
|| findResult.Matches.Count < 1
61-
|| findResult.WasLimitExceeded)
93+
catch (Exception e)
6294
{
63-
Log.Logger?.ReportError(Log.Component.AppManagement, $"Failed to find package. Status={findResult.Status}, Matches Count={findResult.Matches.Count}, LimitReached={findResult.WasLimitExceeded}");
64-
result.TaskAttempted = false;
65-
return result;
95+
Log.Logger?.ReportError(Log.Component.AppManagement, "Elevated app install failed.", e);
96+
result.TaskSucceeded = false;
6697
}
6798

68-
var packageToInstall = findResult.Matches[0].CatalogPackage;
69-
70-
var installOptions = _wingetFactory.CreateInstallOptions();
71-
installOptions.PackageInstallMode = PackageInstallMode.Silent;
72-
73-
Log.Logger?.ReportInfo(Log.Component.AppManagement, $"Initiating install of package {packageId}");
74-
var installResult = await packageManager.InstallPackageAsync(packageToInstall, installOptions);
75-
var extendedErrorCode = installResult.ExtendedErrorCode?.HResult ?? HRESULT.S_OK;
76-
77-
// Contract version 4
78-
var installErrorCode = installResult.GetValueOrDefault(res => res.InstallerErrorCode, HRESULT.S_OK);
79-
80-
Log.Logger?.ReportInfo(Log.Component.AppManagement, $"Install finished. Status={installResult.Status}, InstallerErrorCode={installErrorCode}, ExtendedErrorCode={extendedErrorCode}, RebootRequired={installResult.RebootRequired}");
81-
result.TaskAttempted = true;
82-
result.TaskSucceeded = installResult.Status == InstallResultStatus.Ok;
83-
result.RebootRequired = installResult.RebootRequired;
84-
result.Status = (int)installResult.Status;
85-
result.ExtendedErrorCode = extendedErrorCode;
86-
result.InstallerErrorCode = installErrorCode;
87-
8899
return result;
89100
}).AsAsyncOperation();
90101
}

tools/SetupFlow/DevHome.SetupFlow/Models/ConfigureTask.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public async Task OpenConfigurationSetAsync()
5151
}
5252
catch (Exception e)
5353
{
54-
Log.Logger?.ReportError(Log.Component.Configuration, $"Failed to open configuration set: {e.Message}");
54+
Log.Logger?.ReportError(Log.Component.Configuration, $"Failed to open configuration set.", e);
5555
throw;
5656
}
5757
}
@@ -103,7 +103,7 @@ IAsyncOperation<TaskFinishedState> ISetupTask.Execute()
103103
}
104104
catch (Exception e)
105105
{
106-
Log.Logger?.ReportError(Log.Component.Configuration, $"Failed to apply configuration: {e.Message}");
106+
Log.Logger?.ReportError(Log.Component.Configuration, $"Failed to apply configuration.", e);
107107
return TaskFinishedState.Failure;
108108
}
109109
}).AsAsyncOperation();

tools/SetupFlow/DevHome.SetupFlow/Models/CreateDevDriveTask.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ IAsyncOperation<TaskFinishedState> ISetupTask.ExecuteAsAdmin(IElevatedComponentF
101101
catch (Exception ex)
102102
{
103103
result = ex.HResult;
104-
Log.Logger?.ReportError(Log.Component.DevDrive, $"Failed to create Dev Drive. Due to Exception ErrorCode: 0x{ex.HResult:X}, Msg: {ex.Message}");
104+
Log.Logger?.ReportError(Log.Component.DevDrive, $"Failed to create Dev Drive.", ex);
105105
_actionCenterMessages.PrimaryMessage = _stringResource.GetLocalized(StringResourceKey.DevDriveErrorWithReason, _stringResource.GetLocalizedErrorMsg(ex.HResult, Log.Component.DevDrive));
106106
TelemetryFactory.Get<ITelemetry>().LogException("CreatingDevDriveException", ex);
107107
return TaskFinishedState.Failure;

tools/SetupFlow/DevHome.SetupFlow/Models/GenericRepository.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public IAsyncAction CloneRepositoryAsync(string cloneDestination, IDeveloperId d
5858
}
5959
catch (NameConflictException nameConflictException)
6060
{
61-
Log.Logger?.ReportError("GenericRepository", nameConflictException);
61+
Log.Logger?.ReportError("GenericRepository", string.Empty, nameConflictException);
6262
throw;
6363
}
6464
catch (Exception e)

tools/SetupFlow/DevHome.SetupFlow/Models/InstallPackageTask.cs

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ IAsyncOperation<TaskFinishedState> ISetupTask.Execute()
123123
catch (Exception e)
124124
{
125125
ReportAppInstallFailedEvent();
126-
Log.Logger?.ReportError(Log.Component.AppManagement, $"Exception thrown while installing package: {e.Message}");
126+
Log.Logger?.ReportError(Log.Component.AppManagement, $"Exception thrown while installing package.", e);
127127
return TaskFinishedState.Failure;
128128
}
129129
}).AsAsyncOperation();
@@ -134,23 +134,32 @@ IAsyncOperation<TaskFinishedState> ISetupTask.ExecuteAsAdmin(IElevatedComponentF
134134
ReportAppSelectedForInstallEvent();
135135
return Task.Run(async () =>
136136
{
137-
Log.Logger?.ReportInfo(Log.Component.AppManagement, $"Starting installation with elevation of package {_package.Id}");
138-
var elevatedTask = elevatedComponentFactory.CreateElevatedInstallTask();
139-
var elevatedResult = await elevatedTask.InstallPackage(_package.Id, _package.CatalogName);
140-
WasInstallSuccessful = elevatedResult.TaskSucceeded;
141-
RequiresReboot = elevatedResult.RebootRequired;
142-
_installResultStatus = (InstallResultStatus)elevatedResult.Status;
143-
_extendedErrorCode = elevatedResult.ExtendedErrorCode;
144-
_installerErrorCode = elevatedResult.InstallerErrorCode;
145-
146-
if (elevatedResult.TaskSucceeded)
137+
try
147138
{
148-
ReportAppInstallSucceededEvent();
149-
return TaskFinishedState.Success;
139+
Log.Logger?.ReportInfo(Log.Component.AppManagement, $"Starting installation with elevation of package {_package.Id}");
140+
var elevatedTask = elevatedComponentFactory.CreateElevatedInstallTask();
141+
var elevatedResult = await elevatedTask.InstallPackage(_package.Id, _package.CatalogName);
142+
WasInstallSuccessful = elevatedResult.TaskSucceeded;
143+
RequiresReboot = elevatedResult.RebootRequired;
144+
_installResultStatus = (InstallResultStatus)elevatedResult.Status;
145+
_extendedErrorCode = elevatedResult.ExtendedErrorCode;
146+
_installerErrorCode = elevatedResult.InstallerErrorCode;
147+
148+
if (elevatedResult.TaskSucceeded)
149+
{
150+
ReportAppInstallSucceededEvent();
151+
return TaskFinishedState.Success;
152+
}
153+
else
154+
{
155+
ReportAppInstallFailedEvent();
156+
return TaskFinishedState.Failure;
157+
}
150158
}
151-
else
159+
catch (Exception e)
152160
{
153161
ReportAppInstallFailedEvent();
162+
Log.Logger?.ReportError(Log.Component.AppManagement, $"Exception thrown while installing package.", e);
154163
return TaskFinishedState.Failure;
155164
}
156165
}).AsAsyncOperation();

0 commit comments

Comments
 (0)