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
Make Measure-Object
ignore missing properties unless running in strict mode
#16589
Make Measure-Object
ignore missing properties unless running in strict mode
#16589
Conversation
test/powershell/Modules/Microsoft.PowerShell.Utility/Measure-Object.Tests.ps1
Outdated
Show resolved
Hide resolved
$Err[0].FullyQualifiedErrorId | Should -BeExactly "GenericMeasurePropertyNotFound,Microsoft.PowerShell.Commands.MeasureObjectCommand" | ||
} | ||
|
||
AfterAll { |
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.
This should be after BeforeAll.
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.
Up!
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.
I am a little confused by this suggestion.
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.
In all our tests files are formatted so
PowerShell/test/powershell/Modules/Microsoft.PowerShell.Management/Get-Service.Tests.ps1
Lines 3 to 15 in 7bebf44
Describe "Get-Service cmdlet tests" -Tags "CI" { | |
# Service cmdlet is currently working on windows only | |
# So skip the tests on non-Windows | |
BeforeAll { | |
$originalDefaultParameterValues = $PSDefaultParameterValues.Clone() | |
if ( -not $IsWindows ) { | |
$PSDefaultParameterValues["it:skip"] = $true | |
} | |
} | |
# Restore the defaults | |
AfterAll { | |
$global:PSDefaultParameterValues = $originalDefaultParameterValues | |
} |
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.
Ah, I see, thank you
src/Microsoft.PowerShell.Commands.Utility/commands/utility/Measure-Object.cs
Outdated
Show resolved
Hide resolved
@KiwiThePoodle Please rebase to fix CI-static. |
84e10f4
to
71f73a0
Compare
This pull request has been automatically marked as Review Needed because it has been there has not been any activity for 7 days. |
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.
I spot this when trying to merge approved PRs on behalf of @TravisEz13, who is OOF this week.
@KiwiThePoodle can you please address this comment?
src/Microsoft.PowerShell.Commands.Utility/commands/utility/Measure-Object.cs
Outdated
Show resolved
Hide resolved
… on invalid properties only when in StrictMode, error mentions specific property
…rrorAction Stop and Should -Throw -ErrorId, syntax fixes
4832597
to
e1847f4
Compare
This PR has Quantification details
Why proper sizing of changes matters
Optimal pull request sizes drive a better predictable PR flow as they strike a
What can I do to optimize my changes
How to interpret the change counts in git diff output
Was this comment helpful? 👍 :ok_hand: :thumbsdown: (Email) |
Measure-Object
ignore missing properties unless running in strict mode
Thanks @KiwiThePoodle for your contribution! |
🎉 Handy links: |
This commit adds a note to the `Measure-Object` cmdlet reference documentation for PowerShell 7.3 to clarify that it now only returns an argument error when an object is missing the to-measure property in **StrictMode** to pair with the updated implementation from PowerShell/PowerShell#16589.
* (GH-8618) Add note to Measure-Object in 7.3 This commit adds a note to the `Measure-Object` cmdlet reference documentation for PowerShell 7.3 to clarify that it now only returns an argument error when an object is missing the to-measure property in **StrictMode** to pair with the updated implementation from PowerShell/PowerShell#16589. * Address review feedback. Co-authored-by: Sean Wheeler <sean.wheeler@microsoft.com> Co-authored-by: Sean Wheeler <sean.wheeler@microsoft.com>
PR Summary
When using Measure-Object on an empty folder, the "Length" property is invalid. When in StrictMode, an error is thrown when the requested property is not found. The error message is also updated to include the specific property that is not found. The invalid property is simply ignored when not in StrictMode.
PR Context
Fixes issue #14449
Unless in StrictMode, missing properties are typically ignored by other commands, so the Measure-Object command should do the same. This pull-request updates the Measure-Object command to only throw a property not found error when in StrictMode and ignores the property not found when not in StrictMode. This functionality is now consistent with other PowerShell commands.
PR Steps to Reproduce
my_folder is an empty directory
When StrictMode is off: no error
Set-StrictMode -off
gi my_folder | measure Length -sum
When StrictMode is on: error message
Set-StrictMode -Version 3.0
gi my_folder | measure Length -sum
Measure-Object: Cannot process argument because the value of argument “Length” is not valid. Change the value of the “Length” argument and run the operation again.
PR Changed Files
Measure-Object.cs
-Bug fix: changed "Property" to propertyName, the actual name of the property argument
-WritePropertyNotFoundError(propertyName, errorId) only called when in StrictMode
Measure-Object.Tests.ps1
-Added 2 empty folder tests where Measure-Object command is used on an empty folder
-When not in StrictMode, no error should be thrown
-When in StrictMode, error should be thrown
PR Checklist
.h
,.cpp
,.cs
,.ps1
and.psm1
files have the correct copyright headerWIP:
or[ WIP ]
to the beginning of the title (theWIP
bot will keep its status check atPending
while the prefix is present) and remove the prefix when the PR is ready.(which runs in a different PS Host).