Debugging
Systematic debugging frameworks for finding and fixing bugs - includes root cause analysis, defense-in-depth validation, and verification protocols
Category: development Source: mrgoonie/claudekit-skills
Systematic debugging frameworks for finding and fixing bugs - includes root cause analysis, defense-in-depth validation, and verification protocols
Category: development Source: mrgoonie/claudekit-skillsUserService. Pattern analysis reveals this only happens when certain optional fields are missing. Hypothesis testing by simulating incomplete payloads confirms the cause. The fix then ensures field validation at the source. python ## Example: Defensive field validation before business logic def create_user(payload): if 'email' not in payload or not payload['email']: raise ValueError("Email is required") # Business logic proceeds only if validation passes ### Root Cause Tracing Trace errors backward through the call stack or data flow. For example, when a calculation returns an unexpected result, follow the data from the output back to the initial input, inspecting each transformation. Example: javascript function calculateTotal(cart) { if (!Array.isArray(cart.items)) { throw new Error("Invalid items array"); } // Further processing... } Here, the bug is traced to cart.items not being an array in certain invocations, revealing the original data source as the true fix location. ### Defense-in-Depth Validation Implement validation at multiple layers: - Entry Point: Initial input validation (e.g., API request payloads) - Business Logic: Assertions within domain logic - Environment Guards: Check preconditions (e.g., database connectivity) - Debug Instrumentation: Add logging and metrics to observe runtime behavior Example: go func ProcessOrder(order Order) error { if !order.IsValid() { log.Error("Order failed validation at entry point") return errors.New("invalid order") } // Business logic checks if order.Amount <= 0 { log.Error("Invalid amount in business logic") return errors.New("amount must be positive") } // Environment guard if !db.IsConnected() { log.Error("DB not connected") return errors.New("service unavailable") } // Debug instrumentation log.Info("Order processed successfully") return nil } ### Verification Before Completion No fix is complete without demonstrable evidence that the issue is resolved. Always rerun tests or verification scripts, and capture outputs as proof. Example: bash ## Run unit tests before closing the bug ticket pytest tests/test_user_service.py Attach the output to the issue tracker as verification. ## Best Practices - Never fix without root cause analysis. Resist quick patches—always investigate the original trigger. - Validate at every layer. Defense-in-depth makes entire classes of bugs impossible. -