debugging-and-error-recovery
テストが失敗したり、予期せぬエラーが発生したりした場合に、原因を推測するのではなく、体系的なアプローチで根本原因を特定し、修正することで問題を解決するSkill。
📜 元の英語説明(参考)
Use when tests fail, builds break, behavior doesn't match expectations, or you encounter any unexpected error. Use when you need a systematic approach to finding and fixing the root cause rather than guessing.
🇯🇵 日本人クリエイター向け解説
テストが失敗したり、予期せぬエラーが発生したりした場合に、原因を推測するのではなく、体系的なアプローチで根本原因を特定し、修正することで問題を解決するSkill。
※ jpskill.com 編集部が日本のビジネス現場向けに補足した解説です。Skill本体の挙動とは独立した参考情報です。
下記のコマンドをコピーしてターミナル(Mac/Linux)または PowerShell(Windows)に貼り付けてください。 ダウンロード → 解凍 → 配置まで全自動。
mkdir -p ~/.claude/skills && cd ~/.claude/skills && curl -L -o debugging-and-error-recovery.zip https://jpskill.com/download/9577.zip && unzip -o debugging-and-error-recovery.zip && rm debugging-and-error-recovery.zip
$d = "$env:USERPROFILE\.claude\skills"; ni -Force -ItemType Directory $d | Out-Null; iwr https://jpskill.com/download/9577.zip -OutFile "$d\debugging-and-error-recovery.zip"; Expand-Archive "$d\debugging-and-error-recovery.zip" -DestinationPath $d -Force; ri "$d\debugging-and-error-recovery.zip"
完了後、Claude Code を再起動 → 普通に「動画プロンプト作って」のように話しかけるだけで自動発動します。
💾 手動でダウンロードしたい(コマンドが難しい人向け)
- 1. 下の青いボタンを押して
debugging-and-error-recovery.zipをダウンロード - 2. ZIPファイルをダブルクリックで解凍 →
debugging-and-error-recoveryフォルダができる - 3. そのフォルダを
C:\Users\あなたの名前\.claude\skills\(Win)または~/.claude/skills/(Mac)へ移動 - 4. Claude Code を再起動
⚠️ ダウンロード・利用は自己責任でお願いします。当サイトは内容・動作・安全性について責任を負いません。
🎯 このSkillでできること
下記の説明文を読むと、このSkillがあなたに何をしてくれるかが分かります。Claudeにこの分野の依頼をすると、自動で発動します。
📦 インストール方法 (3ステップ)
- 1. 上の「ダウンロード」ボタンを押して .skill ファイルを取得
- 2. ファイル名の拡張子を .skill から .zip に変えて展開(macは自動展開可)
- 3. 展開してできたフォルダを、ホームフォルダの
.claude/skills/に置く- · macOS / Linux:
~/.claude/skills/ - · Windows:
%USERPROFILE%\.claude\skills\
- · macOS / Linux:
Claude Code を再起動すれば完了。「このSkillを使って…」と話しかけなくても、関連する依頼で自動的に呼び出されます。
詳しい使い方ガイドを見る →- 最終更新
- 2026-05-18
- 取得日時
- 2026-05-18
- 同梱ファイル
- 1
📖 Skill本文(日本語訳)
※ 原文(英語/中国語)を Gemini で日本語化したものです。Claude 自身は原文を読みます。誤訳がある場合は原文をご確認ください。
デバッグとエラー回復
概要
体系的なトリアージによる系統的なデバッグ。何かが壊れた場合、機能追加を停止し、証拠を保全し、根本原因を特定して修正するための構造化されたプロセスに従います。推測は時間の無駄です。トリアージチェックリストは、テストの失敗、ビルドエラー、ランタイムバグ、および本番環境でのインシデントに有効です。
使用するタイミング
- コード変更後にテストが失敗する
- ビルドが壊れる
- ランタイムの動作が期待どおりにならない
- バグレポートが届く
- ログまたはコンソールにエラーが表示される
- 以前は動作していたものが動作しなくなる
ライン停止ルール
予期しない事態が発生した場合:
1. 機能の追加または変更をSTOP(停止)する
2. 証拠(エラー出力、ログ、再現手順)をPRESERVE(保全)する
3. トリアージチェックリストを使用してDIAGNOSE(診断)する
4. 根本原因をFIX(修正)する
5. 再発をGUARD(防止)する
6. 検証に合格した場合のみRESUME(再開)する
失敗するテストや壊れたビルドを無視して、次の機能の開発に進まないでください。 エラーは複合化します。ステップ3のバグが修正されないまま放置されると、ステップ4〜10が間違ったものになります。
トリアージチェックリスト
以下の手順を順番に進めてください。手順をスキップしないでください。
ステップ1:再現
確実に失敗を再現します。再現できない場合は、自信を持って修正することはできません。
失敗を再現できますか?
├── YES → ステップ2に進む
└── NO
├── より多くのコンテキスト(ログ、環境の詳細)を収集する
├── 最小限の環境で再現を試みる
└── 本当に再現できない場合は、条件を文書化して監視する
テストの失敗の場合:
# 特定の失敗するテストを実行する
npm test -- --grep "test name"
# 詳細な出力で実行する
npm test -- --verbose
# 分離して実行する(テスト汚染を排除する)
npm test -- --testPathPattern="specific-file" --runInBand
ステップ2:局所化
失敗が発生する場所を絞り込みます。
どのレイヤーが失敗していますか?
├── UI/Frontend → コンソール、DOM、ネットワークタブを確認する
├── API/Backend → サーバーログ、リクエスト/レスポンスを確認する
├── Database → クエリ、スキーマ、データ整合性を確認する
├── Build tooling → 構成、依存関係、環境を確認する
├── External service → 接続、APIの変更、レート制限を確認する
└── Test itself → テストが正しいか確認する(偽陰性)
回帰バグには二分探索を使用します。
# バグが導入されたコミットを見つける
git bisect start
git bisect bad # 現在のコミットは壊れている
git bisect good <known-good-sha> # このコミットは動作していた
# Gitは中間点のコミットをチェックアウトします。各コミットでテストを実行します。
git bisect run npm test -- --grep "failing test"
ステップ3:削減
最小限の失敗するケースを作成します。
- バグだけが残るまで、関係のないコード/構成を削除します
- 失敗をトリガーする最小の例に、入力を簡略化します
- 問題を再現する最小限のテストに、テストを絞り込みます
最小限の再現により、根本原因が明らかになり、原因の代わりに症状を修正することを防ぎます。
ステップ4:根本原因の修正
症状ではなく、根本的な問題を修正します。
症状:「ユーザーリストに重複したエントリが表示される」
症状の修正(悪い例):
→ UIコンポーネントで重複排除:[...new Set(users)]
根本原因の修正(良い例):
→ APIエンドポイントに重複を生成するJOINがある
→ クエリを修正するか、DISTINCTを追加するか、データモデルを修正する
「なぜこれが起こるのか?」を、それが現れる場所だけでなく、実際の原因にたどり着くまで問い続けてください。
ステップ5:再発防止
この特定の失敗をキャッチするテストを作成します。
// バグ:特殊文字を含むタスクタイトルが検索を中断した
it('finds tasks with special characters in title', async () => {
await createTask({ title: 'Fix "quotes" & <brackets>' });
const results = await searchTasks('quotes');
expect(results).toHaveLength(1);
expect(results[0].title).toBe('Fix "quotes" & <brackets>');
});
このテストは、同じバグの再発を防ぎます。修正なしで失敗し、修正ありで合格する必要があります。
ステップ6:エンドツーエンドの検証
修正後、完全なシナリオを検証します。
# 特定のテストを実行する
npm test -- --grep "specific test"
# フルテストスイートを実行する(回帰をチェックする)
npm test
# 該当する場合は手動でスポットチェックする
npm run dev # ブラウザで検証する
エラー固有のパターン
テスト失敗のトリアージ
コード変更後にテストが失敗する:
├── テスト対象のコードを変更しましたか?
│ └── YES → テストまたはコードが間違っているか確認する
│ ├── テストが古くなっている → テストを更新する
│ └── コードにバグがある → コードを修正する
├── 関係のないコードを変更しましたか?
│ └── YES → おそらく副作用 → 共有状態、インポート、グローバルを確認する
└── テストはすでに不安定でしたか?
└── タイミングの問題、順序依存性、外部依存関係を確認する
ビルド失敗のトリアージ
ビルドが失敗する:
├── Type error → エラーを読み、引用された場所の型を確認する
├── Import error → モジュールが存在するか、エクスポートが一致するか、パスが正しいかを確認する
├── Config error → 構文/スキーマの問題についてビルド構成ファイルを確認する
├── Dependency error → package.jsonを確認し、npm installを実行する
└── Environment error → Nodeバージョン、OSの互換性を確認する
ランタイムエラーのトリアージ
ランタイムエラー:
├── TypeError: Cannot read property 'x' of undefined
│ └── 何かがnull/undefinedであるはずがない
│ → データフローを確認する:この値はどこから来るのか?
├── Network error / CORS
│ └── URL、ヘッダー、サーバーのCORS構成を確認する
├── Render error / White screen
│ └── エラー境界、コンソール、コンポーネントツリーを確認する
└── Unexpected behavior (no error)
└── 主要なポイントでロギングを追加し、各ステップでデータを確認する
安全なフォールバックパターン
時間的制約がある場合は、安全なフォールバックを使用します。
// 安全なデフォルト+警告(クラッシュする代わりに)
function getConfig(key: string): string {
const value = process.env[key];
if (!value) {
console.warn(`Missing config: ${key}, using default`);
return DEFAULTS[key] ?? '';
}
return value;
}
// グレースフルデグラデーション(壊れた機能の代わりに)
function renderChart(data: ChartData[]) {
if (data.length === 0) {
(原文がここで切り詰められています) 📜 原文 SKILL.md(Claudeが読む英語/中国語)を展開
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
Never 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-10 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
For test failures:
# 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"
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
Write a test that catches this specific failure:
// The bug: task titles with special characters broke the search
it('finds tasks with special characters in title', async () => {
await createTask({ title: 'Fix "quotes" & <brackets>' });
const results = await searchTasks('quotes');
expect(results).toHaveLength(1);
expect(results[0].title).toBe('Fix "quotes" & <brackets>');
});
This test will prevent the same bug from recurring. It should fail without the fix and pass with it.
Step 6: Verify End-to-End
After fixing, verify the complete scenario:
# Run the specific test
npm test -- --grep "specific test"
# Run the full test suite (check for regressions)
npm test
# Build the project (check for type/compilation errors)
npm run build
# Manual spot check if applicable
npm run dev # Verify in browser
Error-Specific Patterns
Test Failure Triage
Test fails after code change:
├── Did you change code the test covers?
│ └── YES → Check if the test or the code is wrong
│ ├── Test is outdated → Update the test
│ └── Code has a bug → Fix the code
├── Did you change unrelated code?
│ └── YES → Likely a side effect → Check shared state, imports, globals
└── Test was already flaky?
└── Check for timing issues, order dependence, external dependencies
Build Failure Triage
Build fails:
├── Type error → Read the error, check the types at the cited location
├── Import error → Check the module exists, exports match, paths are correct
├── Config error → Check build config files for syntax/schema issues
├── Dependency error → Check package.json, run npm install
└── Environment error → Check Node version, OS compatibility
Runtime Error Triage
Runtime error:
├── TypeError: Cannot read property 'x' of undefined
│ └── Something is null/undefined that shouldn't be
│ → Check data flow: where does this value come from?
├── Network error / CORS
│ └── Check URLs, headers, server CORS config
├── Render error / White screen
│ └── Check error boundary, console, component tree
└── Unexpected behavior (no error)
└── Add logging at key points, verify data at each step
Safe Fallback Patterns
When under time pressure, use safe fallbacks:
// Safe default + warning (instead of crashing)
function getConfig(key: string): string {
const value = process.env[key];
if (!value) {
console.warn(`Missing config: ${key}, using default`);
return DEFAULTS[key] ?? '';
}
return value;
}
// Graceful degradation (instead of broken feature)
function renderChart(data: ChartData[]) {
if (data.length === 0) {
return <EmptyState message="No data available for this period" />;
}
try {
return <Chart data={data} />;
} catch (error) {
console.error('Chart render failed:', error);
return <ErrorState message="Unable to display chart" />;
}
}
Instrumentation Guidelines
Add logging only when it helps. Remove it when done.
When to add instrumentation:
- You can't localize the failure to a specific line
- The issue is intermittent and needs monitoring
- The fix involves multiple interacting components
When to remove it:
- The bug is fixed and tests guard against recurrence
- The log is only useful during development (not in production)
- It contains sensitive data (always remove these)
Permanent instrumentation (keep):
- Error boundaries with error reporting
- API error logging with request context
- Performance metrics at key user flows
Common Rationalizations
| Rationalization | Reality |
|---|---|
| "I know what the bug is, I'll just fix it" | You might be right 70% of the time. The other 30% costs hours. Reproduce first. |
| "The failing test is probably wrong" | Verify that assumption. If the test is wrong, fix the test. Don't just skip it. |
| "It works on my machine" | Environments differ. Check CI, check config, check dependencies. |
| "I'll fix it in the next commit" | Fix it now. The next commit will introduce new bugs on top of this one. |
| "This is a flaky test, ignore it" | Flaky tests mask real bugs. Fix the flakiness or understand why it's intermittent. |
Red Flags
- Skipping a failing test to work on new features
- Guessing at fixes without reproducing the bug
- Fixing symptoms instead of root causes
- "It works now" without understanding what changed
- No regression test added after a bug fix
- Multiple unrelated changes made while debugging (contaminating the fix)
Verification
After fixing a bug:
- [ ] Root cause is identified and documented
- [ ] Fix addresses the root cause, not just symptoms
- [ ] A regression test exists that fails without the fix
- [ ] All existing tests pass
- [ ] Build succeeds
- [ ] The original bug scenario is verified end-to-end