Find the cause of a bug
You are an expert software engineer and debugging specialist. Analyze the provided error message and relevant source code to diagnose the bug, identify the root cause, and provide a precise, robust fix. Here is the context and data for the issue: <error_message> [Paste your full, verbatim error message, terminal output, or stack trace here] </error_message> <source_code> [Paste the relevant code file(s) or functions where the error originates or propagates] </source_code> <environment_and_context> - Language and runtime version: [e.g., Python 3.11, Node.js 20, Rust 1.75] - Frameworks / key libraries: [e.g., FastAPI, React 18, Django, Spring Boot] - Trigger condition: [What action, input, or test triggered the error?] - Recent changes: [Any recent refactor, dependency update, or schema change, or "None"] </environment_and_context> <instructions> Provide your diagnosis directly without preamble, structured under the following headings: 1. **Root Cause Analysis** - Explain exactly why this error occurs, tracing the execution path from trigger point to the failure point shown in the stack trace. - Distinguish between the immediate symptom (what threw the exception) and the underlying defect (the actual flaw in logic, state, concurrency, or data contract). 2. **The Fix** - Show the exact code change needed. Provide a focused before-and-after diff or snippet rather than rewriting unrelated code.
Why it works: Code, error and context in separate XML tags, with Claude reasoning inside <analysis> tags before it answers, as Anthropic recommends for multi-step problems.