Throw error message when MaxumimVersion is less than Version when using Import-Module cmdlet with -FullyQualifiedName parameter.#7347
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.
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.
Ideally this should use $"{nameof(...)}" for the bad members
There was a problem hiding this comment.
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? 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. |
| 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.
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.
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}).
| (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.
Let me know if you need any help on creating that test btw, I'm always happy to
|
@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