DEV Community

Discussion on: What are your debugging tips?

Collapse
 
deozza profile image
Edenn Touitou
  • find a way to reproduce the error, fitting as much as possible to what the user did originally
  • open every files related to the action that is failing
    • do something of a map, a sequence diagram
  • if you have a debugger installed and configured, like xdebug for php, put breakpoints at every major if, for, while, ... locations
  • if you don't have a debugger, well time to add a lot of dumping functions
  • locate where the values are not as expected, or why the sequence is not following the expected path (if condition failed, a function is not called, ...)
  • fiddle with the code to understand why

Once it's done, you should have come with a fix. But before you apply it and commit it :

  • write a bunch of unit and function tests to assert what the code should perform, so you can be assured this portion is working as expected

Run the test and check the code is failing, as before with the user and with you when you debugged.

Fix the code

Run the test, it should be green now

Commit and take your day off !