エラーを効果的にAIへ貼り付ける
バグ修正に必要な情報をAIに伝えます。
「エラーを効果的にAIへ貼り付ける」はCoddyKit上の無料Vibe Codingレッスンです。 これはレッスン2/4です。 下記で完全なレッスンを無料で読むことができます。その後、ブラウザ内の組み込みコードエディタと24時間対応のAIチューターでハンズオン演習できます。 これはVibe Coding学習パスの一部であり、ウェブとCoddyKitアプリ全体で進捗が同期されます。 Vibe Codingコースには全4レッスンが含まれています。
このレッスンの一部はまだ翻訳されておらず、英語で表示されています。
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.
よくある質問
「エラーを効果的にAIへ貼り付ける」レッスンは無料ですか?
はい。「エラーを効果的にAIへ貼り付ける」の完全なテキストはこのウェブで無料で読めます。インタラクティブに演習し(組み込みコードエディタと24時間対応のAIチューター)、Vibe Codingコースの残りをアンロックするには、CoddyKit PROにアップグレードしてください。 Vibe Codingコースには全4レッスンが含まれています。
「エラーを効果的にAIへ貼り付ける」で何を学びますか?
バグ修正に必要な情報をAIに伝えます。 ブラウザで直接実行するハンズオンコードでVibe Codingを演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。
Vibe Codingを始めるのに経験は必要ですか?
事前経験は必要ありません。CoddyKitのVibe Codingは初級者から上級者向けに構成されているため、ここから始めるか最初から始めて、自分のペースで進むことができます。 これはレッスン2/4です。
「エラーを効果的にAIへ貼り付ける」レッスンにはどのくらい時間がかかりますか?
ほとんどのCoddyKitレッスンは約5~10分かかります。各レッスンはコンパクトでインタラクティブなので、着実に進歩し、ウェブとアプリ全体で正確に前回の場所から再開できます。
このVibe Codingレッスンでコードを書いて実行できますか?
はい。すべてのVibe Codingレッスンに組み込みコードエディタが含まれているため、ブラウザでリアルコードを書いて実行し、即座のAIフィードバックを取得できます。ローカル設定は不要です。
このコースのすべてのレッスン
- エラーメッセージを理解する
- エラーを効果的にAIへ貼り付ける
- バグの原因を絞り込む
- AIが行き詰まったとき