-
Notifications
You must be signed in to change notification settings - Fork 10k
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
Use ArgumentException.ThrowIfNullOrWhitespace #48414
Conversation
Thanks for your PR, @wcontayon. Someone from the team will get assigned to your PR shortly and we'll get it reviewed. |
{ | ||
throw new ArgumentException("A valid non-empty content root must be provided.", nameof(contentRootPath)); | ||
} | ||
ArgumentException.ThrowIfNullOrEmpty(contentRootPath); |
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.
Definitely less explanatory
{ | ||
throw new ArgumentException("Cannot be null or empty", nameof(key)); | ||
} | ||
ArgumentException.ThrowIfNullOrEmpty(purpose); |
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.
Observable change - not saying good or bad, but: definitely a change; I'm fine with it personally
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 missing what observable here?
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 specific error message will change. Very much a pedantic "we should at least be aware that we're changing something, even if it is something that nobody should reasonably rely on", and in this case very much in the "trivial, no custom messages, just go for it" category. New message "The value cannot be an empty string." or "Value cannot be null"
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.
Effectively, we do not have an overload that accepts a custom message.
I opened a Api Proposal on dotnet/runtime to have the option to set the custom message.
we can just update only those part with generic message
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.
Ah, right. By precedent, I think we've had no problem changing exception messages, including in cases like this, so long as that doesn't lose actual useful information.
{ | ||
throw new ArgumentException("A valid non-empty content root must be provided.", nameof(contentRootPath)); | ||
} | ||
ArgumentException.ThrowIfNullOrEmpty(contentRootPath); |
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.
Ditto less explanatory
Not going to comment on each and every one of these, but I think there are 3 main scenarios in here:
The first two categories: IMO absolutely fine, let's encourage that. It is this final category that worries me a little - some of the existing message IMO cross an invisible and subjective line where the current message is more helpful than the new. Not at a PC to check, but: I assume there isn't an overload that accepts a custom message? Clarification: I mean this comment as a discussion starter, not as a definitive "this is the review". So to all: thoughts? |
@@ -13,7 +13,11 @@ internal static void Initialize(this IHostingEnvironment hostingEnvironment, str | |||
#pragma warning restore CS0618 // Type or member is obsolete | |||
{ | |||
ArgumentNullException.ThrowIfNull(options); | |||
ArgumentException.ThrowIfNullOrEmpty(contentRootPath); | |||
|
|||
if (string.IsNullOrEmpty(contentRootPath)) |
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.
if (string.IsNullOrEmpty(contentRootPath)) | |
if (string.IsNullOrEmpty(contentRootPath)) |
Co-authored-by: Dan Moseley <danmose@microsoft.com>
{ | ||
throw new ArgumentException("Value cannot be null or empty string.", nameof(value)); | ||
} | ||
ArgumentException.ThrowIfNullOrEmpty(value, nameof(value)); |
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 2nd parameter is required here?
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.
ArgumentException.ThrowIfNullOrEmpty(value, nameof(value)); | |
ArgumentException.ThrowIfNullOrEmpty(value); |
{ | ||
throw new ArgumentException(Resources.ArgumentCannotBeNullOrEmpty, nameof(folderPath)); | ||
} | ||
ArgumentException.ThrowIfNullOrEmpty(folderPath, nameof(folderPath)); |
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.
ArgumentException.ThrowIfNullOrEmpty(folderPath, nameof(folderPath)); | |
ArgumentException.ThrowIfNullOrEmpty(folderPath); |
throw new ArgumentException($"The {nameof(options.RootPath)} property " + | ||
$"of {nameof(options)} cannot be null or empty."); | ||
} | ||
ArgumentException.ThrowIfNullOrEmpty(options.RootPath, nameof(options.RootPath)); |
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.
does this require the 2nd parameter to get it right?
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.
ArgumentException.ThrowIfNullOrEmpty(options.RootPath, nameof(options.RootPath)); | |
ArgumentException.ThrowIfNullOrEmpty(options.RootPath); |
{ | ||
throw new ArgumentException("Cannot be null or empty", nameof(scriptName)); | ||
} | ||
ArgumentException.ThrowIfNullOrEmpty(sourcePath, nameof(spaBuilder)); |
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.
ArgumentException.ThrowIfNullOrEmpty(sourcePath, nameof(spaBuilder)); | |
ArgumentException.ThrowIfNullOrEmpty(sourcePath); |
better I think
@@ -902,8 +880,6 @@ public static RoutePatternParameterPart ParameterPart(string parameterName, obje | |||
throw new ArgumentException(Resources.TemplateRoute_OptionalCannotHaveDefaultValue); | |||
} | |||
|
|||
ArgumentNullException.ThrowIfNull(parameterPolicies); |
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.
were these intentionally moved up?
{ | ||
throw new ArgumentNullException(nameof(name)); | ||
} | ||
ArgumentNullException.ThrowIfNull(name, parameterName); |
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.
This is covered by the line below, and the implicit equals operator on the StringSegment struct, I think? Anyway in other cases you don't have this line.
ArgumentNullException.ThrowIfNull(name, parameterName); |
Just a few bits of feedback. Have you verified in the debugger that it's working as expected on StringSegment? Normally you can't compare structs to null but I guess it's using the implicit equality operator. BTW, there's still 6 uses of |
{ | ||
throw new ArgumentNullException(nameof(value)); | ||
} | ||
ArgumentException.ThrowIfNullOrWhiteSpace(value.Value); |
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.
Behavior change, Why is this more restrictive than before? This might explain most of the auth test failures, an empty value is commonly used when removing a cookie.
Looks like this PR hasn't been active for some time and the codebase could have been changed in the meantime. |
/azp run |
Commenter does not have sufficient privileges for PR 48414 in repo dotnet/aspnetcore |
@wcontayon To rerun validation you have to click close then click open again.. |
@mkArtakMSFT this comment seems to only work for folks with write access -- should we clarify the text that other folks should close/reopen? (my assumption is that it runs on latest HEAD either way @wtgodbe ?) |
meanwhile, @wcontayon did you have a chance to address the feedback? You can click resolve when you have. |
That's right |
@wcontayon do you expect to be able to continue addressing feedback? thanks for doing this. BTW, if it's easier for you, you could choose to split it into smaller PR's. |
@danmoseley yes sure !! |
Cool! Work on your own schedule, just want to make sure we end up merging your work. |
@wcontayon do you plan to continue with this PR? I'll close it for now, but feel free to reopen when you're ready. |
Use ArgumentException.ThrowIfNullOrWhitespace
Description
Use
ArgumentException.ThrowIfNullOrWhitespace
method from dotnet/runtime#86007Fixes #48185 (partially, still check if we can replace some code with
ArgumentException.ThrowIfNullOrWhitespace
)