Skip to content

Systematically Debug and Fix Errors

Systematically debug and fix errors

Instructions

Follow this comprehensive debugging methodology to resolve: $ARGUMENTS

  1. Error Information Gathering
  2. Collect the complete error message, stack trace, and error code
  3. Note when the error occurs (timing, conditions, frequency)
  4. Identify the environment where the error happens (dev, staging, prod)
  5. Gather relevant logs from before and after the error

  6. Reproduce the Error

  7. Create a minimal test case that reproduces the error consistently
  8. Document the exact steps needed to trigger the error
  9. Test in different environments if possible
  10. Note any patterns or conditions that affect error occurrence

  11. Stack Trace Analysis

  12. Read the stack trace from bottom to top to understand the call chain
  13. Identify the exact line where the error originates
  14. Trace the execution path leading to the error
  15. Look for any obvious issues in the failing code

  16. Code Context Investigation

  17. Examine the code around the error location
  18. Check recent changes that might have introduced the bug
  19. Review variable values and state at the time of error
  20. Analyze function parameters and return values

  21. Hypothesis Formation

  22. Based on evidence, form hypotheses about the root cause
  23. Consider common causes:

    • Null pointer/undefined reference
    • Type mismatches
    • Race conditions
    • Resource exhaustion
    • Logic errors
    • External dependency failures
  24. Debugging Tools Setup

  25. Set up appropriate debugging tools for the technology stack
  26. Use debugger, profiler, or logging as needed
  27. Configure breakpoints at strategic locations
  28. Set up monitoring and alerting if not already present

  29. Systematic Investigation

  30. Test each hypothesis methodically
  31. Use binary search approach to isolate the problem
  32. Add strategic logging or print statements
  33. Check data flow and transformations step by step

  34. Data Validation

  35. Verify input data format and validity
  36. Check for edge cases and boundary conditions
  37. Validate assumptions about data state
  38. Test with different data sets to isolate patterns

  39. Dependency Analysis

  40. Check external dependencies and their versions
  41. Verify network connectivity and API availability
  42. Review configuration files and environment variables
  43. Test database connections and query execution

  44. Memory and Resource Analysis

    • Check for memory leaks or excessive memory usage
    • Monitor CPU and I/O resource consumption
    • Analyze garbage collection patterns if applicable
    • Check for resource deadlocks or contention
  45. Concurrency Issues Investigation

    • Look for race conditions in multi-threaded code
    • Check synchronization mechanisms and locks
    • Analyze async operations and promise handling
    • Test under different load conditions
  46. Root Cause Identification

    • Once the cause is identified, understand why it happened
    • Determine if it's a logic error, design flaw, or external issue
    • Assess the scope and impact of the problem
    • Consider if similar issues exist elsewhere
  47. Solution Implementation

    • Design a fix that addresses the root cause
    • Consider multiple solution approaches and trade-offs
    • Implement the fix with appropriate error handling
    • Add validation and defensive programming where needed
  48. Testing the Fix

    • Test the fix against the original error case
    • Test edge cases and related scenarios
    • Run regression tests to ensure no new issues
    • Test under various load and stress conditions
  49. Prevention Measures

    • Add appropriate unit and integration tests
    • Improve error handling and logging
    • Add input validation and defensive checks
    • Update documentation and code comments
  50. Monitoring and Alerting

    • Set up monitoring for similar issues
    • Add metrics and health checks
    • Configure alerts for error thresholds
    • Implement better observability
  51. Documentation

    • Document the error, investigation process, and solution
    • Update troubleshooting guides
    • Share learnings with the team
    • Update code comments with context
  52. Post-Resolution Review

    • Analyze why the error wasn't caught earlier
    • Review development and testing processes
    • Consider improvements to prevent similar issues
    • Update coding standards or guidelines if needed

Remember to maintain detailed notes throughout the debugging process and consider the wider implications of both the error and the fix.