debugging-and-error-recovery
できること
このガイドは、コードのエラーを体系的に見つけて直す方法を案内します。推測するのではなく、いったん立ち止まり、原因を調べ、問題を解決することを教えます。
使う場面
- ✓変更後にテストが失敗したとき。
- ✓プログラムが期待どおりに動かないとき。
- ✓予期しないエラーに遭遇したとき。
スキルのリンク
https://github.com/addyosmani/agent-skills/blob/main/skills/debugging-and-error-recovery/SKILL.mdコピーしてAI(Claude、ChatGPT、Cursor)に貼り付け、指示に従うよう頼んでください。
使い方
いちばん簡単な方法:メッセージをコピーしてAIに貼り付けるだけ。AIがスキルを読んで指示に従います。
貼り付け用メッセージ
Claude Code、Codex、Cursorの場合:プロジェクトのフォルダで実行するとスキルがインストールされます。
SKILL.mdをダウンロードして、エージェントのスキル用フォルダに入れてください。
AIへの頼み方の例
“ユーザーを保存しようとすると変なエラーが出ます。原因を一緒に調べてもらえますか?”
毎週5つの新しいスキル。1分で読めます。
仕組み
まずエラーを再現し、どこで起きているかを特定します。次に問題を単純化し、最後に本当の原因を修正します。
技術的な内容(元のSKILL.md)
作者による元のテキスト(英語)をGitHubからそのまま表示しています。
Debugging and Error Recovery
Overview
Systematic debugging with structured triage. When something breaks, stop adding features, preserve evidence, and follow a structured process to find and fix the root cause. Guessing wastes time. The triage checklist works for test failures, build errors, runtime bugs, and production incidents.
When to Use
- Tests fail after a code change
- The build breaks
- Runtime behavior doesn't match expectations
- A bug report arrives
- An error appears in logs or console
- Something worked before and stopped working
The Stop-the-Line Rule
When anything unexpected happens:
1. STOP adding features or making changes
2. PRESERVE evidence (error output, logs, repro steps)
3. DIAGNOSE using the triage checklist
4. FIX the root cause
5. GUARD against recurrence
6. RESUME only after verification passes
Don't push past a failing test or broken build to work on the next feature. Errors compound. A bug in Step 3 that goes unfixed makes Steps 4-6 wrong.
The Triage Checklist
Work through these steps in order. Do not skip steps.
Step 1: Reproduce
Make the failure happen reliably. If you can't reproduce it, you can't fix it with confidence.
Can you reproduce the failure?
├── YES → Proceed to Step 2
└── NO
├── Gather more context (logs, environment details)
├── Try reproducing in a minimal environment
└── If truly non-reproducible, document conditions and monitor
When a bug is non-reproducible:
Cannot reproduce on demand:
├── Timing-dependent?
│ ├── Add timestamps to logs around the suspected area
│ ├── Try with artificial delays (setTimeout, sleep) to widen race windows
│ └── Run under load or concurrency to increase collision probability
├── Environment-dependent?
│ ├── Compare Node/browser versions, OS, environment variables
│ ├── Check for differences in data (empty vs populated database)
│ └── Try reproducing in CI where the environment is clean
├── State-dependent?
│ ├── Check for leaked state between tests or requests
│ ├── Look for global variables, singletons, or shared caches
│ └── Run the failing scenario in isolation vs after other operations
└── Truly random?
├── Add defensive logging at the suspected location
├── Set up an alert for the specific error signature
└── Document the conditions observed and revisit when it recurs
For test failures (npm shown — substitute the repository's own test command, per the test-driven-development skill's Discover the Stack First section):
# Run the specific failing test
npm test -- --grep "test name"
# Run with verbose output
npm test -- --verbose
# Run in isolation (rules out test pollution)
npm test -- --testPathPattern="specific-file" --runInBand
Step 2: Localize
Narrow down WHERE the failure happens:
Which layer is failing?
├── UI/Frontend → Check console, DOM, network tab
├── API/Backend → Check server logs, request/response
├── Database → Check queries, schema, data integrity
├── Build tooling → Check config, dependencies, environment
├── External service → Check connectivity, API changes, rate limits
└── Test itself → Check if the test is correct (false negative)
Use bisection for regression bugs:
# Find which commit introduced the bug
git bisect start
git bisect bad # Current commit is broken
git bisect good <known-good-sha> # This commit worked
# Git will checkout midpoint commits; run your test at each
git bisect run npm test -- --grep "failing test" # substitute the repository's focused-test command
Step 3: Reduce
Create the minimal failing case:
- Remove unrelated code/config until only the bug remains
- Simplify the input to the smallest example that triggers the failure
- Strip the test to the bare minimum that reproduces the issue
A minimal reproduction makes the root cause obvious and prevents fixing symptoms instead of causes.
Step 4: Fix the Root Cause
Fix the underlying issue, not the symptom:
Symptom: "The user list shows duplicate entries"
Symptom fix (bad):
→ Deduplicate in the UI component: [...new Set(users)]
Root cause fix (good):
→ The API endpoint has a JOIN that produces duplicates
→ Fix the query, add a DISTINCT, or fix the data model
Ask: "Why does this happen?" until you reach the actual cause, not just where it manifests.
Step 5: Guard Against Recurrence
…
よくある質問
「証拠を保存する」とはどういう意味ですか?
エラーメッセージ、ログ、エラーを起こすまでの操作手順など、エラーに関する重要な情報を残しておくことを意味します。
問題が起きたときに新機能を追加してはいけないのはなぜですか?
コードを追加すると問題が悪化したり、本当の原因が隠れたりして、修正がさらに難しくなるからです。
「二分探索(バイセクション)」とは何ですか?
古いバージョンのコードを順番に試して、正常に動いていたものを見つけ、どの変更が問題を起こしたのかを特定する手法です。
詳細
作者による元の説明
Guides systematic root-cause debugging. Use when tests fail, builds break, something that worked yesterday broke, behavior doesn't match expectations, or you encounter any unexpected error. Use when you need to figure out what broke and why — a systematic approach to finding and fixing the root cause rather than guessing.
repo: addyosmani/agent-skills
人気
- GitHubのスター
- 107k
- ランキング
- #768
- ライセンス
- MIT
- 更新日
- 2026/10/13
コメント
- …
このリポジトリの他のスキル
api-and-interface-design
107k明確に定義されたAPIやインターフェースの作成を支援します。ソフトウェアの異なる部分がどのように通信するかを設計する際に役立ちます。
browser-testing-with-devtools
107k実際のブラウザでコードを直接テストできるよう支援します。実際の利用環境での動作を確認し、エラーやパフォーマンスの問題を見つけるのに役立ちます。
ci-cd-and-automation
107kAIエージェントに、反復的な作業の自動化、プロジェクトのリリース、インフラの管理を教えます。
code-review-and-quality
107k複数の観点から詳細なコードレビューを行います。新しい変更をマージする前に、品質を確保し、将来の問題を防ぐのに役立ちます。
似ているスキル
test-driven-development
311k機能や修正を作る前に、まず失敗するテストを書き、それが失敗するのを確認してから、合格させる最小のコードを書くようエージェントに教えます。
verification-before-completion
311kタスク、修正、ビルドが完了した、または合格したと主張する前に、実際のチェックを実行し、その出力を読むようエージェントに教えます。
migrate-to-shoehorn
310kテストファイル内の危険な型キャストを、shoehornライブラリに置き換え、テストが部分的なデータを使いつつ型チェックを通るようにします。