Skip to content

Commit

Permalink
Append DSC error description messages when applicable (#2197)
Browse files Browse the repository at this point in the history
  • Loading branch information
AmelBawa-msft authored Jan 31, 2024
1 parent 73f7ef4 commit db103eb
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public sealed class ElevatedConfigureUnitTaskResult

public string? Id { get; set; }

public string? Description { get; set; }
public string? UnitDescription { get; set; }

public string? Intent { get; set; }

Expand All @@ -25,4 +25,6 @@ public sealed class ElevatedConfigureUnitTaskResult
public int ResultSource { get; set; }

public string? Details { get; set; }

public string? ErrorDescription { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,12 @@ public IAsyncOperation<ElevatedConfigureTaskResult> ApplyConfiguration(string fi
{
UnitName = unitResult.Unit.UnitName,
Id = unitResult.Unit.Identifier,
Description = descriptionObj?.ToString() ?? string.Empty,
UnitDescription = descriptionObj?.ToString() ?? string.Empty,
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),
ErrorDescription = unitResult.ResultInformation?.Description,
};
}).ToList();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,31 +15,35 @@ public ConfigurationUnitResult(ApplyConfigurationUnitResult result)
UnitName = result.Unit.UnitName;
Id = result.Unit.Identifier;
result.Unit.Directives.TryGetValue("description", out var descriptionObj);
Description = descriptionObj?.ToString() ?? string.Empty;
UnitDescription = descriptionObj?.ToString() ?? string.Empty;
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;
ErrorDescription = result.ResultInformation?.Description;
}

public ConfigurationUnitResult(ElevatedConfigureUnitTaskResult result)
{
UnitName = result.UnitName;
Id = result.Id;
Description = result.Description;
UnitDescription = result.UnitDescription;
Intent = result.Intent;
IsSkipped = result.IsSkipped;
HResult = result.HResult;
ResultSource = (ConfigurationUnitResultSource)result.ResultSource;
Details = result.Details;
ErrorDescription = result.ErrorDescription;
}

public string UnitName { get; }

public string Id { get; }

public string Description { get; }
public string UnitDescription { get; }

public string ErrorDescription { get; }

