Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add error messages for DSC configuration in summary page #2183

Merged
merged 3 commits into from
Jan 29, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public async Task OpenConfigurationSetAsync(string filePath, string content)
_configSet = openResult.Set;
if (_configSet == null)
{
throw new OpenConfigurationSetException(openResult.ResultCode, openResult.Field);
throw new OpenConfigurationSetException(openResult.ResultCode, openResult.Field, openResult.Value);
}

// Set input file path in the configuration set to inform the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,8 @@

namespace DevHome.SetupFlow.Common.Exceptions;

public class OpenConfigurationSetException : Exception
public class OpenConfigurationSetException : WinGetConfigurationException
{
// Open configuration error codes:
// Reference: https://github.com/microsoft/winget-cli/blob/master/src/AppInstallerSharedLib/Public/AppInstallerErrors.h
public const int WingetConfigErrorInvalidConfigurationFile = unchecked((int)0x8A15C001);
public const int WingetConfigErrorInvalidYaml = unchecked((int)0x8A15C002);
public const int WingetConfigErrorInvalidField = unchecked((int)0x8A15C003);
public const int WingetConfigErrorUnknownConfigurationFileVersion = unchecked((int)0x8A15C004);

/// <summary>
/// Gets the <see cref="OpenConfigurationSetResult.ResultCode"/>
/// </summary>
Expand All @@ -24,16 +17,25 @@ public Exception ResultCode
}

/// <summary>
/// Gets the <see cref="OpenConfigurationSetResult.Field"/>
/// Gets the field that is missing/invalid, if appropriate for the specific ResultCode.
/// </summary>
public string Field
{
get;
}

public OpenConfigurationSetException(Exception resultCode, string field)
/// <summary>
/// Gets the value of the field, if appropriate for the specific ResultCode.
/// </summary>
public string Value
{
get;
}

public OpenConfigurationSetException(Exception resultCode, string field, string value)
{
ResultCode = resultCode;
Field = field;
Value = value;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// Copyright (c) Microsoft Corporation and Contributors
// Licensed under the MIT license.

using System;

namespace DevHome.SetupFlow.Common.Exceptions;

public class WinGetConfigurationException : Exception
{
// WinGet Configuration error codes:
// https://github.com/microsoft/winget-cli/blob/master/src/PowerShell/Microsoft.WinGet.Configuration.Engine/Exceptions/ErrorCodes.cs
public const int WingetConfigErrorInvalidConfigurationFile = unchecked((int)0x8A15C001);
public const int WingetConfigErrorInvalidYaml = unchecked((int)0x8A15C002);
public const int WingetConfigErrorInvalidFieldType = unchecked((int)0x8A15C003);
public const int WingetConfigErrorUnknownConfigurationFileVersion = unchecked((int)0x8A15C004);
public const int WingetConfigErrorSetApplyFailed = unchecked((int)0x8A15C005);
public const int WingetConfigErrorDuplicateIdentifier = unchecked((int)0x8A15C006);
public const int WingetConfigErrorMissingDependency = unchecked((int)0x8A15C007);
public const int WingetConfigErrorDependencyUnsatisfied = unchecked((int)0x8A15C008);
public const int WingetConfigErrorAssertionFailed = unchecked((int)0x8A15C009);
public const int WingetConfigErrorManuallySkipped = unchecked((int)0x8A15C00A);
public const int WingetConfigErrorWarningNotAccepted = unchecked((int)0x8A15C00B);
public const int WingetConfigErrorSetDependencyCycle = unchecked((int)0x8A15C00C);
public const int WingetConfigErrorInvalidFieldValue = unchecked((int)0x8A15C00D);
public const int WingetConfigErrorMissingField = unchecked((int)0x8A15C00E);

// WinGet Configuration unit error codes:
public const int WinGetConfigUnitNotFound = unchecked((int)0x8A15C101);
public const int WinGetConfigUnitNotFoundRepository = unchecked((int)0x8A15C102);
public const int WinGetConfigUnitMultipleMatches = unchecked((int)0x8A15C103);
public const int WinGetConfigUnitInvokeGet = unchecked((int)0x8A15C104);
public const int WinGetConfigUnitInvokeTest = unchecked((int)0x8A15C105);
public const int WinGetConfigUnitInvokeSet = unchecked((int)0x8A15C106);
public const int WinGetConfigUnitModuleConflict = unchecked((int)0x8A15C107);
public const int WinGetConfigUnitImportModule = unchecked((int)0x8A15C108);
public const int WinGetConfigUnitInvokeInvalidResult = unchecked((int)0x8A15C109);
public const int WinGetConfigUnitSettingConfigRoot = unchecked((int)0x8A15C110);
public const int WinGetConfigUnitImportModuleAdmin = unchecked((int)0x8A15C111);
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Copyright (c) Microsoft Corporation and Contributors
// Licensed under the MIT license.

using Microsoft.Management.Configuration;

namespace DevHome.SetupFlow.ElevatedComponent.Helpers;

/// <summary>
Expand All @@ -19,4 +21,8 @@ public sealed class ElevatedConfigureUnitTaskResult
public bool IsSkipped { get; set; }

public int HResult { get; set; }

public int ResultSource { get; set; }

public string? Details { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public IAsyncOperation<ElevatedConfigureTaskResult> ApplyConfiguration(string fi
Intent = unitResult.Unit.Intent.ToString(),
IsSkipped = unitResult.State == ConfigurationUnitState.Skipped,
HResult = unitResult.ResultInformation?.ResultCode?.HResult ?? HRESULT.S_OK,
ResultSource = (int)(unitResult.ResultInformation?.ResultSource ?? ConfigurationUnitResultSource.None),
};
}).ToList();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ public ConfigurationUnitResult(ApplyConfigurationUnitResult result)
Intent = result.Unit.Intent.ToString();
IsSkipped = result.State == ConfigurationUnitState.Skipped;
HResult = result.ResultInformation?.ResultCode?.HResult ?? HRESULT.S_OK;
ResultSource = result.ResultInformation?.ResultSource ?? ConfigurationUnitResultSource.None;
Details = result.ResultInformation.Details;
AmelBawa-msft marked this conversation as resolved.
Show resolved Hide resolved
AmelBawa-msft marked this conversation as resolved.
Show resolved Hide resolved
}

