Skip to content

NativeCommandParameterBinder.appendOneNativeArgument: Remove overly restrictive Diagnostics.Assert - cannot handle -encodedarguments - #5836

Merged
Jason Shirk (lzybkr) merged 1 commit into
PowerShell:masterfrom
dantraMSFT:dantra/issue5733
Jan 12, 2018
Merged

Jason Shirk (lzybkr) merged 1 commit into
PowerShell:masterfrom
dantraMSFT:dantra/issue5733

Conversation

@dantraMSFT

@dantraMSFT Dan Travison (dantraMSFT) commented Jan 9, 2018 •

Copy link
Copy Markdown
Contributor

Fixes #5733
Parameter binding has an assert that expects the argument value to be an array when the AST for the argument is an array. This assertion fails when the argument is encoded, such as when the -encodedarguments command-line parameter is used. The assert causes a process crash when running tests for debug builds.

The fix removes this assert since the method does not know the name of the argument being bound.

PR Checklist

Note: Please mark anything not applicable to this PR NA.

@dantraMSFT Dan Travison (dantraMSFT) changed the title Remove overly restrictive Diagnostics.Assert - cannot handle -encodedarguments NativeCommandParameterBinder.appendOneNativeArgument: Remove overly restrictive Diagnostics.Assert - cannot handle -encodedarguments Jan 9, 2018
@lzybkr

Copy link
Copy Markdown
Contributor

I used to add too many assertions, but do so much less these days - so I feel like I added this for a good reason.

I think a better fix would be to not pass the ast for the minishell code path because the parameter values no longer match up with the ast properly anyway.

@dantraMSFT

Copy link
Copy Markdown
Contributor Author

Jason Shirk (@lzybkr): I'm sure there was a reason but, at the end of the day, test runs consistently fail against debug builds due to this assert and consistently pass in release builds. In short, this assert isn't providing any value since debug builds are only run privately.

if you do have a good reason for leaving it in, let me know. In lieu of one, I'm reluctant to make a functional change to address this.

@lzybkr

Copy link
Copy Markdown
Contributor

The assertion caught a contract violation - the ast does not match the argument. Contract violations should not be "fixed" by ignoring the assertion.

If everything works today, code added in the future might not realize the contract is violated and do strange things.

You can make a change in this area with some confidence because it is well tested in our tests, there is plenty of time before the next release, and I will review the fix.

@dantraMSFT

Copy link
Copy Markdown
Contributor Author

Then perhaps it shouldn't be an assert. The contract is being violated multiple times a test run right now.

@lzybkr

Copy link
Copy Markdown
Contributor

It's an internal api for code that changes infrequently - an assert is reasonable.

@dantraMSFT

Copy link
Copy Markdown
Contributor Author

Jason Shirk (@lzybkr): I have to say that I would be open to your argument if we had a process for running tests against debug builds but we don't and, in fact, this assert always failed in test runs.

That said, I'll update the PR with a proposed runtime fix.

…es an assert failiure.

Revert previous change - restore the Diagnostics.Assert statement.
@dantraMSFT

Copy link
Copy Markdown
Contributor Author

Jason Shirk (@lzybkr): Do you have any additional feedback?

@lzybkr
Jason Shirk (lzybkr) merged commit d911bac into PowerShell:master Jan 12, 2018
@dantraMSFT
Dan Travison (dantraMSFT) deleted the dantra/issue5733 branch January 12, 2018 21:08
Thatgfsj (Thatgfsj) pushed a commit to Thatgfsj-contribs/PowerShell that referenced this pull request Aug 6, 2026
…rShell#5836)

When calling powershell from powershell (called the minishell for historical reasons), the arguments are passed as a base64 encoded string.

The native command parameter binder was trying to match up the ast to the argument value, which in this case, doesn't make sense.

The fix is to ignore the ast during parameter binding for this case of calling powershell from powershell.

Fix PowerShell#5733
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Debug assert "array argument and ArrayLiteralAst differ in number of elements" while running ConsoleHost tests

4 participants