public string Intent { get; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ namespace DevHome.SetupFlow.ViewModels;
public class ConfigurationUnitResultViewModel
{
private readonly ConfigurationUnitResult _unitResult;
private readonly ISetupFlowStringResource _stringResource;
private readonly ISetupFlowStringResource _stringResource;

public ConfigurationUnitResultViewModel(ISetupFlowStringResource stringResource, ConfigurationUnitResult unitResult)
{
Expand All @@ -33,13 +33,15 @@ public ConfigurationUnitResultViewModel(ISetupFlowStringResource stringResource,
public string Title => BuildTitle();

public string ApplyResult => GetApplyResult();

public string ErrorDescription => GetErrorDescription();

public bool IsSkipped => _unitResult.IsSkipped;

public bool IsError => !IsSkipped && _unitResult.HResult != HRESULT.S_OK;

public bool IsSuccess => _unitResult.HResult == HRESULT.S_OK;


private string GetApplyResult()
{
if (IsSkipped)
Expand All @@ -57,22 +59,22 @@ private string GetApplyResult()

private string BuildTitle()
{
if (string.IsNullOrEmpty(_unitResult.Id) && string.IsNullOrEmpty(_unitResult.Description))
if (string.IsNullOrEmpty(_unitResult.Id) && string.IsNullOrEmpty(_unitResult.UnitDescription))
{
return _stringResource.GetLocalized(StringResourceKey.ConfigurationUnitSummaryMinimal, _unitResult.Intent, _unitResult.UnitName);
}

if (string.IsNullOrEmpty(_unitResult.Id))
{
return _stringResource.GetLocalized(StringResourceKey.ConfigurationUnitSummaryNoId, _unitResult.Intent, _unitResult.UnitName, _unitResult.Description);
return _stringResource.GetLocalized(StringResourceKey.ConfigurationUnitSummaryNoId, _unitResult.Intent, _unitResult.UnitName, _unitResult.UnitDescription);
}

if (string.IsNullOrEmpty(_unitResult.Description))
if (string.IsNullOrEmpty(_unitResult.UnitDescription))
{
return _stringResource.GetLocalized(StringResourceKey.ConfigurationUnitSummaryNoDescription, _unitResult.Intent, _unitResult.UnitName, _unitResult.Id);
}

return _stringResource.GetLocalized(StringResourceKey.ConfigurationUnitSummaryFull, _unitResult.Intent, _unitResult.UnitName, _unitResult.Id, _unitResult.Description);
return _stringResource.GetLocalized(StringResourceKey.ConfigurationUnitSummaryFull, _unitResult.Intent, _unitResult.UnitName, _unitResult.Id, _unitResult.UnitDescription);
}

private string GetUnitSkipMessage()
Expand Down Expand Up @@ -147,5 +149,34 @@ private string GetUnitErrorMessage()
}

return _stringResource.GetLocalized(StringResourceKey.ConfigurationUnitFailed, resultCodeHex);
}
}

private string GetErrorDescription()
{
if (string.IsNullOrEmpty(_unitResult.ErrorDescription))
{
return string.Empty;
}

// If the localized configuration error message requires additional
// context, display the error description from the resource module directly.
// Code reference: https://github.com/microsoft/winget-cli/blob/master/src/AppInstallerCLICore/Workflows/ConfigurationFlow.cpp
switch (_unitResult.HResult)
{
case WinGetConfigurationException.WingetConfigErrorDuplicateIdentifier:
case WinGetConfigurationException.WingetConfigErrorMissingDependency:
case WinGetConfigurationException.WingetConfigErrorAssertionFailed:
case WinGetConfigurationException.WinGetConfigUnitNotFound:
case WinGetConfigurationException.WinGetConfigUnitNotFoundRepository:
case WinGetConfigurationException.WinGetConfigUnitMultipleMatches:
case WinGetConfigurationException.WinGetConfigUnitModuleConflict:
case WinGetConfigurationException.WinGetConfigUnitImportModule:
case WinGetConfigurationException.WinGetConfigUnitInvokeInvalidResult:
case WinGetConfigurationException.WinGetConfigUnitSettingConfigRoot:
case WinGetConfigurationException.WinGetConfigUnitImportModuleAdmin:
return string.Empty;
default:
return _unitResult.ErrorDescription;
}
}
}
28 changes: 18 additions & 10 deletions tools/SetupFlow/DevHome.SetupFlow/Views/SummaryView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="ms-appx:///DevHome.SetupFlow/Styles/SetupFlowStyles.xaml"/>
<ResourceDictionary>
<converters:StringVisibilityConverter x:Key="StringVisibilityConverter" />
<converters:CollectionVisibilityConverter x:Key="CollectionVisibilityConverter" EmptyValue="Collapsed" NotEmptyValue="Visible"/>
<converters:CollectionVisibilityConverter x:Key="NegatedCollectionVisibilityConverter" EmptyValue="Visible" NotEmptyValue="Collapsed"/>
<converters:EmptyCollectionToObjectConverter x:Key="EmptyCollectionWillNotSpanColumnsConverter" EmptyValue="0" NotEmptyValue="*"/>
Expand Down Expand Up @@ -144,22 +145,29 @@
<Setter Property="FontFamily" Value="{StaticResource CascadiaMonoFontFamily}"/>
<Setter Property="Foreground" Value="{ThemeResource TextFillColorSecondaryBrush}"/>
<Setter Property="LineHeight" Value="20"/>
<Setter Property="TextWrapping" Value="Wrap"/>
<Setter Property="IsTextSelectionEnabled" Value="True"/>
</Style>
</ItemsRepeater.Resources>
<ItemsRepeater.ItemTemplate>
<DataTemplate x:DataType="viewModels:ConfigurationUnitResultViewModel">
<StackPanel>
<TextBlock Text="{x:Bind Title}"/>
<TextBlock Margin="20,0,0,0" Text="{x:Bind ApplyResult}" IsTextSelectionEnabled="{x:Bind IsError}">
<i:Interaction.Behaviors>
<ic:DataTriggerBehavior Binding="{x:Bind IsError}" Value="True">
<ic:ChangePropertyAction PropertyName="Foreground" Value="{ThemeResource SystemFillColorCriticalBrush}"/>
</ic:DataTriggerBehavior>
<ic:DataTriggerBehavior Binding="{x:Bind IsSkipped}" Value="True">
<ic:ChangePropertyAction PropertyName="Foreground" Value="{ThemeResource SystemFillColorCautionBrush}"/>
</ic:DataTriggerBehavior>
</i:Interaction.Behaviors>
</TextBlock>
<StackPanel Margin="20,0,0,0">
<TextBlock Text="{x:Bind ApplyResult}">
<i:Interaction.Behaviors>
<ic:DataTriggerBehavior Binding="{x:Bind IsError}" Value="True">
<ic:ChangePropertyAction PropertyName="Foreground" Value="{ThemeResource SystemFillColorCriticalBrush}"/>
</ic:DataTriggerBehavior>
<ic:DataTriggerBehavior Binding="{x:Bind IsSkipped}" Value="True">
<ic:ChangePropertyAction PropertyName="Foreground" Value="{ThemeResource SystemFillColorCautionBrush}"/>
</ic:DataTriggerBehavior>
</i:Interaction.Behaviors>
</TextBlock>
<TextBlock Text="{x:Bind ErrorDescription}"
Foreground="{ThemeResource SystemFillColorCriticalBrush}"
Visibility="{x:Bind ErrorDescription, Converter={StaticResource StringVisibilityConverter}}"/>
</StackPanel>
</StackPanel>
</DataTemplate>
</ItemsRepeater.ItemTemplate>
Expand Down

0 comments on commit db103eb

Please sign in to comment.