-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Throw error message when MaxumimVersion is less than Version when using Import-Module cmdlet with -FullyQualifiedName parameter. #7347
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
Conversation
…ng Import-Module cmdlet with -FullyQualifiedName parameter.
| if (badKeys.Length != 0) | ||
| { | ||
| message = StringUtil.Format(Modules.InvalidModuleSpecificationMember, "ModuleName, ModuleVersion, RequiredVersion, GUID", badKeys); | ||
| message = StringUtil.Format(Modules.InvalidModuleSpecificationMember, "ModuleName, ModuleVersion, MaximumVersion, RequiredVersion, GUID", badKeys); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add to PR Summary:
Also fixing following error message to include 'MaximumVersion' in the list of 'valid members':
<data name="InvalidModuleSpecificationMember" xml:space="preserve">
<value>The hashtable describing a module contains one or more members that are not valid. The valid members are ({0}). Remove the members that are not valid ({1}), then try again.</value>
</data>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ideally this should use $"{nameof(...)}" for the bad members
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nameof(badKeys) returns 'badKeys', but we need its actual value.
Or am I missing something?
|
@daxian-dbw @SteveL-MSFT please evaluate if this technically breaking (however unlikely) change has to go to PS Committee for review. |
|
@PowerShell/powershell-committee agrees this is a breaking change. For example using this in a pipeline would terminate the pipeline now whereas a $null being returned would not execute the rest of the pipeline. We agree that this should have been an error and would accept returning a non-terminating error and not a terminating one. |
|
Can you guide me a little bit? PowerShell/src/System.Management.Automation/engine/Modules/ModuleSpecification.cs Lines 167 to 172 in 321537c
Or is there another way to return a non-terminating error? |
|
@sethvs I took a look at the code. Since the validation is in the ModuleSpecification class that should continue to return an exception that gets thrown. You'll probably need to update GetModuleCommand.cs to handle this specific case. |
rjmholt
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apologies, I should have reviewed this sooner. Looks like a good change! Just left a couple of minor comments.
Thanks for your contribution @sethvs!
| if (badKeys.Length != 0) | ||
| { | ||
| message = StringUtil.Format(Modules.InvalidModuleSpecificationMember, "ModuleName, ModuleVersion, RequiredVersion, GUID", badKeys); | ||
| message = StringUtil.Format(Modules.InvalidModuleSpecificationMember, "ModuleName, ModuleVersion, MaximumVersion, RequiredVersion, GUID", badKeys); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ideally this should use $"{nameof(...)}" for the bad members
| <data name="InvalidModuleSpecificationMember" xml:space="preserve"> | ||
| <value>The hashtable describing a module contains one or more members that are not valid. The valid members are ({0}). Remove the members that are not valid ({1}), then try again.</value> | ||
| </data> | ||
| <data name="ModuleSpecificationMemberIsLessThanOther" xml:space="preserve"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The error message should ideally be slightly more specific. Something like:
The hashtable describing a module cannot have its ModuleVersion ({0}) greater than its MaximumVersion ({1}).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
| (Get-Module TestModule).Version | Should -BeIn "1.1" | ||
| } | ||
|
|
||
| It "should throw if 'MaximumVersion' is less than 'Version' when using -FullyQualifiedName parameter" { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let me know if you need any help on creating that test btw, I'm always happy to
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
|
@SteveL-MSFT is it possible for a parameter binding exception to be non-terminating? The error when called with |
|
Also for reference, here is PowerShell/src/System.Management.Automation/engine/Modules/ImportModuleCommand.cs Lines 1686 to 1690 in c94fc31
I think that's a terminating error, no? |
|
Is this OK with VSTS: PowerShell-CI-macos? |
|
@sethvs the VSTS runs are currently not blocking for merging, we're still working on improving them. They currently run in parallel to allow us to validate it's going to work for us. |
|
In light of recent discussions about returning nothing vs an error. I'd like @PowerShell/powershell-committee to re-review this |
|
Close and reopen to restart tests. |
|
@PowerShell/powershell-committee re-reviewed this. The conclusion is that well-formed filters should return nothing if the result set is nothing and not return an error. In this case, the filter is well-formed, although invalid. Since this is also a breaking change, our recommendation is to not take this change as it's inconsistent with the desired filtering behavior and introduces a breaking change. |
PR Summary
Fix #7337
Also fixing following error message to include 'MaximumVersion' in the list of 'valid members':
Concerning if the change is breaking, I would refer it to Unlikely Grey Area.
PR Checklist
.h,.cpp,.cs,.ps1and.psm1files have the correct copyright headerWIP:to the beginning of the title and remove the prefix when the PR is ready.[feature]if the change is significant or affects feature tests