Skip to main content
AIPromptIndex
Cursor Coding beginner

Debug Error Detective

Added Apr 1, 2026

You are a senior software engineer who excels at debugging. I am encountering the following error in my [LANGUAGE] [PROJECT_TYPE] project: [ERROR_MESSAGE]. The error occurs when [TRIGGER_CONTEXT]. Here is the relevant code: [CODE_SNIPPET]. My environment: [ENVIRONMENT_DETAILS]. Please: 1) Explain what this error means in plain English, 2) Identify the root cause (not just the symptom), 3) Provide a step-by-step fix with code changes, 4) Explain why the fix works, 5) Suggest how to prevent this class of error in the future (linting rules, type safety, etc.), and 6) List any related issues this error might be hiding that I should check for.
0
Share
Try in Cursor

About This Prompt

Debugging is often the most frustrating part of development, especially when error messages are cryptic or misleading. This prompt turns the AI into a debugging partner that goes beyond fixing the immediate error to help you understand the root cause and prevent similar issues. The requirement to explain in plain English demystifies complex error messages, while the prevention suggestions help you write more defensive code going forward. The hidden issues check is particularly valuable because production bugs often mask underlying problems that surface later as harder-to-diagnose failures.

Variables to Customize

[LANGUAGE]

Programming language

Example: Python 3.11

[PROJECT_TYPE]

Type of project

Example: FastAPI web application

[ERROR_MESSAGE]

The full error message and stack trace

Example: TypeError: 'NoneType' object is not subscriptable at line 45 in user_service.py

[TRIGGER_CONTEXT]

What you were doing when the error occurred

Example: calling the /api/users/{id} endpoint with a valid user ID that exists in the database

[CODE_SNIPPET]

The relevant code around the error

Example: user = await db.fetch_one(query) return user['email']

[ENVIRONMENT_DETAILS]

Your development environment

Example: Python 3.11, FastAPI 0.104, asyncpg, PostgreSQL 15

Tips for Best Results

  • Include the full stack trace, not just the error message line
  • Mention any recent changes that might have introduced the bug
  • Provide your database schema if the error involves data access

Example Output

## Plain English Explanation
Your code is trying to access the 'email' key on a variable that is None (null). This means `db.fetch_one(query)` returned None instead of a user record.

## Root Cause
The `fetch_one` method returns None when no rows match the query, but your code assumes it always returns a valid row. Even though you say the user ID exists, the query might be using a different column or the connection might be hitting a different database/schema.

## Fix
```python
user = await db.fetch_one(query)
if user is None:
    raise HTTPException(status_code=404, detail=f'User {id} not found')
return user['email']
```
debugging error-handling troubleshooting code-fix

Get the Best AI Prompts Weekly

Curated prompts, tips, and guides delivered to your inbox every week. Free.