public ConfigurationUnitResult(ElevatedConfigureUnitTaskResult result)
Expand All @@ -28,7 +30,9 @@ public ConfigurationUnitResult(ElevatedConfigureUnitTaskResult result)
Description = result.Description;
Intent = result.Intent;
IsSkipped = result.IsSkipped;
HResult = result.HResult;
HResult = result.HResult;
ResultSource = (ConfigurationUnitResultSource)result.ResultSource;
Details = result.Details;
}

public string UnitName { get; }
Expand All @@ -42,4 +46,8 @@ public ConfigurationUnitResult(ElevatedConfigureUnitTaskResult result)
public bool IsSkipped { get; }

public int HResult { get; }

public ConfigurationUnitResultSource ResultSource { get; }

public string Details { get; }
}
35 changes: 30 additions & 5 deletions tools/SetupFlow/DevHome.SetupFlow/Services/StringResourceKey.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,6 @@ public static class StringResourceKey
public static readonly string ConfigurationFileApplySuccess = nameof(ConfigurationFileApplySuccess);
public static readonly string ConfigurationFileApplySuccessReboot = nameof(ConfigurationFileApplySuccessReboot);
public static readonly string ConfigurationFileApplying = nameof(ConfigurationFileApplying);
public static readonly string ConfigurationFieldInvalid = nameof(ConfigurationFieldInvalid);
public static readonly string ConfigurationFileInvalid = nameof(ConfigurationFileInvalid);
public static readonly string ConfigurationFileOpenUnknownError = nameof(ConfigurationFileOpenUnknownError);
public static readonly string ConfigurationFileVersionUnknown = nameof(ConfigurationFileVersionUnknown);
public static readonly string ConfigurationFileTypeNotSupported = nameof(ConfigurationFileTypeNotSupported);
public static readonly string ConfigurationUnitFailed = nameof(ConfigurationUnitFailed);
public static readonly string ConfigurationUnitSkipped = nameof(ConfigurationUnitSkipped);
public static readonly string ConfigurationUnitSuccess = nameof(ConfigurationUnitSuccess);
Expand Down Expand Up @@ -176,4 +171,34 @@ public static class StringResourceKey
public static readonly string InstallPackageErrorNoApplicableInstallers = nameof(InstallPackageErrorNoApplicableInstallers);
public static readonly string InstallPackageErrorUnknownErrorWithErrorCode = nameof(InstallPackageErrorUnknownErrorWithErrorCode);
public static readonly string InstallPackageErrorUnknownErrorWithErrorCodeAndExitCode = nameof(InstallPackageErrorUnknownErrorWithErrorCodeAndExitCode);

// WinGet Configuration
public static readonly string ConfigurationFieldInvalidType = nameof(ConfigurationFieldInvalidType);
public static readonly string ConfigurationFieldInvalidValue = nameof(ConfigurationFieldInvalidValue);
public static readonly string ConfigurationFieldMissing = nameof(ConfigurationFieldMissing);
public static readonly string ConfigurationFileInvalid = nameof(ConfigurationFileInvalid);
public static readonly string ConfigurationFileOpenUnknownError = nameof(ConfigurationFileOpenUnknownError);
public static readonly string ConfigurationFileVersionUnknown = nameof(ConfigurationFileVersionUnknown);
public static readonly string ConfigurationUnitHasDuplicateIdentifier = nameof(ConfigurationUnitHasDuplicateIdentifier);
public static readonly string ConfigurationUnitHasMissingDependency = nameof(ConfigurationUnitHasMissingDependency);
public static readonly string ConfigurationUnitAssertHadNegativeResult = nameof(ConfigurationUnitAssertHadNegativeResult);
public static readonly string ConfigurationUnitNotFoundInModule = nameof(ConfigurationUnitNotFoundInModule);
public static readonly string ConfigurationUnitNotFound = nameof(ConfigurationUnitNotFound);
public static readonly string ConfigurationUnitMultipleMatches = nameof(ConfigurationUnitMultipleMatches);
public static readonly string ConfigurationUnitFailedDuringGet = nameof(ConfigurationUnitFailedDuringGet);
public static readonly string ConfigurationUnitFailedDuringTest = nameof(ConfigurationUnitFailedDuringTest);
public static readonly string ConfigurationUnitFailedDuringSet = nameof(ConfigurationUnitFailedDuringSet);
public static readonly string ConfigurationUnitModuleConflict = nameof(ConfigurationUnitModuleConflict);
public static readonly string ConfigurationUnitModuleImportFailed = nameof(ConfigurationUnitModuleImportFailed);
public static readonly string ConfigurationUnitReturnedInvalidResult = nameof(ConfigurationUnitReturnedInvalidResult);
public static readonly string ConfigurationUnitManuallySkipped = nameof(ConfigurationUnitManuallySkipped);
public static readonly string ConfigurationUnitNotRunDueToDependency = nameof(ConfigurationUnitNotRunDueToDependency);
public static readonly string WinGetConfigUnitSettingConfigRoot = nameof(WinGetConfigUnitSettingConfigRoot);
public static readonly string WinGetConfigUnitImportModuleAdmin = nameof(WinGetConfigUnitImportModuleAdmin);
public static readonly string ConfigurationUnitFailedConfigSet = nameof(ConfigurationUnitFailedConfigSet);
public static readonly string ConfigurationUnitFailedInternal = nameof(ConfigurationUnitFailedInternal);
public static readonly string ConfigurationUnitFailedPrecondition = nameof(ConfigurationUnitFailedPrecondition);
public static readonly string ConfigurationUnitFailedSystemState = nameof(ConfigurationUnitFailedSystemState);
public static readonly string ConfigurationUnitFailedUnitProcessing = nameof(ConfigurationUnitFailedUnitProcessing);
public static readonly string ConfigurationUnitNotRunDueToFailedAssert = nameof(ConfigurationUnitNotRunDueToFailedAssert);
}
101 changes: 93 additions & 8 deletions tools/SetupFlow/DevHome.SetupFlow/Strings/en-us/Resources.resw
Original file line number Diff line number Diff line change
Expand Up @@ -221,14 +221,6 @@
<value>View {0}</value>
<comment>{Locked="{0}"}Title for the page showing the contents of a configuration file. {0} is replaced by the configuration file name.</comment>
</data>
<data name="ConfigurationUnitFailed" xml:space="preserve">
<value>Failed: {0}</value>
<comment>{Locked="{0}"}Error message displayed when applying a configuration unit fails. {0} is replaced by an error code.</comment>
</data>
<data name="ConfigurationUnitSkipped" xml:space="preserve">
<value>Skipped: {0}</value>
<comment>{Locked="{0}"}Warning message displayed when applying a configuration unit is skipped. {0} is replaced by an error code.</comment>
</data>
<data name="ConfigurationUnitSuccess" xml:space="preserve">
<value>Configuration successfully applied</value>
<comment>Message displayed when applying a configuration unit succeeds.</comment>
Expand Down Expand Up @@ -1263,4 +1255,97 @@
<value>Add another account</value>
<comment>Menu flyout item content to add another account</comment>
</data>
<data name="ConfigurationFieldInvalidType" xml:space="preserve">
AmelBawa-msft marked this conversation as resolved.
Show resolved Hide resolved
<value>The field '{0}' in the configuration file is the wrong type.</value>
<comment>{Locked="{0}"} An error in reading a configuration file. {0} is a placeholder replaced by the field name from the file.</comment>
</data>
<data name="ConfigurationUnitAssertHadNegativeResult" xml:space="preserve">
<value>The system is not in the desired state asserted by the configuration.</value>
</data>
<data name="ConfigurationUnitFailed" xml:space="preserve">
<value>This configuration unit failed for an unknown reason: {0}</value>
<comment>{Locked="{0}"} {0} is a placeholder for the unrecognized error code.</comment>
</data>
<data name="ConfigurationUnitFailedConfigSet" xml:space="preserve">
<value>The configuration unit failed due to the configuration: {0}</value>
<comment>{Locked="{0}"} {0} is a placeholder for the unrecognized error code.</comment>
</data>
<data name="ConfigurationUnitFailedDuringGet" xml:space="preserve">
<value>The configuration unit failed while attempting to get the current system state.</value>
</data>
<data name="ConfigurationUnitFailedDuringSet" xml:space="preserve">
<value>The configuration unit failed while attempting to apply the desired state.</value>
</data>
<data name="ConfigurationUnitFailedDuringTest" xml:space="preserve">
<value>The configuration unit failed while attempting to test the current system state.</value>
</data>
<data name="ConfigurationUnitFailedInternal" xml:space="preserve">
<value>The configuration unit failed due to an internal error: {0}</value>
<comment>{Locked="{0}"} {0} is a placeholder for the unrecognized error code.</comment>
</data>
<data name="ConfigurationUnitFailedPrecondition" xml:space="preserve">
<value>The configuration unit failed due to a precondition not being valid: {0}</value>
<comment>{Locked="{0}"} {0} is a placeholder for the unrecognized error code.</comment>
</data>
<data name="ConfigurationUnitFailedSystemState" xml:space="preserve">
<value>The configuration unit failed due to the system state: {0}</value>
<comment>{Locked="{0}"} {0} is a placeholder for the unrecognized error code.</comment>
</data>
<data name="ConfigurationUnitFailedUnitProcessing" xml:space="preserve">
<value>The configuration unit failed while attempting to run: {0}</value>
<comment>{Locked="{0}"} {0} is a placeholder for the unrecognized error code.</comment>
</data>
<data name="ConfigurationUnitHasDuplicateIdentifier" xml:space="preserve">
<value>The configuration contains the identifier `{0}` multiple times.</value>
<comment>{Locked="{0}"} {0} is a placeholder that is replaced by the identifier string from the user input file.</comment>
</data>
<data name="ConfigurationUnitHasMissingDependency" xml:space="preserve">
<value>The dependency `{0}` was not found within the configuration.</value>
<comment>{Locked="{0}"} {0} is a placeholder that is replaced by the identifier string from the user input file.</comment>
</data>
<data name="ConfigurationUnitManuallySkipped" xml:space="preserve">
<value>This configuration unit was manually skipped.</value>
</data>
<data name="ConfigurationUnitModuleConflict" xml:space="preserve">
<value>The module for the configuration unit is available in multiple locations with the same version.</value>
</data>
<data name="ConfigurationUnitModuleImportFailed" xml:space="preserve">
<value>Loading the module for the configuration unit failed.</value>
</data>
<data name="ConfigurationUnitMultipleMatches" xml:space="preserve">
<value>Multiple matches were found for the configuration unit; specify the module to select the correct one.</value>
</data>
<data name="ConfigurationUnitNotFound" xml:space="preserve">
<value>The configuration unit could not be found.</value>
</data>
<data name="ConfigurationUnitNotFoundInModule" xml:space="preserve">
<value>The configuration unit was not in the module as expected.</value>
</data>
<data name="ConfigurationUnitNotRunDueToDependency" xml:space="preserve">
<value>This configuration unit was not run because a dependency failed or was not run.</value>
</data>
<data name="ConfigurationUnitReturnedInvalidResult" xml:space="preserve">
<value>The configuration unit returned an unexpected result during execution.</value>
</data>
<data name="ConfigurationUnitSkipped" xml:space="preserve">
<value>This configuration unit was not run for an unknown reason: {0}</value>
<comment>{Locked="{0}"} {0} is a placeholder for the unrecognized error code.</comment>
</data>
<data name="ConfigurationFieldInvalidValue" xml:space="preserve">
<value>The field '{0}' has an invalid value: {1}</value>
<comment>{Locked="{0}","{1}"} An error in reading a configuration file. {0} is a placeholder replaced by the field name from the file. {1} is a placeholder for the invalid value.</comment>
</data>
<data name="ConfigurationFieldMissing" xml:space="preserve">
<value>The field '{0}' is missing or empty.</value>
<comment>{Locked="{0}"} An error in reading a configuration file. {0} is a placeholder replaced by the expected field name from the file.</comment>
</data>
<data name="WinGetConfigUnitImportModuleAdmin" xml:space="preserve">
<value>Loading the module for the configuration unit failed because it requires administrator privileges to run.</value>
</data>
<data name="WinGetConfigUnitSettingConfigRoot" xml:space="preserve">
<value>A unit contains a setting that requires the config root.</value>
</data>
<data name="ConfigurationUnitNotRunDueToFailedAssert" xml:space="preserve">
<value>This configuration unit was not run because an assert failed or was false.</value>
</data>
</root>
Loading
Loading