Fix using expression for invalid property#27349
Open
jborean93 wants to merge 2 commits into
Open
Conversation
Fixes the using expression builder when encountering a using expression with invalid property. Previously such a property would stop the using builder from working on the remaining using statements while ignoring the error. From this change it will still ignore the error but continue working on the remaining expressions.
5 tasks
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes $using: value collection so that a failure to evaluate one using expression (e.g., invalid property access) does not prevent subsequent $using: expressions from being collected. This aligns remoting and ForEach-Object -Parallel behavior with normal script evaluation expectations and addresses #27340.
Changes:
- Adjusted
$using:value collection to handle per-expression failures and continue processing remaining using expressions. - Added regression tests for remoting loopback and
ForEach-Object -Parallelto ensure subsequent$using:references still resolve when one using expression is invalid.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
src/System.Management.Automation/engine/runtime/ScriptBlockToPowerShell.cs |
Moves exception handling to per-using-expression evaluation so later $using: values are still collected. |
test/powershell/engine/Remoting/RemoteSession.Basic.Tests.ps1 |
Adds remoting regression test to ensure invalid $using: property access doesn’t break subsequent $using: references. |
test/powershell/Modules/Microsoft.PowerShell.Utility/Foreach-Object-Parallel.Tests.ps1 |
Adds ForEach-Object -Parallel regression test covering the same scenario. |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
iSazonov
reviewed
Apr 24, 2026
| { | ||
| if (rte.ErrorRecord.FullyQualifiedErrorId.Equals("VariableIsUndefined", StringComparison.Ordinal)) | ||
| { | ||
| throw InterpreterError.NewInterpreterException( |
Collaborator
There was a problem hiding this comment.
Can we simply re-throw?
throw;
Collaborator
Author
There was a problem hiding this comment.
Not sure, I just re-used what was already there but haven't actually looked deeper into what the NewInterpreterException is doing.
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.
PR Summary
Fixes the using expression builder when encountering a using expression with invalid property. Previously such a property would stop the using builder from working on the remaining using statements while ignoring the error. From this change it will still ignore the error but continue working on the remaining expressions.
PR Context
Fixes: #27340
Currently if a using expression throws an error, like an invalid property, when building the using expression it would stop the using value builder from processing the remaining expressions. With this change it instead still continues to process the remaining expressions while still keeping the invalid one as
$nulllike before.This fixes this statement:
With the changes here it now becomes
This better reflects how the same statement would work in a normal invocation with the same vars outside of
$using:.The only exception to this was if the inner scriptblock had enabled strict mode but the existing logic isn't equipped to deal with this as it already ignores errors on the client side. All this PR does is to continue resolving the remaining expressions rather than leaving it as unset.
PR Checklist
.h,.cpp,.cs,.ps1and.psm1files have the correct copyright header