🕵️ Bug Fixing & Troubleshooting Protocol
"Don't just patch the symptom; cure the disease."
When you encounter an error, DO NOT immediately write code to fix it. Follow this 4-Step Investigation Protocol first.
🚨 Step 1: Triage (Diagnosis)
Analyze the error stack trace or behavior. Categorize the issue:
- •
Type A: Financial/Calculation Error (e.g.,
NaN,0.300004, Wrong Balance)- •👉 Directive: You MUST consult the
financial-mathskill. - •Check: Are we using
numberinstead ofDecimal? Are we mixing currencies?
- •👉 Directive: You MUST consult the
- •
Type B: Database/Prisma Error (e.g.,
Foreign key constraint failed,Connection limit)- •👉 Directive: You MUST consult the
prisma-data-modelingskill. - •Check: Are relations correct? Is the ID valid? Is the migration applied?
- •👉 Directive: You MUST consult the
- •
Type C: Security/Auth Error (e.g.,
Unauthorized,403 Forbidden)- •👉 Directive: You MUST consult the
security-auditskill. - •Check: Is
auth()called? Is the user modifying their own data?
- •👉 Directive: You MUST consult the
- •
Type D: Fetch/Network Error (e.g.,
Failed to fetch,500 Internal Server Error)- •👉 Directive: You MUST consult the
data-integration-layerskill. - •Check: Is the API down? Do we have a fallback?
- •👉 Directive: You MUST consult the
🧠 Step 2: Reproduction Strategy
Before fixing, prove you understand the bug.
- •Create a mental (or actual) reproduction case: "If I call
buyStockwith negative amount, it crashes."
🛠️ Step 3: The Surgical Fix
Apply the fix based on the consulted Skill's rules.
- •ANTI-PATTERN: Wrapping everything in
try/catchand returningnulljust to silence the error. NEVER DO THIS. - •CORRECT: Fix the logic validation or data type.
✅ Step 4: Verification
Refer to Skill: qa-testing
- •Run the reproduction case again. Does it pass?
- •Regression Check: Did this fix break something else? (e.g., Fixing Buy logic shouldn't break Sell logic).
🛑 Example Scenario
Error: Invalid value: 150.234234234 for field amount
Bot Thought Process:
- •Triage: This is a DB/Math error.
- •Consult:
financial-mathsays "No floats" andprisma-data-modelingsays "Decimal(19,4)". - •Root Cause: We are passing a raw JS float to Prisma.
- •Fix: Wrap the value in
new Decimal(amount).toFixed(4). - •Verify: Run test.