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

Make Update-Help throw proper error when current culture is not associated with a language #19765

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Add error message when trying to Update-Help in a Linux system with C…
….UTF-8 culture (issue 19765).
  • Loading branch information
josea committed Jun 20, 2023
commit df3a79ee5424d2ba08a7dd4ad815a844956524f8
11 changes: 11 additions & 0 deletions src/System.Management.Automation/help/UpdateHelpCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
adityapatwardhan marked this conversation as resolved.
Show resolved Hide resolved
ThrowTerminatingError(error);
}

base.Process(_module, FullyQualifiedModule);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,9 @@ English-US help content is available and can be saved using: Save-Help -UICultur
<value>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.</value>
</data>
<data name="FailedToUpdateHelpWithLocaleNoUICulture" xml:space="preserve">
<value>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.</value>
</data>
<data name="FalseShort" xml:space="preserve">
<value>false</value>
</data>
Expand Down
6 changes: 6 additions & 0 deletions test/powershell/engine/Help/UpdatableHelpSystem.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading