-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Revert a few changes to not use 'ArgumentNullException.ThrowIfNull' #19151
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
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
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.
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.
As I pointed already in another PR, this generates worst code.
Also in .Net 8 Preview 1 we will get ArgumentOutOfRangeException.ThrowIfZero (and more) so that the code will be:
Uh oh!
There was an error while loading. Please reload this page.
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.
The difference in generated code doesn't always matter, and you cannot use it as the single criteria. In this case, the original code is more readable.
As far as I can found in the dotnet/runtime repo, it's
ArgumentOutOfRangeException.ThrowIfZero, notArgumentNullException.ThrowIfZero. It throws a different exception.Also, even in case of
ArgumentOutOfRangeException.ThrowIfZero(value.count), I don't know what will be used as the parameter name,"value.count"I guess?Uh oh!
There was an error while loading. Please reload this page.
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.
You are right it will throw a different exception, I don't know if it will be a problem (maybe we just have to change the tests).
From dotnet/runtime#69590
public static void ThrowIfZero<T>(T value, [CallerArgumentExpression("value")] string? paramName = null)it seems can set any string as parameter nameThere 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.
The original code is not correct. There are not too few places in our code where an exception is called that is not what it should be. This is not even a breaking change, as it is not a functional exception, and it is worth correcting it for the correct one. If someone even uses this behavior in their code, it is catastrophically bad code.
Yes, as the attribute name (CallerArgumentExpression) says
expressionis used as "name". It is more informative and more correct. (Otherwise this API would never have been approved.)So I think we should fix such protective (non-functional) exceptions to the correct ones in whole code base.
Uh oh!
There was an error while loading. Please reload this page.
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.
That will need to be discussed and approved by all maintainers. If you insist on fixing those exceptions, then please open an issue on it and mark it with
Review - Maintainer.ArgumentOutOfRangeExceptionwon't be the right exception either. If you insist to be accurate about the exception, then anArgumentExceptionwith a customized error message should be the way to go.In my personal view, changing those exceptions is not worth the time (discussion, making the change, and code review). But if all other maintainers agree to make the change, then I'm fine to replace the current code with a customized
ArgumentException.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 already explained in #19151 (comment) why it's arguably incorrect. I'm not trying to persuade you, just to clarify my opinion.
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'm trying to figure out what to demand from other contributors so we don't waste time later. So you'd better convince me. 😃
Right now I don't see that a ArgumentException message would be better than an ArgumentOutOfRangeException. (If I understand correctly you have no objection to the exception class type used but only to content of message.)
While I'm on vacation and have no opportunity to experiment. I'll try it a week later.
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.
A custom message will be absolutely better than
'paramName' must be a non-zero value. (Parameter 'paramName'), which is whatArgumentOutOfRangeException.ThrowIfZerogives you.In this particular case, the message should be something like
'paramName' must be a non-empty collection. (Parameter 'paramName')I'm fine changing the type of exception to be thrown. That's a bucket 3 breaking change.
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.
To be clear,
ClientWebSocketOptions.SetBuffer(Int32, Int32, ArraySegment<Byte>)is a public API introduced in .NET Framework 4.5. In any case, please could we should start discussion in a new issue.Uh oh!
There was an error while loading. Please reload this page.
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.
To be clear,
ClientWebSocketOptions.SetBuffer(Int32, Int32, ArraySegment<Byte>)is a public API introduced in .NET Framework 4.5. In any case, please could we continue discussion in a new issue.