Skip to content

Conversation

@sethvs
Copy link
Contributor

@sethvs sethvs commented Jul 24, 2018

PR Summary

Fix #7337

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>

Concerning if the change is breaking, I would refer it to Unlikely Grey Area.

PR Checklist

…ng Import-Module cmdlet with -FullyQualifiedName parameter.
@iSazonov iSazonov requested a review from rjmholt July 25, 2018 12:04
@daxian-dbw daxian-dbw added the WG-Cmdlets-Core cmdlets in the Microsoft.PowerShell.Core module label Jul 25, 2018
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);
Copy link

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>

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

Copy link
Collaborator

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

Copy link
Contributor Author

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?

@anmenaga
Copy link

anmenaga commented Aug 1, 2018

@daxian-dbw @SteveL-MSFT please evaluate if this technically breaking (however unlikely) change has to go to PS Committee for review.

@SteveL-MSFT SteveL-MSFT added Review - Committee The PR/Issue needs a review from the PowerShell Committee Breaking-Change breaking change that may affect users labels Aug 2, 2018
@SteveL-MSFT
Copy link
Member

@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.

@SteveL-MSFT SteveL-MSFT added Committee-Reviewed PS-Committee has reviewed this and made a decision and removed Review - Committee The PR/Issue needs a review from the PowerShell Committee labels Aug 8, 2018
@sethvs
Copy link
Contributor Author

sethvs commented Aug 12, 2018

Can you guide me a little bit?
How can I use WriteError in there?

if (moduleSpecification.Version != null && moduleSpecification.MaximumVersion != null &&
moduleSpecification.Version > ModuleCmdletBase.GetMaximumVersion(moduleSpecification.MaximumVersion))
{
message = StringUtil.Format(Modules.ModuleSpecificationMemberIsLessThanOther, "MaximumVersion", "ModuleVersion");
return new ArgumentException(message);
}

Or is there another way to return a non-terminating error?

@SteveL-MSFT
Copy link
Member

@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.

Copy link
Collaborator

@rjmholt rjmholt left a 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);
Copy link
Collaborator

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">
Copy link
Collaborator

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}).

Copy link
Contributor Author

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" {
Copy link
Collaborator

Choose a reason for hiding this comment

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

In addition to this test, we should add a more specific one using the [ModuleSpecification] constructor.

You should find those tests here (I know that's not an obvious place at all).

Note to self: once #7499 is merged, this test will be included in that.

Copy link
Collaborator

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@rjmholt
Copy link
Collaborator

rjmholt commented Aug 15, 2018

@SteveL-MSFT is it possible for a parameter binding exception to be non-terminating? The error when called with Get-Module will occur when the hashtable is cast to a ModuleSpecification; execution will never reach Get-Module.

@rjmholt
Copy link
Collaborator

rjmholt commented Aug 15, 2018

Also for reference, here is Import-Module's version check:

if (BaseMaximumVersion != null && BaseMinimumVersion != null && BaseMaximumVersion < BaseMinimumVersion)
{
string message = StringUtil.Format(Modules.MinimumVersionAndMaximumVersionInvalidRange, BaseMinimumVersion, BaseMaximumVersion);
throw new PSArgumentOutOfRangeException(message);
}

I think that's a terminating error, no?

@sethvs
Copy link
Contributor Author

sethvs commented Aug 15, 2018

Is this OK with VSTS: PowerShell-CI-macos?

@SteveL-MSFT
Copy link
Member

@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.

@SteveL-MSFT SteveL-MSFT added Review - Committee The PR/Issue needs a review from the PowerShell Committee and removed Committee-Reviewed PS-Committee has reviewed this and made a decision labels Aug 21, 2018
@SteveL-MSFT
Copy link
Member

In light of recent discussions about returning nothing vs an error. I'd like @PowerShell/powershell-committee to re-review this

@sethvs
Copy link
Contributor Author

sethvs commented Sep 5, 2018

Close and reopen to restart tests.

@sethvs sethvs closed this Sep 5, 2018
@sethvs sethvs reopened this Sep 5, 2018
@SteveL-MSFT
Copy link
Member

@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.

@SteveL-MSFT SteveL-MSFT added Committee-Reviewed PS-Committee has reviewed this and made a decision and removed Review - Committee The PR/Issue needs a review from the PowerShell Committee labels Sep 5, 2018
@sethvs sethvs closed this Sep 6, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Breaking-Change breaking change that may affect users Committee-Reviewed PS-Committee has reviewed this and made a decision WG-Cmdlets-Core cmdlets in the Microsoft.PowerShell.Core module

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Get-Module accepts nonsensical combinations of ModuleVersion and MaximumVersion entries for -FullyQualifiedName

5 participants