TypeScript Errors
Agent: Run tsc and fix all TypeScript errors
With YOLO mode, Agent iterates until build passes
Debugging is no longer about manually adding print statements and staring at stack traces. With Cursor’s AI assistance, you can diagnose issues in minutes that would traditionally take hours, automatically fix errors, and even prevent bugs before they happen.
The most powerful debugging pattern: Let AI add logging, run code, analyze output, and fix issues automatically.
AI adds strategic logging
Agent: Add logging to understand why user sessions are expiring
Run code with instrumentation
Agent executes code, captures all log output
AI analyzes logs
Based on logs: "Sessions expire because cookie lacksSecure flag on HTTPS connections"
Automatic fix generation
Agent fixes the issue and verifies the solution
User: The payment processing is failing intermittently
Agent: I'll add strategic logging to diagnose this issue.
[Adds logging around payment API calls, database transactions,and error handling]
Running the payment flow 10 times to capture the pattern...
Analysis: The issue occurs when:1. Database connection pool is exhausted (8/10 failures)2. Payment API rate limit hit (2/10 failures)
Let me fix both issues:- Adding connection pool retry logic- Implementing exponential backoff for API calls
[Implements fixes][Runs 50 more tests - 100% success rate]
The intermittent failures are now resolved.
Use @Linter-errors
to automatically fix code quality issues:
TypeScript Errors
Agent: Run tsc and fix all TypeScript errors
With YOLO mode, Agent iterates until build passes
ESLint Issues
Agent: Fix all ESLint warnings and errors
AI understands intent behind lint rules
Python Type Hints
Agent: Add missing type hints based on mypy output
Comprehensive type safety without manual work
Format & Style
Agent: Run prettier and fix all formatting
Consistent code style automatically maintained
# Create a pre-PR command that runs all checks{ "scripts": { "pre-pr": "npm run lint && npm run test && npm run build" }}
Then simply:
Agent: Run npm run pre-pr and fix any issues until it passes
Connect Cursor to production error tracking for automated resolution:
User: Check Sentry for recent errors and create fixes
Agent: Analyzing Sentry dashboard...
Found 3 critical issues:1. NullPointerException in UserService.getProfile() - 147 occurrences2. API timeout in PaymentGateway - 23 occurrences3. Invalid date format in ReportGenerator - 89 occurrences
Starting with the most frequent issue:
[Opens UserService.java]The null pointer occurs when user.getPreferences() returns nullbut we don't check before calling .getTheme().
Creating fix with null safety:
Use Cursor’s bug finder before committing:
Command: Ctrl+Shift+P → "bug finder"
Agent analyzes your changes and identifies:- Potential null pointer exceptions- Missing error handling- Security vulnerabilities- Performance issues- Logic errors
Bug Finder Results:
1. 🔴 Critical: Potential SQL injection in UserQuery.java:45 - User input directly concatenated into query - Suggested fix: Use parameterized queries
2. 🟡 Warning: Missing null check in calculateTotal(): - items parameter could be null - Suggested fix: Add null guard clause
3. 🟡 Warning: Inefficient loop in processOrders(): - N+1 query pattern detected - Suggested fix: Use batch loading
Agent: Would you like me to fix these issues?
AI can identify and fix performance bottlenecks:
Agent: Profile the slow endpoint and identify bottlenecks
Running performance profiler...
Results:- 45% time in database queries- 30% time in JSON serialization- 15% time in business logic- 10% other
Main bottleneck: Missing database index on user_id
Agent: This query takes 2.3 seconds. Optimizing...
Issues found:1. Missing index on frequently queried column2. Unnecessary JOIN with unused table3. SELECT * instead of specific columns
After optimization: 0.087 seconds (26x faster)
Agent: Analyzing memory usage patterns...
Found potential leak: EventListeners not being removedin ComponentManager. Each mount adds listeners butunmount doesn't clean them up.
Adding cleanup in componentWillUnmount()
Agent: Compare working version (commit abc123) with broken versionto identify what caused the regression
Analyzing differences...
The issue was introduced in commit def456:- Changed authentication flow- Removed session validation step- This causes immediate logout on page refresh
Reverting problematic change and adding test to prevent regression
Agent: Debug why orders are failing in microservices architecture
Tracing request flow:1. ✓ Order Service receives request2. ✓ Inventory Service reserves items3. ✗ Payment Service times out4. ✗ Order Service rollback fails
Root cause: Payment Service database connection pool exhaustedSecondary issue: Rollback transaction missing timeout handling
Fixing both issues...
Agent: This test passes locally but fails in CI. Investigating...
Adding timing logs around critical sections...
Found race condition:- Test assumes API call completes before UI update- In CI (slower environment), UI updates first- Test checks for data that hasn't loaded yet
Adding proper async/await and wait conditions
Agent: The last deployment caused errors. Rolling back...
1. Identifying last working version from Git tags2. Creating revert PR for problematic changes3. Running tests to ensure rollback is clean4. Deploying previous stable version5. Creating incident report with root cause
# Configure self-healing behaviorsAgent: Monitor application health and auto-fix common issues:
- If memory usage > 80%: Trigger garbage collection- If response time > 2s: Clear caches and restart workers- If error rate > 5%: Switch to degraded mode- If database connection fails: Attempt reconnection with backoff
Frontend + Backend
Agent traces issues across full stack, from UI to database
Async Operations
AI adds timing logs to identify race conditions and deadlocks
Third-Party APIs
Mock external services to isolate issues and test error cases
Production vs Local
Agent helps reproduce production issues in local environment
Test failing: UserAuthentication.test.js
Agent: Let me debug this test failure.
1. Running test in isolation - FAILS2. Adding verbose logging to test3. Test expects 'user.role' but getting undefined4. Checking recent changes...5. Found: Schema migration added 'role' but seed data wasn't updated6. Updating test fixtures with role field7. Test now passes ✓
URGENT: Users can't log in - production issue
Agent: Investigating login failure...
1. Checking recent deployments (2 hours ago)2. Examining error logs: "Invalid JWT secret"3. Environment variable JWT_SECRET not set in production4. Creating hotfix: - Adding fallback for missing env var - Logging warning when using fallback - Creating urgent PR
Fix deployed. Login restored.Total resolution time: 8 minutes.
When Cursor itself has problems:
Solution:1. Run network diagnostics: Settings → Network → Run Diagnostics2. Check firewall/proxy settings3. Try HTTP/1.1 fallback if HTTP/2 is blocked4. Verify internet connectivity
Solution:1. Check if indexing is in progress2. Disable problematic extensions: cursor --disable-extensions3. Clear cache and restart4. Monitor MCP server logs for issues
Solution:1. Verify API quota not exceeded2. Check Privacy Mode settings3. Ensure files are indexed: Settings → Indexing & Docs4. Try switching AI models
Defensive Coding
Let AI add null checks, input validation, and error boundaries
Early Testing
Write tests with implementation to catch issues immediately
Type Safety
Use TypeScript/type hints to prevent runtime errors
Code Reviews
BugBot catches issues before they reach production
Track these metrics to see improvement:
Master debugging with AI assistance: