Fix #2953: fail open when a bound parameter's ToString throws in the mock filter serializer - #2955
Merged
Merged
Conversation
…n the mock filter serializer Test-ParameterFilter builds diagnostic text from the bound parameters, which called ToString on every value. A value whose ToString throws (for example a mocked SMO type created by New-MockObject) made the whole filter throw, even when the value was not referenced by the filter at all. Serialize each value through a small helper that catches the failure and falls back to a placeholder, so the diagnostic text can never take down the mock.
nohwnd
enabled auto-merge (squash)
August 6, 2026 18:56
nohwnd
disabled auto-merge
August 6, 2026 19:19
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix #2953
Test-ParameterFilter serializes the bound parameters into diagnostic text (the debug message and the failed-filter summary), and that called ToString on every value. If a value's ToString throws, for example a mocked SMO type created by New-MockObject, the filter threw even when the value was never referenced by the filter.
Each value now goes through a small helper that catches the failure and falls back to a placeholder, so building the diagnostic text can never take down the mock.
Added a test that mocks a command with a non-matching parameter filter and passes a value whose ToString throws.
🤖