Claude Sonnet 4.6 / GPT-4o / Gemini 2.5 ProDebug runtime errors faster — paste the error, stack trace, and relevant code snippet, and get a root cause diagnosis with a working fix and a clear explanation.Developer Tools

رمزگشای Stack Trace: هر خطایی را Paste کنید، علت ریشه‌ای و راه حل را در چند ثانیه دریافت کنید

اشتراک‌گذاری:
رمزگشای Stack Trace: هر خطایی را Paste کنید، علت ریشه‌ای و راه حل را در چند ثانیه دریافت کنید

Why this prompt matters

Debugging is where developer time disappears. Reading a stack trace tells you where the crash happened, but not why. This prompt gives you both — a diagnosis that explains the root cause in plain language, the exact code change to fix it, and an explanation of the underlying mechanism so you don't hit the same bug twice. It works regardless of language or framework because it reasons from the error text and stack trace, not from memorized APIs.

What we use it for

Debug runtime errors faster — paste the error, stack trace, and relevant code snippet, and get a root cause diagnosis with a working fix and a clear explanation.

Prompt

I'm debugging an error. Please help me understand what went wrong and how to fix it.

**Error message:**
[PASTE ERROR MESSAGE HERE]

**Stack trace:**
[PASTE FULL STACK TRACE HERE]

**Relevant code (the function/file where the error originates):**
```
[PASTE CODE HERE]
```

**Context:**
- Language/runtime: [e.g. Python 3.11, Node.js 22, Go 1.22]
- What I was trying to do when the error occurred: [one sentence]
- What I've already tried: [or "nothing yet"]

Please provide:
1. **Root cause** — explain in plain language what actually went wrong and why
2. **The fix** — show the corrected code with inline comments explaining the change
3. **Why this happened** — the underlying mechanism or misconception that caused the bug, so I understand it rather than just copying the fix
4. **Prevention** — one sentence on how to avoid this class of error in the future

Result

The Prompt

I'm debugging an error. Please help me understand what went wrong and how to fix it.

**Error message:**
[PASTE ERROR MESSAGE HERE]

**Stack trace:**
[PASTE FULL STACK TRACE HERE]

**Relevant code (the function/file where the error originates):**
```
[PASTE CODE HERE]
```

**Context:**
- Language/runtime: [e.g. Python 3.11, Node.js 22, Go 1.22]
- What I was trying to do when the error occurred: [one sentence]
- What I've already tried: [or "nothing yet"]

Please provide:
1. **Root cause** — explain in plain language what actually went wrong and why
2. **The fix** — show the corrected code with inline comments explaining the change
3. **Why this happened** — the underlying mechanism or misconception that caused the bug, so I understand it rather than just copying the fix
4. **Prevention** — one sentence on how to avoid this class of error in the future

How to Use It

Copy the template above. Fill in the four sections — error message, stack trace, code, and context. The more complete the stack trace, the better the diagnosis. You don't need to edit or clean it up; paste it raw.

The context section is optional but worth filling in. "What I was trying to do" helps the model understand intent. "What I've already tried" prevents it from suggesting things you've already ruled out.

What You Get Back

The four-part response structure is designed specifically to avoid the two most common failure modes of AI debugging help:

  • The blind fix — giving you corrected code without explaining why the original was wrong. You apply it, it works, but you don't understand it and hit the same pattern in a different file next week.
  • The vague diagnosis — "it looks like there might be a null reference issue." No specifics, no fix, no path forward.

The structured output forces specificity: root cause first (what is actually broken), then the fix with inline comments (not just a code dump), then the mechanism (the why behind the why), then prevention (a rule you can internalize).

Works Across Languages

This prompt is language-agnostic. It works well with:

  • Python — great for tracebacks, import errors, type errors, async/await issues
  • JavaScript / TypeScript — handles Node.js errors, browser console exceptions, TypeScript compiler errors
  • Go — runtime panics, goroutine stack traces, interface assertion failures
  • Java / Kotlin — NullPointerException chains, JVM stack traces, Spring context errors
  • Rust — compiler error messages (which are already detailed but still benefit from explanation)
  • SQL — query parse errors, constraint violations, deadlock traces from PostgreSQL/MySQL

For compiled languages where the stack trace is less informative, paste the full compiler output along with the error.

Example Input and Output

Input (simplified):

Error message: TypeError: Cannot read properties of undefined (reading 'map')

Stack trace:
  at ProductList (ProductList.jsx:14:22)
  at renderWithHooks (react-dom.development.js:14985:18)

Relevant code:
function ProductList({ products }) {
  return (
    <ul>
      {products.map(p => <li key={p.id}>{p.name}</li>)}
    </ul>
  );
}

Context: React 18, Node 22. Trying to render a list fetched from an API.

What a good response looks like:

  • Root cause: products is undefined when the component first renders, before the API response arrives. .map() can't run on undefined.
  • Fix: Add a default value — function ProductList({ products = [] }) — or add a null guard before the map.
  • Why this happened: React renders synchronously before async data fetches resolve. The component renders with whatever initial value the parent passes, which is undefined if the parent hasn't set an initial state yet.
  • Prevention: Always initialize list props with a default empty array and handle loading/empty states explicitly in the component.

Tips for Better Results

  • Paste the full stack trace, not just the top line. Lower frames often reveal the actual call that triggered the error.
  • Include the immediate surrounding code, not just the line that errored. A few lines of context above and below matter.
  • If the error is intermittent, say so — the model will consider race conditions and timing issues.
  • For TypeScript errors, include the tsconfig.json relevant settings if the error is about strictness or module resolution.

پرامپت (Prompt)

I'm debugging an error. Please help me understand what went wrong and how to fix it.

