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

Enhance ValueError messages (#148 and #157) #185

Merged

Conversation

LaurentAjdnik
Copy link
Collaborator

For feedback: First attempt to enhance ValueError messages (see #148 and #157), starting with register.py.

Guidelines:

  • Functional explanation of parameter
  • Technical name of parameter
  • Provided value of parameter
  • Using "must" rather than any other verb
  • No negation
  • Using "less than / equal to / greater than" rather than any other expression
  • Recall allowed values
  • All sentences follow the same structure

Copy link
Collaborator

@HGSilveri HGSilveri left a comment

Choose a reason for hiding this comment

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

No complaints, I agree that this is much cleaner

@@ -147,11 +147,13 @@ def test_max_connectivity():
reg = Register.max_connectivity(2, None)

# Check min number of atoms
with pytest.raises(ValueError, match=r"The number of qubits(.+)or above"):
with pytest.raises(ValueError,
match=r"The number of qubits(.+)greater than"):
Copy link
Collaborator

Choose a reason for hiding this comment

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

Cool, I didn't know about this syntax

@HGSilveri
Copy link
Collaborator

@LaurentAjdnik So, how do you want to go about this? Doing this for the whole code seems like a big task. But also, I was wondering about how we can enforce it automatically, for anyone contributing to the code base.

I had an idea to have a test in CI that would search the code for specific errors and check if their message is valid. For example, it would identify "threshold" value errors and check if the message follows the specific guidelines. What do you think about this?

@LaurentAjdnik
Copy link
Collaborator Author

@LaurentAjdnik So, how do you want to go about this? Doing this for the whole code seems like a big task.

Still, I had planned to do it. 😇

But also, I was wondering about how we can enforce it automatically, for anyone contributing to the code base.

Automatically? I have not clue... I can only think of writing guidelines in CONTRIBUTING.md and checking if it's done when a PR arrives...

I had an idea to have a test in CI that would search the code for specific errors and check if their message is valid. For example, it would identify "threshold" value errors and check if the message follows the specific guidelines. What do you think about this?

Cool! How would you do that?

@HGSilveri
Copy link
Collaborator

@LaurentAjdnik So, how do you want to go about this? Doing this for the whole code seems like a big task.

Still, I had planned to do it. 😇

Thanks a lot for the initiative!

I had an idea to have a test in CI that would search the code for specific errors and check if their message is valid. For example, it would identify "threshold" value errors and check if the message follows the specific guidelines. What do you think about this?

Cool! How would you do that?

First, we have to layout all the guidelines for the error messages. At first, we could try to check for specific patterns that all errors of a given type should follow, based on these guidelines. This will be easier said than done, considering the variability that can occur within a single error type (eg ValueError). Depending on how far we want to take this, it might be necessary to create custom subclasses to further specify the error involved (e.g. ValueThresholdError, etc...), though this might be overkill for now.

@HGSilveri
Copy link
Collaborator

@LaurentAjdnik do you have anything to add to this PR before I merge it?

@LaurentAjdnik
Copy link
Collaborator Author

@LaurentAjdnik do you have anything to add to this PR before I merge it?

Nope.

Copy link
Collaborator

@HGSilveri HGSilveri left a comment

Choose a reason for hiding this comment

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

LGTM

@HGSilveri HGSilveri merged commit 30ee47a into pasqal-io:develop Jun 2, 2021
@LaurentAjdnik
Copy link
Collaborator Author

First, we have to layout all the guidelines for the error messages. At first, we could try to check for specific patterns that all errors of a given type should follow, based on these guidelines. This will be easier said than done, considering the variability that can occur within a single error type (eg ValueError). Depending on how far we want to take this, it might be necessary to create custom subclasses to further specify the error involved (e.g. ValueThresholdError, etc...), though this might be overkill for now.

Indeed, it does sound like a lot of hassle for something not so worth it.

I guess we should keep it simple for now: Let's officialize some guidelines, make sure all existing ValueErrors are updated accordingly (*) and check any PR coming in.

(*) Most of the time, when in doubt, people check existing parts of code to make sure they comply to guidelines. That's what I did anyway. 😉

@HGSilveri
Copy link
Collaborator

I guess we should keep it simple for now: Let's officialize some guidelines, make sure all existing ValueErrors are updated accordingly (*) and check any PR coming in.

(*) Most of the time, when in doubt, people check existing parts of code to make sure they comply to guidelines. That's what I did anyway. 😉

I agree. My only concern is the compliance with the guidelines, and the need for the reviewer to remember to check for them. In general, I prefer to have as much checks as possible happening automatically, so as not to pile on the things the reviewer as to look for. But I agree that, at least for now, what you suggest seems sufficient.

@HGSilveri HGSilveri mentioned this pull request Jun 8, 2021
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