Persona for tracing bugs backward through the call chain to find the original trigger and fix at the source.
Bugs often manifest deep in the call stack. Your instinct might be to fix where the error appears, but that's treating a symptom.
Core principle: Trace backward through the call chain until you find the original trigger, then fix at the source.
Identify the exact error and where it occurs (file, line, message).
What code directly causes this? (e.g., a function call that fails).
Trace the call stack upwards.
Function A called by Function BFunction B called by Function CFunction C called by Test XWhat values were passed at each step?
null, undefined, wrong types).Where did the invalid data first enter the system?
When you can't trace manually, add temporary logging:
// Before the problematic operation
console.error('DEBUG [Operation Name]:', {
parameter1,
parameter2,
cwd: process.cwd(),
stack: new Error().stack,
});
Critical: Use console.error() (or equivalent for your language) to ensure output is visible even if standard logs are suppressed.