Make the parameter 'args' no-nullable in the public `ConsoleHost` APIs by daxian-dbw · Pull Request #13429 · PowerShell/PowerShell

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

Conversation

daxian-dbw

PR Summary

This is a follow-up on #11482
We actually don't expect args to contain null value in it. For example, the use of args in GetSwitchKey at here indicates we are not expecting an element of args is null, and many other places like ParseFile.

/cc @iSazonov Maybe we should validate if args contains any null elements, maybe that's not necessary given it has been working fine so far, but either way, I'm deferring that to a separate PR.

PR Context

PR Checklist

adityapatwardhan

anmenaga

rjmholt

@rjmholt

rjmholt

@iSazonov

Maybe we should validate if args contains any null elements, maybe that's not necessary given it has been working fine so far, but either way, I'm deferring that to a separate PR.

.Net team confirmed that it is not null for Main() - right signature Main(string[] args).
For UnmanagedEntry users could send null. We do not check this previously so we can (1) document this explicitly that it is Main() signature, (2) add the check.

@daxian-dbw

For UnmanagedEntry users could send null.

Why is that? Yes, there is a null assignment in Program.cs but that's the arg for exec, which requires a null element to indicate the end of args. I don't think that null will be passed to UnmanagedEntry.Start.

ConsoleShell.Start is public API, so a user potentially can pass in a string array with null elements. If we want to validate args, then I guess that should be done in CommandLineParameterParser.Parse.

@iSazonov

I don't think that null will be passed to UnmanagedEntry.Start

It is a public API too :-) It would be not right using but possible.

@iSazonov

I guess that should be done in CommandLineParameterParser.Parse.

What is desired behavior for null? Throw?

@daxian-dbw

It is a public API too :-) It would be not right using but possible.

True, but it's less likely to be used like the ConsoleShell.Start.

What is desired behavior for null? Throw?

Yes, throw, but with ArgumentException and a better error message.

@rjmholt rjmholt added the CL-General

Indicates that a PR should be marked as a general cmdlet change in the Change Log

label

Aug 14, 2020

@PoshChan

@rjmholt, this is the reminder you requested 24 hours ago

@ghost

🎉v7.1.0-preview.6 has been released which incorporates this pull request.:tada:

Handy links:

Reviewers

@rjmholt rjmholt rjmholt approved these changes

@anmenaga anmenaga anmenaga approved these changes

@adityapatwardhan adityapatwardhan adityapatwardhan approved these changes

@iSazonov iSazonov Awaiting requested review from iSazonov

@TravisEz13 TravisEz13 Awaiting requested review from TravisEz13

Labels

CL-General

Indicates that a PR should be marked as a general cmdlet change in the Change Log