Skip to content
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.ThrowIfNullOrEmpty #50666

Closed
wants to merge 5 commits into from

Conversation

divyeshio
Copy link
Contributor

@divyeshio divyeshio commented Sep 12, 2023

Use ArgumentException.ThrowIfNullOrEmpty where applicable

  • You've read the Contributor Guide and Code of Conduct.
  • You've included unit or integration tests for your change, where applicable.
  • You've included inline docs for your change, where applicable.
  • There's an open issue for the PR that you are making. If you'd like to propose a new feature or change, please open an issue to discuss the change or find an existing issue.

Description

As suggested here #48414 (comment) , I have splitted up the changes specific to ArgumentException.ThrowIfNullOrEmpty and have already addressed the feedback in this PR.

Also, I have made changes to Resources.ArgumentCannotBeNullOrEmpty in the separate commit (just easier to filter on commit and review)

Fixes #50665

@dotnet-issue-labeler dotnet-issue-labeler bot added the area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates label Sep 12, 2023
@ghost ghost added the community-contribution Indicates that the PR has been added by a community member label Sep 12, 2023
@ghost
Copy link

ghost commented Sep 12, 2023

Thanks for your PR, @divyeshio. Someone from the team will get assigned to your PR shortly and we'll get it reviewed.

@captainsafia
Copy link
Member

@divyeshio Thanks! It looks like you might've inadvertently re-introduced changes to the spa-templates submodule that are causing the build break. Removing these changes from the commit should do the trick. Let me know if you need help with this!

@danmoseley
Copy link
Member

thanks for the PR @divyeshio . Looks like there's a build error -- typo. Could you please build locally before pushing changes? That will save unnecessary runs of our (considerable) validation matrix..

@divyeshio
Copy link
Contributor Author

While restoring, I'm getting following error. I have tried deleting artifacts folder, cleared everything in nuget cache but still failing, all while being on main branch. Can you help me with this?

image

@wtgodbe
Copy link
Member

wtgodbe commented Sep 14, 2023

That's weird - that wildcard expression should be picking up our native projects. It's from

aspnetcore/eng/Build.props

Lines 117 to 121 in 36d30fd

<ItemGroup Condition=" '$(TargetOsName)' == 'win' AND ('$(TargetArchitecture)' == 'x86' OR '$(TargetArchitecture)' == 'x64') ">
<NativeProjects Include="$(RepoRoot)src\**\*.vcxproj" Exclude="@(ProjectToExclude)" AdditionalProperties="Platform=x64" />
<NativeProjects Include="$(RepoRoot)src\**\*.vcxproj" Exclude="@(ProjectToExclude)" AdditionalProperties="Platform=Win32" />
<NativeProjects Include="$(RepoRoot)src\**\*.vcxproj" Exclude="@(ProjectToExclude)" AdditionalProperties="Platform=arm64" />
</ItemGroup>
. It must be something in your local setup - have you deleted any files? What command-line shell are you using? Worst case scenario, you could work around it by deleting the block I linked (but don't include that change in your PR)

@divyeshio
Copy link
Contributor Author

@wtgodbe It's resolved now, I had to update vs workload, delete the repo, start over again and then it worked. Btw, I'm using powershell.

A question, as these changes are spread across several projects, how do I verify my changes? Do I need to build and test whole repo? I tried -projects parameter in eng/build script, build fails when I use that vs when I build the individual project by navigating to the folder, it builds fine.

image

image

@wtgodbe
Copy link
Member

wtgodbe commented Sep 14, 2023

Building the whole repo with eng/build.cmd -test will verify that everything is working. You can also run tests for the changed projects with dotnet test in the project directory

@divyeshio
Copy link
Contributor Author

For following, should we change from ArgumentException to ArgumentNullException ?

Since we are checking for null here and ArgumentNullException make more sense for it. Secondly, there is no ThrowIfNull helper for ArgumentException.
And change it to ArgumentNullException.ThrowIfNull(tagBuilder)

if (tagBuilder == null)
{
throw new ArgumentException(Resources.ArgumentCannotBeNullOrEmpty, nameof(tagBuilder));
}

@danmoseley
Copy link
Member

For following, should we change from ArgumentException to ArgumentNullException ?

Seems reasonable, plus the current "or empty" message does not seem right.

@divyeshio
Copy link
Contributor Author

Using ArgumentException.ThrowIfNullOrEmpty throws ArgumentException and ArgumentNullException. Methods that were simply throwing ArgumentException have their Tests failing after changes, as tests were expecting ArgumentException but got ArgumentNullException instead. One such example is following:

if (string.IsNullOrEmpty(flagString))
{
throw new ArgumentException("Argument cannot be null or empty string.", nameof(flagString));
}

After changes: ArgumentException.ThrowIfNullOrEmpty(flagString);

Failing test

Assert.Throws<ArgumentException>(() => FlagParser.Parse(null));

Should I update the tests or is it big enough breaking change?

@danmoseley
Copy link
Member

I think it's fine to update tests that were expecting AE for a null parameter to now expect ANE. We've done that before.

@mkArtakMSFT mkArtakMSFT removed the area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates label Sep 20, 2023
@mkArtakMSFT mkArtakMSFT added the area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions label Sep 20, 2023
@ghost
Copy link

ghost commented Sep 28, 2023

Looks like this PR hasn't been active for some time and the codebase could have been changed in the meantime.
To make sure no conflicting changes have occurred, please rerun validation before merging. You can do this by leaving an /azp run comment here (requires commit rights), or by simply closing and reopening.

@ghost ghost added the pending-ci-rerun When assigned to a PR indicates that the CI checks should be rerun label Sep 28, 2023
@captainsafia captainsafia added the pr: pending author input For automation. Specifically separate from Needs: Author Feedback label Oct 10, 2023
@ghost
Copy link

ghost commented Oct 21, 2023

Hi @divyeshio.
It seems you haven't touched this PR for the last two weeks. To avoid accumulating old PRs, we're marking it as stale. As a result, it will be closed if no further activity occurs within 4 days of this comment. You can learn more about our Issue Management Policies here.

@ghost ghost added the stale Indicates a stale issue. These issues will be closed automatically soon. label Oct 21, 2023
@ghost ghost closed this Oct 25, 2023
@divyeshio
Copy link
Contributor Author

Hi @danmoseley, I am still willing to make this contribution happen. I have few commits unpushed and last time I remember there were still few test cases failing and required changes. I was almost 80-90% there with all the changes. Now, starting again, Do I need to do something rebase or anything?

@ghost
Copy link

ghost commented Dec 12, 2023

Hi @divyeshio. It looks like you just commented on a closed PR. The team will most probably miss it. If you'd like to bring something important up to their attention, consider filing a new issue and add enough details to build context.

This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions community-contribution Indicates that the PR has been added by a community member pending-ci-rerun When assigned to a PR indicates that the CI checks should be rerun pr: pending author input For automation. Specifically separate from Needs: Author Feedback stale Indicates a stale issue. These issues will be closed automatically soon.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Use ArgumentException.ThrowIfNullOrEmpty
6 participants