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

Support ArgumentException for the GuardClauseAssertion #1107

Open
zvirja opened this issue Mar 11, 2019 · 3 comments · May be fixed by #1121
Open

Support ArgumentException for the GuardClauseAssertion #1107

zvirja opened this issue Mar 11, 2019 · 3 comments · May be fixed by #1121
Labels
enhancement feature request An idea for a change, aimed at impoving quality of life Idioms An issue related to idiomatic assertions

Comments

@zvirja
Copy link
Member

zvirja commented Mar 11, 2019

Currently GuardClauseAssertion supports only ArgumentNullException for the null guard. It's very inconvenient, as sometimes you are checking inputs like following:

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

I suggest to also allow ArgumentException with the right parameter name, as it's still a valid guard clause.

@Kralizek
Copy link
Contributor

I'm torn about it. I see the need but it opens a can of use cases, like "accepted integer must be greater than zero".

@zvirja
Copy link
Member Author

zvirja commented Mar 11, 2019

@Kralizek Could you please elaborate a bit more? The current issue is to accept the ArgumentException exception with ParamName == nameof(argument) when it's thrown for null input. It's only about particular check for null we already have and it doesn't enable any other scenario per se (like range validations) - those capabilities are already present anyway 😉

@Kralizek
Copy link
Contributor

@zvirja oh really? Shame on me! I couldn't find how to do it! Then nevermind! 😁

@zvirja zvirja linked a pull request May 28, 2019 that will close this issue
@aivascu aivascu added feature request An idea for a change, aimed at impoving quality of life Idioms An issue related to idiomatic assertions labels Dec 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement feature request An idea for a change, aimed at impoving quality of life Idioms An issue related to idiomatic assertions
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants