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: ألصق أي خطأ واحصل على السبب الجذري والحل في ثوانٍ

مشاركة:
أداة فك تتبع Stack Trace: ألصق أي خطأ واحصل على السبب الجذري والحل في ثوانٍ

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

أواجه خطأً أثناء التصحيح. أرجو مساعدتي في فهم سبب المشكلة وكيفية إصلاحها.

**رسالة الخطأ:**
[الصق رسالة الخطأ هنا]

**تتبع المكدس (Stack Trace):**
[الصق التتبع الكامل للمكدس هنا]

**الكود ذو الصلة (الدالة أو الملف الذي يظهر فيه الخطأ):**
```
[الصق الكود هنا]
```

**السياق:**
- اللغة/بيئة التشغيل: [مثل Python 3.11, Node.js 22, Go 1.22]
- ما كنت أحاول فعله عند حدوث الخطأ: [جملة واحدة]
- ما جربته بالفعل: [أو "لم أجرب شيئًا بعد"]

المرجو تقديم:
1. **السبب الجذري** — شرح بلغة واضحة لما حدث بالفعل ولماذا
2. **الإصلاح** — عرض الكود المُصحَّح مع تعليقات داخلية تشرح التغيير
3. **لماذا حدث ذلك** — الآلية الكامنة أو المفهوم الخاطئ الذي تسبب في الخلل، حتى أفهمه بدلاً من مجرد نسخ الإصلاح
4. **الوقاية** — جملة واحدة عن كيفية تجنب هذا النوع من الأخطاء في المستقبل

كيفية الاستخدام

انسخ القالب أعلاه. املأ الأقسام الأربعة — رسالة الخطأ، تتبع المكدس، الكود، والسياق. كلما كان تتبع المكدس أكثر اكتمالاً، كان التشخيص أفضل. لست بحاجة إلى تحريره أو تنظيفه؛ الصقه كما هو.

قسم السياق اختياري لكن من المفيد ملؤه. "ما كنت أحاول فعله" يساعد النموذج على فهم القصد. "ما جربته بالفعل" يمنعه من اقتراح أشياء استبعدتها سابقاً.

ما ستحصل عليه

هيكل الرد رباعي الأجزاء صُمِّم خصيصاً لتجنب نمطي الفشل الأكثر شيوعاً في مساعدة تصحيح الأخطاء بالذكاء الاصطناعي:

  • الإصلاح الأعمى — تقديم كود مُصحَّح دون شرح لماذا كان الأصلي خاطئاً. تطبقه، فيعمل، لكنك لا تفهمه ثم تصادف نفس النمط في ملف آخر الأسبوع التالي.
  • التشخيص المبهم — "يبدو أن هناك مشكلة مرجع فارغ." لا تفاصيل، لا إصلاح، لا مسار للمضي قدماً.

المخرجات المنظَّمة تفرض التحديد: السبب الجذري أولاً (ما هو المكسور فعلاً)، ثم الإصلاح مع تعليقات داخلية (ليس مجرد تفريغ كود)، ثم الآلية (لماذا وراء اللماذا)، ثم الوقاية (قاعدة يمكنك استيعابها).

يعمل عبر اللغات

هذا الـ Prompt غير مرتبط بلغة محددة. يعمل جيداً مع:

  • Python — ممتاز لتتبع الأخطاء، أخطاء الاستيراد، أخطاء النوع، مشكلات async/await
  • JavaScript / TypeScript — يعالج أخطاء Node.js، استثناءات وحدة التحكم في المتصفح، أخطاء مترجم TypeScript
  • Go — حالات panic أثناء التشغيل، تتبع مكدس الـ goroutine، فشل تأكيد الـ interface
  • Java / Kotlin — سلاسل NullPointerException، تتبع مكدس JVM، أخطاء سياق Spring
  • Rust — رسائل أخطاء المترجم (والتي هي مفصلة أصلاً لكنها تستفيد من الشرح)
  • SQL — أخطاء تحليل الاستعلام، انتهاكات القيود، تتبع حالات deadlock من PostgreSQL/MySQL

بالنسبة للغات المُجمَّعة حيث يكون تتبع المكدس أقل إفادة، الصق مخرجات المترجم الكاملة مع الخطأ.

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

الإدخال (مبسَّط):

رسالة الخطأ: TypeError: Cannot read properties of undefined (reading 'map')

تتبع المكدس:
  at ProductList (ProductList.jsx:14:22)
  at renderWithHooks (react-dom.development.js:14985:18)

الكود ذو الصلة:
function ProductList({ products }) {
  return (
    <ul>
      {products.map(p => <li key={p.id}>{p.name}</li>)}
    </ul>
  );
}

السياق: React 18, Node 22. أحاول عرض قائمة تم جلبها من API.

ما يجب أن يبدو عليه الرد الجيد:

  • السبب الجذري: المتغير products يساوي undefined عند أول عرض للمكوِّن، قبل وصول استجابة الـ API. لا يمكن لـ .map() العمل على undefined.
  • الإصلاح: أضف قيمة افتراضية — function ProductList({ products = [] }) — أو أضف حارس null قبل عملية الـ map.
  • لماذا حدث ذلك: React يعرض بشكل متزامن قبل أن تتحلَّى عمليات جلب البيانات غير المتزامنة. يُعرض المكوِّن بالقيمة الأولية التي يمررها المكوِّن الأب، وهي undefined إذا لم يحدد الأب حالة أولية بعد.
  • الوقاية: قم دائماً بتهيئة خصائص القوائم بمصفوفة فارغة افتراضية وتعامل مع حالات التحميل/الفارغة بشكل صريح داخل المكوِّن.

نصائح للحصول على نتائج أفضل

  • الصق تتبع المكدس الكامل، ليس السطر العلوي فقط. الإطارات السفلية غالباً ما تكشف الاستدعاء الفعلي الذي تسبب في الخطأ.
  • ضمِّن الكود المحيط المباشر، وليس السطر الذي حدث فيه الخطأ فقط. بضعة أسطر من السياق فوق وتحت مهمة.
  • إذا كان الخطأ متقطعاً، فاذكر ذلك — سينظر النموذج في حالات السباق والتوقيت.
  • بالنسبة لأخطاء TypeScript، ضمِّن الإعدادات ذات الصلة من tsconfig.json إذا كان الخطأ يتعلق بالصرامة أو حل الوحدات.
developer toolsai-promptsdebuggingcodingstack-trace
مشاركة: