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

[IMPROVEMENT] Improve Error Messages #33

Open
smusali opened this issue May 16, 2023 · 0 comments
Open

[IMPROVEMENT] Improve Error Messages #33

smusali opened this issue May 16, 2023 · 0 comments
Labels
enhancement New feature or request

Comments

@smusali
Copy link
Contributor

smusali commented May 16, 2023

  1. The Importance of Clear Error Messages: When tests fail, the error messages are the first source of information to understand what went wrong. Clear, informative error messages help developers quickly identify and address issues. They serve as a guide pointing out the specific component or functionality that has failed and providing hints on the possible reasons for the failure.
  2. Customizing Error Messages: When writing tests, use the ability to provide custom error messages in your assertions. These custom messages should be clear and specific. They should indicate what was being tested, the expected result, and how it differed. This can make debugging test failures much faster and less frustrating. In testthat, you can provide custom messages to most of the expect_* functions.
  3. Using Error Classes: Errors classes like other objects. I think this can be useful in your tests. If your code throws errors with specific classes, your tests can check that an error was thrown and that an error of the correct class was thrown. This can help catch situations where an error might be thrown for the wrong reason.
  4. Verbose and Informative Errors: Aim to make your error messages as informative as possible. They should contain all the information necessary to understand the problem without looking at the code that caused it. Consider including details such as the function or method where the error occurred, the values of critical variables or parameters, and the expected vs. actual outcomes.
  5. Consistency in Error Messages: Be consistent in your error messages. Using similar phrasing or structure for your error messages can make it easier for others (and your future self) to understand them. For example, you might always start your error messages with the function's name or method where the error occurred.
  6. Updating Error Messages as Code Evolves: Ensure your error messages stay current as your codebase evolves. If you change how a function works, you may need to update the error messages to reflect those changes.
  7. Documenting Errors: Consider documenting common errors and their meanings somewhere in your project. This can be useful for other developers or users who encounter these errors.
@smusali smusali added the enhancement New feature or request label May 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant