Skip to content

Issue 458 WithParam: throw exception if parameter starts with '$' (or… #460

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

Merged
merged 5 commits into from
Feb 7, 2023

Conversation

Clooney24
Copy link
Contributor

… any other not allowed character).

Issue 458 WithParam: throw exception if parameter starts with '$' (or any other not allowed character).

Issue 459 WithParam: exeption when using already existing param name outputs "key" instead of param name

… any other not allowed character).

Issue 459 WithParam: exeption when using already existing param name outputs "key" instead of param name
Copy link
Member

@cskardon cskardon left a comment

Choose a reason for hiding this comment

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

Hey Reiner,

Thank you for doing this, the exception messages need to be changed for the PR to be accepted, as setting the ParameterName property to being the nameof(theParameter) is important from the POV of what the actual exception should be passing around.

Otherwise, all good

if (parameters.Keys.Any(key => QueryWriter.ContainsParameterWithKey(key)))
throw new ArgumentException("A parameter with the given key is already defined in the query.", nameof(parameters));
throw new ArgumentException("A parameter with the given key is already defined in the query.", parameters.Keys.First(key => QueryWriter.ContainsParameterWithKey(key)));
Copy link
Member

Choose a reason for hiding this comment

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

This has the same issue as with the previous comment, the parameter called parameter is the problem.

The reason it should be this is if another parameter is added to the method, or something like that, you distinguish between those with that. The message can include the key that was invalid, but not the ParameterName property.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi, same here, nameof(parameters) is always "parameters". But the value of parameters.Keys.First(key => QueryWriter.ContainsParameterWithKey(key))) contains the key that is used duplicate.

image

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I just added a test for this to check duplicates in WithParams in the PR

Copy link
Member

Choose a reason for hiding this comment

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

And my argument still stands, the fact is that the parameter to the method is wrong, if the method had 4 parameters, all string (for example) and you just fire out the 'value' of the one that is wrong, you wouldn't be able to tell which of those parameters was wrong.

Value can go into the message, but the parameter name that is wrong is parameters

if (parameters.Keys.Any(key => QueryWriter.ContainsParameterWithKey(key)))
throw new ArgumentException("A parameter with the given key is already defined in the query.", nameof(parameters));
throw new ArgumentException("A parameter with the given key is already defined in the query.", parameters.Keys.First(key => QueryWriter.ContainsParameterWithKey(key)));
Copy link
Member

Choose a reason for hiding this comment

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

And my argument still stands, the fact is that the parameter to the method is wrong, if the method had 4 parameters, all string (for example) and you just fire out the 'value' of the one that is wrong, you wouldn't be able to tell which of those parameters was wrong.

Value can go into the message, but the parameter name that is wrong is parameters

@Clooney24
Copy link
Contributor Author

Changes pushed - sorry for the long-winded discussion.

@cskardon cskardon merged commit 3a80214 into DotNet4Neo4j:master Feb 7, 2023
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.

2 participants