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

Fix invalid usages of ArgumentNullException #4629

Merged
merged 1 commit into from Mar 15, 2018

Conversation

drewnoakes
Copy link
Member

Pretty simple change. Will annotate the diff with descriptions.

if (key == null)
{
var ex = new ArgumentNullException("KeySelector produced a key that is null. See exception data for source.");
var ex = new Exception("KeySelector produced a key that is null. See exception data for source.");
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two usages here are not validating arguments. They're validating the result of keySelector. Opted for Exception as that's what a lot of existing code does. Could be InvalidOperationException, but I'm indifferent.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Specifically, the first argument to ArgumentNullException is supposed to be a parameter name. Given there's no parameter here, it's not possible to use that exception type here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 You could use ArgumentException here since keySelector does not behavior in a manner consistent with the requirements of this method.

@@ -98,7 +98,7 @@ private bool HaveValidCommitMsgHook([NotNull] IGitModule gitModule, bool force)
{
if (gitModule == null)
{
throw new ArgumentNullException("gitDirectory");
throw new ArgumentNullException(nameof(gitModule));
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Previous code likely an artefact of refactoring. New code shouldn't have that problem in future.

@codecov
Copy link

codecov bot commented Mar 13, 2018

Codecov Report

Merging #4629 into master will not change coverage.
The diff coverage is 0%.

@@           Coverage Diff           @@
##           master    #4629   +/-   ##
=======================================
  Coverage   26.35%   26.35%           
=======================================
  Files         503      503           
  Lines       41424    41424           
  Branches     5997     5997           
=======================================
  Hits        10919    10919           
  Misses      30016    30016           
  Partials      489      489
Impacted Files Coverage Δ
GitExtUtils/Linq/LinqExtensions.cs 13.46% <0%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 663036a...539037c. Read the comment docs.

Copy link
Member

@sharwell sharwell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❗️ We should use a better type than just Exception. Multiple alternatives are viable, we can pick any that makes sense.

@drewnoakes
Copy link
Member Author

Replaced Exception with ArgumentException and included the argument name as the second arg in f6e5af0.

@gerhardol
Copy link
Member

Replaced Exception with ArgumentException and included the argument name as the second arg in f6e5af0.

For one occurrence only, intentional?

@drewnoakes
Copy link
Member Author

@gerhardol thanks, fixed in 539037c.

@RussKie RussKie merged commit 9359554 into gitextensions:master Mar 15, 2018
@RussKie RussKie added this to the 3.00 milestone Mar 15, 2018
@drewnoakes drewnoakes deleted the argument-exceptions branch March 15, 2018 12:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants