-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Description
Summary of the new feature / enhancement
In PowerShell code base there are some places where we are not accurate with exceptions.
Typical example:
PowerShell/src/System.Management.Automation/engine/CommandInfo.cs
Lines 286 to 294 in 4314e63
| internal void Rename(string newName) | |
| { | |
| if (string.IsNullOrEmpty(newName)) | |
| { | |
| throw new ArgumentNullException(nameof(newName)); | |
| } | |
| Name = newName; | |
| } |
Here we throw ArgumentNullException that is not correct if the argument is empty. (There are examples with other exceptions.)
My proposal is to fix such code and throw ArgumentNullException if argument is null and ArgumentException is argument is empty.
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.
The proposal comes from the fact that we are blocked from using new .Net API like ArgumentException.ThrowIfNullOrEmpty(). The API makes code more friendly for .Net Rumtime optimizations (like inlining). We already use this kind of API in a lot of places and it's worth updating the rest.
Proposed technical implementation details (optional)
No response