**Error message:**
[PASTE ERROR MESSAGE HERE]

**Stack trace:**
[PASTE FULL STACK TRACE HERE]

**Relevant code (the function/file where the error originates):**
```
[PASTE CODE HERE]
```

**Context:**
- Language/runtime: [e.g. Python 3.11, Node.js 22, Go 1.22]
- What I was trying to do when the error occurred: [one sentence]
- What I've already tried: [or "nothing yet"]

Please provide:
1. **Root cause** — explain in plain language what actually went wrong and why
2. **The fix** — show the corrected code with inline comments explaining the change
3. **Why this happened** — the underlying mechanism or misconception that caused the bug, so I understand it rather than just copying the fix
4. **Prevention** — one sentence on how to avoid this class of error in the future

چطور از این پرامپت استفاده کنید

قالب بالا را کپی کنید. چهار بخش — پیام خطا، stack trace، کد و کانتکست — را پر کنید. هرچه stack trace کامل‌تر باشد، تشخیص دقیق‌تر خواهد بود. نیازی به ویرایش یا پاک‌سازی نیست؛ به‌همان‌شکل خام paste کنید.

بخش کانتکست اختیاری است اما ارزش پر کردن دارد. «چه کاری می‌خواستم انجام دهم» به مدل کمک می‌کند نیّت شما را بفهمد. «چه کارهایی را قبلاً امتحان کرده‌ام» مانع پیشنهاد راه‌حل‌هایی می‌شود که قبلاً رد کرده‌اید.

چه چیزی دریافت می‌کنید

ساختار پاسخ چهاربخشی طوری طراحی شده که از دو مشکل رایج کمک‌های دیباگ هوش مصنوعی جلوگیری کند:

  • رفع کورکورانه — کد اصلاح‌شده به شما داده می‌شود بدون اینکه توضیح دهد چرا نسخه اصلی اشتباه بوده. شما آن را اعمال می‌کنید، کار می‌کند، اما علت را نمی‌فهمید و هفته بعد در فایلی دیگر با همان الگو مواجه می‌شوید.
  • تشخیص مبهم — «به نظر می‌رسد یک مشکل null reference وجود دارد». بدون جزئیات، بدون رفع، بدون مسیر پیشرو.

خروجی ساختاریافته به ناچار باید دقیق باشد: اول root cause (واقعاً چه چیزی خراب است)، بعد فیکس با inline comment (نه فقط یک کد کپی‌شده)، بعد مکانیزم (چرای پشت چرا)، و نهایتاً پیشگیری (قاعده‌ای که می‌توانید درونی کنید).

کار می‌کند برای همه زبان‌ها

این پرامپت به زبان خاصی وابسته نیست. با موارد زیر به خوبی کار می‌کند:

  • Python — عالی برای traceback، خطاهای import، type error، مشکلات async/await
  • JavaScript / TypeScript — خطاهای Node.js، استثناهای کنسول مرورگر، خطاهای کامپایلر TypeScript
  • Go — runtime panic، stack trace گوروتین، خطاهای interface assertion
  • Java / Kotlin — زنجیره NullPointerException، stack trace JVM، خطاهای Spring context
  • Rust — پیام‌های خطای کامپایلر (که خودشان جزئی هستند اما همچنان از توضیح بهره می‌برند)
  • SQL — خطاهای parse query، violation constraint، deadlock trace از PostgreSQL/MySQL

برای زبان‌های کامپایلری که stack trace چندان مفید نیست، خروجی کامل کامپایلر را همراه با خطا paste کنید.

مثال ورودی و خروجی

ورودی (ساده‌شده):

Error message: TypeError: Cannot read properties of undefined (reading 'map')

Stack trace:
  at ProductList (ProductList.jsx:14:22)
  at renderWithHooks (react-dom.development.js:14985:18)

Relevant code:
function ProductList({ products }) {
  return (
    <ul>
      {products.map(p => <li key={p.id}>{p.name}</li>)}
    </ul>
  );
}

Context: React 18, Node 22. Trying to render a list fetched from an API.

نمونه یک پاسخ خوب:

  • Root cause: products در اولین رندر کامپوننت، قبل از رسیدن پاسخ API، undefined است. نمی‌توان روی undefined متد .map() اجرا کرد.
  • فیکس: یک مقدار پیش‌فرض اضافه کنید — function ProductList({ products = [] }) — یا قبل از map یک null guard بگذارید.
  • چرا این اتفاق افتاد: React قبل از اینکه داده‌های async resolve شوند، به‌صورت همزمان رندر می‌کند. کامپوننت با همان مقدار اولیه‌ای که parent پاس می‌دهد رندر می‌شود؛ اگر parent هنوز state اولیه را تنظیم نکرده باشد، آن مقدار undefined خواهد بود.
  • پیشگیری: همیشه propهای لیست را با یک آرایه خالی پیش‌فرض مقداردهی کنید و حالت‌های loading/empty را به‌صریح در کامپوننت مدیریت کنید.

نکاتی برای نتایج بهتر

  • کل stack trace را paste کنید، نه فقط خط اول. فریم‌های پایین‌تر اغلب نشان می‌دهند که واقعاً چه چیزی باعث خطا شده است.
  • کد اطراف محل خطا را هم بیاورید، نه فقط همان خط. چند خط بالا و پایین context اهمیت دارد.
  • اگر خطا intermittent است، حتماً بگویید — مدل race condition و مسائل timing را در نظر می‌گیرد.
  • برای خطاهای TypeScript، اگر خطا مربوط به strictness یا module resolution است، تنظیمات مربوطه از tsconfig.json را هم اضافه کنید.
developer toolsai-promptsdebuggingcodingstack-trace
اشتراک‌گذاری: