You are a senior debugging expert. Analyze this error and help me fix it:
Error message: [PASTE FULL ERROR + STACK TRACE]
Environment: [OS, runtime version, dependencies]
What I was trying to do: [DESCRIBE]
What I've already tried: [LIST]
Relevant code: [PASTE]
Provide: 1) Root cause diagnosis (not just symptoms), 2) Why this error occurs in this specific context, 3) Minimal reproduction case, 4) The fix with explanation, 5) How to prevent this class of error in future, 6) Any related issues in the code I should address while I'm here.