From df3a79ee5424d2ba08a7dd4ad815a844956524f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Araujo?= Date: Tue, 20 Jun 2023 08:36:54 -0400 Subject: [PATCH 1/2] Add error message when trying to Update-Help in a Linux system with C.UTF-8 culture (issue 19765). --- .../help/UpdateHelpCommand.cs | 11 +++++++++++ .../resources/HelpDisplayStrings.resx | 3 +++ .../engine/Help/UpdatableHelpSystem.Tests.ps1 | 6 ++++++ 3 files changed, 20 insertions(+) diff --git a/src/System.Management.Automation/help/UpdateHelpCommand.cs b/src/System.Management.Automation/help/UpdateHelpCommand.cs index 236ec2877db..fb968069751 100644 --- a/src/System.Management.Automation/help/UpdateHelpCommand.cs +++ b/src/System.Management.Automation/help/UpdateHelpCommand.cs @@ -7,6 +7,7 @@ using System.Diagnostics.CodeAnalysis; using System.Globalization; using System.IO; +using System.Linq; using System.Management.Automation; using System.Management.Automation.Help; using System.Management.Automation.Internal; @@ -181,6 +182,16 @@ protected override void ProcessRecord() _isInitialized = true; } + + // check if there is an UI, if not Throw out terminating error. + var cultures = _language ?? _helpSystem.GetCurrentUICulture(); + if (!cultures.Any()) + { + string cultureString = string.IsNullOrEmpty(CultureInfo.CurrentCulture.Name) ? CultureInfo.CurrentCulture.DisplayName : CultureInfo.CurrentCulture.Name; + string errMsg = StringUtil.Format(HelpDisplayStrings.FailedToUpdateHelpWithLocaleNoUICulture, cultureString); + ErrorRecord error = new ErrorRecord(new InvalidOperationException(errMsg), "FailedToUpdateHelpWithLocaleNoUICulture", ErrorCategory.InvalidOperation, null); + ThrowTerminatingError(error); + } base.Process(_module, FullyQualifiedModule); diff --git a/src/System.Management.Automation/resources/HelpDisplayStrings.resx b/src/System.Management.Automation/resources/HelpDisplayStrings.resx index 8656518d531..1bacf906961 100644 --- a/src/System.Management.Automation/resources/HelpDisplayStrings.resx +++ b/src/System.Management.Automation/resources/HelpDisplayStrings.resx @@ -392,6 +392,9 @@ English-US help content is available and can be saved using: Save-Help -UICultur Failed to update Help for the module(s) '{0}' with UI culture(s) {{{1}}} : {2}. English-US help content is available and can be installed using: Update-Help -UICulture en-US. + + Your current culture is ({0}), which is not associated with any language, consider changing your system culture or install the English-US help content using: Update-Help -UICulture en-US. + false diff --git a/test/powershell/engine/Help/UpdatableHelpSystem.Tests.ps1 b/test/powershell/engine/Help/UpdatableHelpSystem.Tests.ps1 index c1d01f6476b..439dc3be989 100644 --- a/test/powershell/engine/Help/UpdatableHelpSystem.Tests.ps1 +++ b/test/powershell/engine/Help/UpdatableHelpSystem.Tests.ps1 @@ -417,6 +417,12 @@ Describe "Validate 'Update-Help' shows 'HelpCultureNotSupported' when thrown" -T @{ 'name' = 'explicit culture de-DE'; 'culture' = 'de-DE' } ) { param ($name, $culture) + + # if running in Linux as an invariant culture => force Spanish + if ($IsLinux && $culture -eq $null && (Get-Culture).LCID -eq 127 ){ + $culture = 'es-ES' + } + # Cannot pass null, have to splat to skip argument entirely $cultureArg = $culture ? @{ 'UICulture' = $culture } : @{} $cultureUsed = $culture ?? (Get-Culture) From 25b32ff3e86d048a68c319518a8bfd95080ea366 Mon Sep 17 00:00:00 2001 From: Aditya Patwardhan Date: Tue, 20 Jun 2023 07:58:01 -0700 Subject: [PATCH 2/2] Update src/System.Management.Automation/help/UpdateHelpCommand.cs --- src/System.Management.Automation/help/UpdateHelpCommand.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/System.Management.Automation/help/UpdateHelpCommand.cs b/src/System.Management.Automation/help/UpdateHelpCommand.cs index fb968069751..9df82699a32 100644 --- a/src/System.Management.Automation/help/UpdateHelpCommand.cs +++ b/src/System.Management.Automation/help/UpdateHelpCommand.cs @@ -189,7 +189,7 @@ protected override void ProcessRecord() { string cultureString = string.IsNullOrEmpty(CultureInfo.CurrentCulture.Name) ? CultureInfo.CurrentCulture.DisplayName : CultureInfo.CurrentCulture.Name; string errMsg = StringUtil.Format(HelpDisplayStrings.FailedToUpdateHelpWithLocaleNoUICulture, cultureString); - ErrorRecord error = new ErrorRecord(new InvalidOperationException(errMsg), "FailedToUpdateHelpWithLocaleNoUICulture", ErrorCategory.InvalidOperation, null); + ErrorRecord error = new ErrorRecord(new InvalidOperationException(errMsg), "FailedToUpdateHelpWithLocaleNoUICulture", ErrorCategory.InvalidOperation, targetObject: null); ThrowTerminatingError(error); }