Skip to content

Conversation

@dkaszews
Copy link
Contributor

@dkaszews dkaszews commented Jul 26, 2022

PR Summary

HelpCultureNotSupported is caught and ignored with implicit culture (-UICulture not given explicitly, defaults to system) to allow trying again with culture's parents. It does not however check if there are any more fallbacks, so all errors of this type are completely silenced. I store first error of this type, then show it if none of the fallbacks succeed,

Fixes #17696

PR Context

Update-Help with implcit culture fails silently on non-US systems (en-GB in my case), with no feedback on what is wrong even when using -Verbose. With this fix, the user is shown the same error as with explicit -UICulture (Get-UICulture), which clearly describes what they should do:

Update-Help: Failed to update Help for the module(s) '...' with UI culture(s) {en-GB} : No UI culture was found that matches the following pattern: en-GB. Verify the pattern and then try the command again..
English-US help content is available and can be installed using: Update-Help -UICulture en-US.

PR Checklist

@daxian-dbw
Copy link
Member

@dkaszews Thanks for submitting the PR!
@adityapatwardhan, can you please review when you have time? Thanks!

@adityapatwardhan
Copy link
Member

@dkaszews I like the change. Thanks for the PR. For testing, I would add some test hooks to make sure we fall in to the expected code paths.

Look at the files here to see how test hooks can be added:

https://github.com/PowerShell/PowerShell/search?q=testhook&type=code

Also, the test hook is used in product code like this:

if (!InternalTestHooks.TestWaitStopComputer && Wait && containLocalhost)
{
// The local machine will be ignored, and an error will be emitted.
InvalidOperationException ex = new(ComputerResources.CannotWaitLocalComputer);
WriteError(new ErrorRecord(ex, "CannotWaitLocalComputer", ErrorCategory.InvalidOperation, null));
containLocalhost = false;
}

@dkaszews
Copy link
Contributor Author

@adityapatwardhan Thanks for the tip! Please take a look if something like this is good.

@dkaszews
Copy link
Contributor Author

dkaszews commented Aug 1, 2022

If found additional issues all related to matching culture:

  1. We use globbing to try and match current culture with the one in help, but because valid CultureInfo values never contain wildcards, this does nothing. E.g.: en-GB has fallback en, but it still won't glob match with en-US. A simple fix would be to suffix (or surround) culture with '*':
    // UpdateableHelpSystem:594:
    IEnumerable<WildcardPattern> patternList = SessionStateUtilities.CreateWildcardsFromStrings(
    // - globPatterns: new[] { currentCulture },
    globPatterns: new[] { currentCulture + '*' },
    options: WildcardOptions.IgnoreCase | WildcardOptions.CultureInvariant);
  2. Second issue is that in UpdateableHelpSystemBase:EndProcessing, when we collapse all HelpCultureNotSupported exceptions for different modules into a single error, the supported culture is actually ignored, always displaying "en-US is supported" without checking that it actually is. That may be true for PowerShell-core modules, but if some module provides help in let's say en-GB or even fr-FR, it will be misleading, as I believe may be the case in Update-Help -UICulture en-US #17534 . Fix for that is slightly more involved, as it would require storing the supported cultures in the exception and probably reworking the exception hierarchy, as right now they are only in string.

Which of those should I fix here and which should be a separate issue? I would say the first one can be here, as it's just a single line, but the other I would prefer merging separately.

@dkaszews dkaszews changed the title WIP: Fix Update-Help failing silently with implicit non-US culture. Fix Update-Help failing silently with implicit non-US culture. Aug 1, 2022
@pull-request-quantifier-deprecated

This PR has 39 quantified lines of changes. In general, a change size of upto 200 lines is ideal for the best PR experience!


Quantification details

Label      : Extra Small
Size       : +37 -2
Percentile : 15.6%

Total files changed: 6

Change summary by file extension:
.cs : +12 -1
.resx : +3 -0
.ps1 : +22 -1

Change counts above are quantified counts, based on the PullRequestQuantifier customizations.

Why proper sizing of changes matters

Optimal pull request sizes drive a better predictable PR flow as they strike a
balance between between PR complexity and PR review overhead. PRs within the
optimal size (typical small, or medium sized PRs) mean:

  • Fast and predictable releases to production:
    • Optimal size changes are more likely to be reviewed faster with fewer
      iterations.
    • Similarity in low PR complexity drives similar review times.
  • Review quality is likely higher as complexity is lower:
    • Bugs are more likely to be detected.
    • Code inconsistencies are more likely to be detected.
  • Knowledge sharing is improved within the participants:
    • Small portions can be assimilated better.
  • Better engineering practices are exercised:
    • Solving big problems by dividing them in well contained, smaller problems.
    • Exercising separation of concerns within the code changes.

What can I do to optimize my changes

  • Use the PullRequestQuantifier to quantify your PR accurately
    • Create a context profile for your repo using the context generator
    • Exclude files that are not necessary to be reviewed or do not increase the review complexity. Example: Autogenerated code, docs, project IDE setting files, binaries, etc. Check out the Excluded section from your prquantifier.yaml context profile.
    • Understand your typical change complexity, drive towards the desired complexity by adjusting the label mapping in your prquantifier.yaml context profile.
    • Only use the labels that matter to you, see context specification to customize your prquantifier.yaml context profile.
  • Change your engineering behaviors
    • For PRs that fall outside of the desired spectrum, review the details and check if:
      • Your PR could be split in smaller, self-contained PRs instead
      • Your PR only solves one particular issue. (For example, don't refactor and code new features in the same PR).

How to interpret the change counts in git diff output

  • One line was added: +1 -0
  • One line was deleted: +0 -1
  • One line was modified: +1 -1 (git diff doesn't know about modified, it will
    interpret that line like one addition plus one deletion)
  • Change percentiles: Change characteristics (addition, deletion, modification)
    of this PR in relation to all other PRs within the repository.


Was this comment helpful? 👍  :ok_hand:  :thumbsdown: (Email)
Customize PullRequestQuantifier for this repository.

@dkaszews
Copy link
Contributor Author

dkaszews commented Aug 1, 2022

CodeRefactor reports new issues in UpdateHelpCommand.cs on lines 471 and 476, but I only modified 217 and see similar errors at other places in the file. How can I get it resolved as false positive?

@adityapatwardhan
Copy link
Member

adityapatwardhan commented Aug 3, 2022

@dkaszews

Thanks for the updates. If the CodeFactor issues are not in the code block you touched, you can ignore them.

I would prefer both the changes 1 and 2 in a separate PR as it changes the behavior and is an improvement in fallback lookup.
This PR is focused on fixing the error message on fallback.

@dkaszews
Copy link
Contributor Author

dkaszews commented Aug 3, 2022

@adityapatwardhan Sure, I'll create new issues and separate PRs for those two later

@dkaszews
Copy link
Contributor Author

dkaszews commented Aug 9, 2022

@adityapatwardhan Anything else I should do before this can be merged?

@adityapatwardhan adityapatwardhan merged commit 1ee2f0d into PowerShell:master Aug 9, 2022
@adityapatwardhan
Copy link
Member

@dkaszews thank you for your contribution!

@adityapatwardhan adityapatwardhan added the CL-General Indicates that a PR should be marked as a general cmdlet change in the Change Log label Aug 9, 2022
@TravisEz13 TravisEz13 mentioned this pull request Sep 30, 2022
22 tasks
@ghost
Copy link

ghost commented Dec 20, 2022

🎉v7.4.0-preview.1 has been released which incorporates this pull request.:tada:

Handy links:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CL-General Indicates that a PR should be marked as a general cmdlet change in the Change Log Extra Small

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Update-Help fails silently for UICulture en-GB

3 participants