Skip to content

Conversation

@ArmaanMcleod
Copy link
Contributor

@ArmaanMcleod ArmaanMcleod commented Aug 20, 2023

PR Summary

Fixes #20142

PR Context

Added more user friendly #requires error message when a module cannot be loaded, instead of just the module name.

If you had a required module included like:

#Requires -Modules @{ ModuleName = 'CosmosDB'; RequiredVersion = '4.6.0'}

Previous Behaviour

Just shows module name.

.\test.ps1: The script 'test.ps1' cannot be run because the following modules that are specified by the "#requires" statements of the script are missing: CosmosDB.

Current Behaviour

Includes full RESX message with module name and version.

.\test.ps1: The script 'test.ps1' cannot be run because the following modules that are specified by the "#requires" statements of the script are missing: The module 'CosmosDB' cannot be found with RequiredVersion '4.6.0'.

The new RESX messages are like below for each version type and if no version is specified

#Requires -Modules @{ ModuleName = 'CosmosDB'; RequiredVersion = '4.6.0' }
The module 'CosmosDB' cannot be found with RequiredVersion '4.6.0'. 

#Requires -Modules @{ ModuleName = 'CosmosDB'; ModuleVersion = '4.6.0' }
The module 'CosmosDB' cannot be found with ModuleVersion '4.6.0'.

#Requires -Modules @{ ModuleName = 'CosmosDB'; MaximumVersion = '4.6.0' }
The module 'CosmosDB' cannot be found with MaximumVersion '4.6.0'.

#Requires -Modules @{ ModuleName = 'CosmosDB'; ModuleVersion = '4.6.0';  MaximumVersion = '4.7.0' }
The module 'CosmosDB' cannot be found with ModuleVersion '4.6.0' and MaximumVersion '4.7.0'.

 #Requires -Modules @{ ModuleName = 'CosmosDB' }
The module 'CosmosDB' cannot be found.

PR Checklist

@ArmaanMcleod ArmaanMcleod changed the title Fix require module version error message Include Module Version in Requires error message when module version is not found Aug 20, 2023
@ArmaanMcleod ArmaanMcleod changed the title Include Module Version in Requires error message when module version is not found Include Module Version in Requires error message when module is not found Aug 20, 2023
@iSazonov
Copy link
Collaborator

.\test.ps1: The script 'test.ps1' cannot be run because the following modules that are specified by the "#requires" statements of the script are missing: @{ ModuleName = 'CosmosDB'; RequiredVersion = '4.6.0' }.

What if there are some modules?
It seems it is not user-friendly format.

@SteveL-MSFT SteveL-MSFT added the CommunityDay-Small A small PR that the PS team has identified to prioritize to review label Aug 21, 2023
@SteveL-MSFT
Copy link
Member

I agree with @iSazonov that the output, although technically correct, isn't the most user friendly particularly those who simply got a script to run. It may be better to have a new resource string in a resx file added and specifically have the module name and module version instead of the hashtable syntax.

@microsoft-github-policy-service microsoft-github-policy-service bot added the Waiting on Author The PR was reviewed and requires changes or comments from the author before being accept label Aug 21, 2023
@ArmaanMcleod
Copy link
Contributor Author

I agree with @iSazonov that the output, although technically correct, isn't the most user friendly particularly those who simply got a script to run. It may be better to have a new resource string in a resx file added and specifically have the module name and module version instead of the hashtable syntax.

Thanks @SteveL-MSFT @iSazonov.

I thought the same initially but wasn't sure what format we should include. The hashtable string looks ok for one module but for many it gets quite hard to read.

Could we do something like <Module Name> <Version>? Was also thinking if we should make it clear whether its ModuleVersion, RequiredVersion or MaximumVersion in the message as well?

Or should we have a full resx message like The module <module> cannot be found with required version <version>.

Happy to do whatever is preferred and most user friendly 😄.

@microsoft-github-policy-service microsoft-github-policy-service bot removed the Waiting on Author The PR was reviewed and requires changes or comments from the author before being accept label Aug 21, 2023
@SteveL-MSFT
Copy link
Member

@ArmaanMcleod my initial thinking is the latter: The module "<module>" cannot be found with required version <version>.

@iSazonov
Copy link
Collaborator

iSazonov commented Aug 22, 2023

Since the directive has 3 parameters ModuleVersion, MaximumVersion , RequiredVersion (https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_requires?view=powershell-7.3#-modules-module-name--hashtable) my first question is - are two first error messages correct or we should fix them too? I think all three messages should have the same format (not one resx string I mean).

Image
Prevents a script from running without the required elements.

@kilasuit
Copy link
Collaborator

@ArmaanMcleod my initial thinking is the latter: The module "<module>" cannot be found with required version <version>.

This but if is a max version, not required version then the message should state along lines of The module "<module>" cannot be found with a maximum version of <version>.

So would need both in for full clarity.

@ArmaanMcleod ArmaanMcleod requested a review from iSazonov August 26, 2023 13:18
Copy link
Collaborator

@iSazonov iSazonov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM with minor proposal.

@iSazonov iSazonov added the CL-General Indicates that a PR should be marked as a general cmdlet change in the Change Log label Aug 28, 2023
Copy link
Member

@SteveL-MSFT SteveL-MSFT left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great change! Thanks!

@microsoft-github-policy-service
Copy link
Contributor

This pull request has been automatically marked as Review Needed because it has been there has not been any activity for 7 days.
Maintainer, please provide feedback and/or mark it as Waiting on Author

@microsoft-github-policy-service microsoft-github-policy-service bot added the Review - Needed The PR is being reviewed label Sep 5, 2023
@microsoft-github-policy-service microsoft-github-policy-service bot removed the Review - Needed The PR is being reviewed label Sep 11, 2023
@pull-request-quantifier-deprecated

Image

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


Quantification details

Label      : Small
Size       : +90 -6
Percentile : 38.4%

Total files changed: 4

Change summary by file extension:
.cs : +28 -1
.resx : +15 -0
.ps1 : +47 -5

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.

@iSazonov iSazonov changed the title Include Module Version in Requires error message when module is not found Include Module Version in error messages when module is not found Sep 12, 2023
@iSazonov iSazonov merged commit 2a7384c into PowerShell:master Sep 12, 2023
@ArmaanMcleod ArmaanMcleod deleted the fix-require-module-version-error-message branch September 12, 2023 20:36
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 CommunityDay-Small A small PR that the PS team has identified to prioritize to review Small

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Requires statement error should show which version of module you need

4 participants