Menempelkan Error ke Kecerdasan Buatan secara Efektif
Berikan hal-hal yang diperlukan kecerdasan buatan untuk memperbaiki bug.
Menempelkan Error ke Kecerdasan Buatan secara Efektif adalah pelajaran Vibe Coding gratis di CoddyKit. Ini adalah pelajaran 2 dari 4. Kamu bisa membaca pelajaran lengkapnya di bawah secara gratis — lalu praktikkan langsung di browser dengan editor kode bawaan dan tutor AI 24/7. Ini adalah bagian dari jalur belajar Vibe Coding, dan progresmu tersinkronisasi di web dan aplikasi CoddyKit. Kursus Vibe Coding mencakup 4 pelajaran total.
Bagian dari pelajaran ini belum diterjemahkan dan ditampilkan dalam bahasa Inggris.
Garbage In, Garbage Out
You found an error. Now you want AI to fix it. But here's the thing: AI is only as good as the context you give it.
Paste 'it's broken pls fix' and you'll get a guess. Paste the right details and tools like Cursor, Claude Code, or Copilot can nail the fix instantly.
This lesson teaches you exactly what the AI needs to fix a bug — and how to hand it over cleanly.
The Four Things AI Needs
For a great fix, give the AI these four ingredients:
- The full error message — including the stack trace
- The relevant code — the function or file the error points to
- What you expected to happen
- What actually happened
Miss any of these and the AI has to guess. Include them and it reasons like a senior engineer looking over your shoulder.
A Bad Prompt vs A Good Prompt
Compare these two. The first wastes everyone's time. The second gets a precise fix.
Notice the second one gives the error, the code, the expectation, and the reality — all four ingredients.
BAD:
"my app crashes fix it"
GOOD:
"I'm getting this error when I click Save:
TypeError: Cannot read properties of undefined (reading 'id')
at saveUser (api.js:22:14)
Here's the saveUser function:
[paste the function]
Expected: the user gets saved.
Actual: it crashes on click. What's wrong and how do I fix it?"Always Include the Full Error
Beginners often paste only the first line of an error. But the stack trace below it tells the AI which functions were involved and in what order.
Copy the whole red block — from the error type down through the at ... lines. In the browser console, right-click the error and choose 'Copy'. In a terminal, select and copy the full output.
More signal = better fix. The AI can ignore what it doesn't need.
Paste the Right Code, Not Everything
You don't need to dump your entire project. Give the AI the function the error points to, plus anything it directly touches.
If the error is in saveUser on line 22, paste saveUser. If saveUser uses a variable created in another function, paste that too.
In Cursor or Claude Code, you often don't even paste — you just @mention the file and the AI reads it. But knowing which file to point at is the skill.
Describe Expected vs Actual
This is the ingredient beginners skip most — and it's the most powerful. The AI can read your code, but it can't read your intentions.
Spell out both sides clearly:
"When I submit the form, I EXPECT the new task to
appear in the list below.
What ACTUALLY happens: the page goes blank and the
console shows the error below."
// This one sentence often points AI straight to the bug.A Reusable Debug Prompt Template
Save this template. Fill in the blanks every time you hit a bug. It guarantees you include all four ingredients.
I'm building [what your app does].
When I [action that triggers it], I get this error:
[paste full error + stack trace]
Here's the relevant code:
[paste function / file]
Expected: [what should happen]
Actual: [what happens instead]
What's the cause, and what's the smallest fix?Ask for the Cause, Not Just the Patch
A subtle upgrade: end your prompt by asking the AI to explain the cause, not only hand you new code.
If you only ask 'fix it', you might get code you don't understand — and the next bug stumps you again. Asking 'why did this happen?' teaches you as you go, and helps you catch when the AI's reasoning is off.
"Before you give me the fix, explain in one or two
sentences WHY this error happens. Then show the
smallest change that fixes it."Reproduce It Yourself First
The strongest thing you can hand the AI is exact steps to reproduce. If you can say 'click Save with an empty name field → crash', the AI knows precisely what path the code took.
Try this snippet: it reproduces a real bug. Run it, copy the error it prints, and imagine pasting that plus the code into your AI tool.
function saveUser(user) {
return "Saved user #" + user.id;
}
try {
saveUser(undefined); // reproduce: no user passed
} catch (err) {
console.log(err.name + ": " + err.message);
}Watch Out for Secrets
One safety rule before you paste: never include API keys, passwords, or tokens in code you send to AI or share publicly.
If your error or code shows something like API_KEY="sk-abc123...", replace it with API_KEY="REDACTED" before pasting. The AI doesn't need the real secret to fix your logic.
Most tools are safe, but this is a good lifelong habit for any builder.
Put It All Together
Here's a fully filled-in example using the template — error, code, expected, actual, and a request for the cause. This is what a 'perfect' debug prompt looks like in practice.
Internalize this shape and AI tools will feel like they read your mind.
I'm building a to-do app.
When I click 'Add', I get:
TypeError: Cannot read properties of null (reading 'value')
at addTask (app.js:9:30)
Code:
function addTask() {
const text = document.getElementById('taskInput').value;
list.push(text);
}
Expected: the typed task is added to the list.
Actual: nothing adds, console throws the error above.
Why does this happen, and what's the smallest fix?Quick Check
Which prompt will get you the best, most accurate fix from an AI tool?
Recap: Hand AI the Right Context
You now know how to turn a vague 'it's broken' into a precise request. Remember to include:
- The full error and stack trace
- The relevant code (the function it points to)
- Expected vs actual behavior
- A request to explain the cause, and redact any secrets
Use the reusable template every time. Next lesson: when the error alone isn't enough, you'll learn to narrow down a bug with AI's help.
Pertanyaan yang Sering Diajukan
Apakah pelajaran “Menempelkan Error ke Kecerdasan Buatan secara Efektif” gratis?
Ya — teks lengkap “Menempelkan Error ke Kecerdasan Buatan secara Efektif” gratis dibaca di sini di web. Untuk praktiknya secara interaktif (editor kode bawaan dan tutor AI 24/7) dan buka sisa kursus Vibe Coding, upgrade ke CoddyKit PRO. Kursus Vibe Coding mencakup 4 pelajaran total.
Apa yang akan aku pelajari di “Menempelkan Error ke Kecerdasan Buatan secara Efektif”?
Berikan hal-hal yang diperlukan kecerdasan buatan untuk memperbaiki bug. Kamu berlatih Vibe Coding dengan kode praktik yang langsung kamu jalankan di browser, dan tutor AI 24/7 menjawab pertanyaanmu saat kamu mengerjakan pelajaran ini.
Apakah aku perlu pengalaman untuk memulai Vibe Coding?
Tidak diperlukan pengalaman sebelumnya. Vibe Coding di CoddyKit dirancang untuk pemula hingga pelajar tingkat lanjut, jadi kamu bisa memulai di sini atau dari awal dan belajar sesuai kecepatan kamu sendiri. Ini adalah pelajaran 2 dari 4.
Berapa lama pelajaran “Menempelkan Error ke Kecerdasan Buatan secara Efektif” memakan waktu?
Sebagian besar pelajaran CoddyKit memakan waktu sekitar 5–10 menit. Setiap pelajaran ringkas dan interaktif, jadi kamu membuat kemajuan stabil dan melanjutkan dari tempat kamu tinggalkan di web dan aplikasi.
Bisakah aku menulis dan menjalankan kode dalam pelajaran Vibe Coding ini?
Ya. Setiap pelajaran Vibe Coding menyertakan editor kode bawaan, jadi kamu menulis dan menjalankan kode nyata langsung di browser dan mendapatkan umpan balik AI instan — tidak diperlukan penyiapan lokal.
Semua pelajaran dalam kursus ini
- Memahami Pesan Error
- Menempelkan Error ke Kecerdasan Buatan secara Efektif
- Mempersempit Sumber Bug
- Saat Kecerdasan Buatan Mengalami Kebuntuan