Analyze stack traces and log files with Cursor by pasting error output directly into Chat (Cmd+L), referencing the relevant source files with @file, and using @web for error message lookups. Cursor can parse multi-line stack traces, identify the failing function, and propose targeted fixes when given both the error and source code context.
Using Cursor as a Stack Trace Debugger
Stack traces contain all the information needed to diagnose a bug, but reading them requires understanding call chains, async boundaries, and framework internals. Cursor can parse stack traces instantly, identify the relevant source files, and propose fixes. This tutorial shows you how to use Chat and Composer effectively for debugging by providing the right combination of error output and source code context.
Prerequisites
- Cursor installed (Free or Pro)
- A stack trace or error log to analyze
- Access to the source code referenced in the stack trace
Step-by-step guide
Paste the stack trace into Cursor Chat
Paste the stack trace into Cursor Chat
Open Chat with Cmd+L and paste the full stack trace or error log. Cursor will automatically parse it, identify file paths, line numbers, and the error type. Ask it to explain the error and identify the root cause. The more complete the stack trace, the better the analysis.
1// Prompt to type in Cursor Chat (Cmd+L):2// Analyze this stack trace and identify the root cause:3//4// TypeError: Cannot read properties of undefined (reading 'map')5// at UserList (src/components/UserList.tsx:24:18)6// at renderWithHooks (node_modules/react-dom/...)7// at mountIndeterminateComponent (node_modules/react-dom/...)8// at beginWork (node_modules/react-dom/...)9//10// What is causing this error and how do I fix it?Pro tip: Always paste the FULL stack trace, not just the error message. The call chain helps Cursor understand the execution flow and identify the actual root cause versus the symptom.
Expected result: Cursor identifies the failing file (UserList.tsx:24), explains that a variable is undefined where an array was expected, and suggests adding a null check or default value.
Reference the failing source file for targeted fixes
Reference the failing source file for targeted fixes
After the initial analysis, reference the actual source file mentioned in the stack trace. Cursor will read the file, look at the exact line number, and provide a precise fix rather than a generic suggestion.
1// Follow-up prompt in the same Chat session:2// @src/components/UserList.tsx3// Look at line 24 of this file and provide the exact fix4// for the TypeError. Show me the corrected code.Pro tip: If the stack trace mentions multiple files, reference all of them. Cross-file bugs are common and Cursor can trace the data flow between files to find where the undefined value originates.
Expected result: Cursor reads the file, identifies the exact expression on line 24, and provides the corrected code with proper null handling.
Use @web for unfamiliar error messages
Use @web for unfamiliar error messages
For error messages you do not recognize, use @web context to have Cursor search for the latest solutions. This is particularly useful for framework-specific errors, library version issues, or errors with cryptic messages.
1// Prompt to type in Cursor Chat (Cmd+L):2// @web "NEXT_REDIRECT" error in Next.js 14 server component3//4// I'm getting this error in my server component:5// Error: NEXT_REDIRECT6// at redirect (node_modules/next/...)7//8// What causes this and how do I fix it?Expected result: Cursor searches the web for the latest information about the error and provides a fix based on current documentation and community solutions.
Create a reusable /debug command
Create a reusable /debug command
Create a custom Cursor command that any team member can use to analyze stack traces. Save it in .cursor/commands/ and trigger it with /debug in chat. This standardizes how your team approaches debugging with Cursor.
1---2description: Analyze a stack trace and propose fixes3---45Analyze the provided stack trace or error log:671. Parse the error type, message, and full call chain82. Identify the root cause file and line number93. Explain why the error occurs in plain language104. Read the referenced source files for context115. Provide the exact fix with corrected code126. Suggest how to prevent this error class in the future137. If the error is from a third-party library, search @web for known issues1415Format your response as:16- **Error**: [type and message]17- **Root cause**: [file:line and explanation]18- **Fix**: [corrected code]19- **Prevention**: [how to avoid this in the future]Pro tip: Team members paste a stack trace, type /debug, and get a structured analysis. This is especially helpful for junior developers who are learning to read stack traces.
Expected result: A reusable /debug command available to all team members for structured stack trace analysis.
Use Composer to fix bugs across multiple files
Use Composer to fix bugs across multiple files
For bugs that span multiple files, use Composer (Cmd+I) in Agent mode. Paste the error, reference the involved files, and let the agent trace the issue across files and apply fixes. Agent mode can also run the application to verify the fix.
1// Prompt to type in Cursor Composer (Cmd+I):2// I'm getting this error when submitting the checkout form:3// [paste full error with stack trace]4//5// @src/pages/CheckoutPage.tsx @src/api/orderApi.ts @src/hooks/useCart.ts6// Trace the data flow from form submission to API call.7// Identify where the bug is and fix it across all affected files.8// Run the dev server and verify the fix works.Pro tip: Agent mode can run your test suite to verify the fix. Add 'Run npm test after fixing to verify no regressions' to your prompt.
Expected result: Cursor traces the bug across multiple files, applies fixes, and optionally verifies them by running tests.
Complete working example
1---2description: Analyze a stack trace and propose fixes3---45Analyze the provided stack trace or error log.67## Step 1: Parse8- Identify the error type (TypeError, ReferenceError, custom error)9- Extract the error message10- List all application files in the call chain (skip node_modules)11- Note the originating file and line number1213## Step 2: Diagnose14- Read the source files referenced in the stack trace using @file15- Identify the exact expression causing the error16- Trace the data flow to find where the bad value originates17- Check for common patterns: undefined props, missing null checks,18 async race conditions, incorrect type assertions1920## Step 3: Fix21- Provide the corrected code for each affected file22- Explain why the fix works23- Show both the broken and fixed versions2425## Step 4: Prevent26- Suggest a TypeScript type change, test case, or runtime check27 that would catch this error earlier28- If applicable, suggest a .cursorrules entry to prevent the29 AI from generating this pattern in the future3031## Output Format32**Error**: `{error type}: {message}`33**Root cause**: `{file}:{line}` — {explanation}34**Fix**:35```typescript36// corrected code37```38**Prevention**: {suggestion}Common mistakes when analyzing Stack Traces with Cursor
Why it's a problem: Pasting only the error message without the full stack trace
How to avoid: Always paste the complete stack trace including all file paths and line numbers.
Why it's a problem: Not referencing the source files after initial analysis
How to avoid: Follow up with @file references to the specific files mentioned in the stack trace.
Why it's a problem: Debugging in a long existing chat session
How to avoid: Start a fresh chat with Cmd+N for each new debugging session.
Best practices
- Paste the complete stack trace including file paths and line numbers
- Reference the actual source files mentioned in the trace with @file for precise fixes
- Use @web for unfamiliar error messages or third-party library issues
- Create a /debug custom command for standardized team-wide debugging
- Start fresh chat sessions for each new debugging task to avoid context pollution
- Use Composer Agent mode for multi-file bugs that span several modules
- Ask Cursor to suggest prevention measures (types, tests, rules) alongside fixes
Still stuck?
Copy one of these prompts to get a personalized, step-by-step explanation.
Analyze this stack trace: [paste trace]. Identify the root cause file and line number. Explain why the error occurs. Provide the exact fix with corrected code. Suggest how to prevent this error type in the future with better TypeScript types or runtime checks.
@src/components/UserList.tsx Analyze this error and fix it: TypeError: Cannot read properties of undefined (reading 'map') at UserList (src/components/UserList.tsx:24:18) Read the file, identify the exact expression on line 24, and provide the corrected code with proper null handling.
Frequently asked questions
Can Cursor parse stack traces from any language?
Yes. Cursor understands stack traces from JavaScript, TypeScript, Python, Java, Go, Rust, and most other languages. It recognizes standard trace formats including file paths, line numbers, and call chains.
How do I debug production errors from Sentry with Cursor?
Copy the full stack trace and breadcrumbs from Sentry, paste them into Cursor Chat, and reference the relevant source files with @file. Cursor can parse Sentry's enriched error format including context lines and tags.
Can Cursor fix the error automatically?
Yes. In Composer Agent mode (Cmd+I), Cursor can read the stack trace, identify the failing file, apply the fix, and run tests to verify. For simple errors, it can complete the entire debug cycle autonomously.
What if the stack trace points to node_modules?
When the error originates in a third-party library, focus on your code's interaction with it. Reference your file that calls the library and use @web to search for the specific library error. The fix is usually in how you call the library, not in the library itself.
How do I analyze minified stack traces?
If you have source maps, Cursor can read them. Reference the source map file with @file. Without source maps, paste the minified trace and ask Cursor to identify the likely cause based on the error message and your source code context.
Talk to an Expert
Our team has built 600+ apps. Get personalized help with your project.
Book a free consultation