Skip to content

Instantly share code, notes, and snippets.

@waf
Created July 6, 2022 07:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save waf/085ab1e7edca7fa89d0876b4006f6a71 to your computer and use it in GitHub Desktop.
Save waf/085ab1e7edca7fa89d0876b4006f6a71 to your computer and use it in GitHub Desktop.
Debugging Tips - the following is originally from https://www.debug.coach/ which is super useful but has since gone offline.

A collection of questions and mental models the pros use when debugging

  1. What question can you ask that will eliminate half the possible answers? Ask that first.
    • Ask broad questions before asking specific ones. For example ask “have you checked the logs?” Before asking “have you checked the dev tools console log?”
  2. Have you checked the logs?
    • Application Logs
    • System Logs
    • Web Server Logs
    • Database Logs
    • Browser Dev Tools Console/Network Tabs
  3. Are there any error helpful error codes you can lookup?
  4. Have you stepped through it in a debugger?
    • Have you walked through the stacktrace in the debugger?
    • If you can’t place a breakpoint directly can you manually add a breakpoint on a specific exception and then subsequently walk up the stacktrace to get to the actual problem?
  5. Have you tried rubber ducking it?
  6. Have you sought out and compared it deeply with a working/known good example?
  7. An error message says XYZ missing/not found/doesn’t exist
    • have you checked that it does or doesn’t actually exist? The computer is usually telling you it doesn’t exist or can’t be found because it doesn’t actually exist and therefore cannot be found.
    • have you tried doing a clean build?
    • have you actually even deployed the code?
  8. Is there a typo somewhere?
    • did you (very) carefully check capitilization?
      • setup vs. Setup vs. SetUp #datapoint
      • Is there a naming convention that expects capitilization other than what you have used?
    • has something been renamed and something is still pointing to the old name?
    • have you copy pasted something from one place where it was spelled incorrectly and then subsequently typed it out correctly manually at a later stage and hence things don’t match somewhere?
  9. Is it a permissions issue?
    • Does it work if you run it as a different user?
    • Does something else own a lock because the resources is in use by another process?
      • once a schema script refused to run because I had the very screen open in edit mode that used the table so a row was locked and the schema script failed with cryptic errors. #datapoint
    • Does your user own the necessary locks?/have they been granted the necessary role?
  10. Are you being tricked by your assumptions?
    • Has something cached an output and that’s why you are still seeing the old behaviour?
    • Are you assuming you have a recent code change because it has been merged to master, but actually you have not updated your branch?
    • Are there actually two different things/classes/objects/scripts/files with the same name and you don’t realize they are actually different?
      • I was troubleshooting an issue and assumed the Optional<> I was seeing was Java 8’s optional when in fact it was actually a class called Optional that served exactly the same purpose as Java 8’s Optional but it was written years before Java 8 came out. #datapoint
  11. What do the docs have to say about the expected behavior?
  12. Could it be a problem with inheritance?
    • Is there a method overriding the behaviour you’re currently looking at?
    • Is the behavior you are observing actually located in the superclass or somewhere else in the inheritance hierarchy?
  13. Do you know when the error was introduced?
    • Has someone (or perhaps another system) made a change recently either to configuration or code that could be affecting the behavior you are seeing?
      • is a new code path being executed that wasn’t previously being executed because of this change?
    • Have you checked the history of the file in the version control system to see how it has changed throughout time and if that might be of any relevance?
    • If you are not sure when the error was introduced have you tried using binary search on the commit history to locate exactly which commit introduced the error by checkout out the commit, building it and testing the behavior then iterating that process until you find it?
  14. Is it a timing/ordering issue?
  15. Is the file symlinked?
  16. Is it a path/build path/classpath issue?
    • Have you looked at the file that defines the path/build path/.classpath and check is every folder/resource that you expect to be declared there actually declared?
    • If a particular file is missing from the path/build path/classpath, which folder is that file in? Is that folder listed in the path/build path/classpath?
  17. Help! There is a NullPointerException which nothing on this line could possibly generate! What’s going on?
    • Is a null Integer being passed into a method signature of myMethod(int someInt); and being auto-unboxed at runtime causing an unexpected NullPointerException because int by definition cannot be null? Nasty.
  18. Could it be an environmental difference?
    • Could there be different versions of a part of the techstack that are behaving differently?
    • If dev and prod use different webservers or databases i.e Tomcat for dev but WebLogic for prod or MySql for dev and Oracle for prod could there be a difference in the way an API or spec is implemented by the different vendors?
      • Case in point Tomcat’s expression language implementation allows method signatures of both public boolean isSomething(); and public Boolean isSomething(); but WebLogic only allows public boolean isSomething();
  19. Is a resource at capacity?
    • out of memory?
    • out of disk?
    • out of bandwidth?
    • too many simultaneous connections to a server/disk?
  20. Is a resource unavailable?
    • are there any 3rd party services that are relied on but unable to connect to?
    • Is there a server that is expected to be running or a network location that is expected to be available?
  21. Could there be a bug in a library/3rd party code?
    • Is the source code available to look at?
  22. Could there be a possible race condition?
  23. Have you tried turning it on an off again?
    • bounce the server?
    • bounce the database?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment