Marketplace

Debugging and Troubleshooting

Systematic error diagnosis and debugging workflow for Rust code. Use when code isn't working, tests fail, or runtime errors occur.

allowed_tools: Bash, Read, Grep, Glob

$ Installer

git clone https://github.com/ShunsukeHayashi/Miyabi /tmp/Miyabi && cp -r /tmp/Miyabi/packages/mcp-bundle/claude-plugins/miyabi-full/skills/debugging-troubleshooting ~/.claude/skills/Miyabi

// tip: Run this command in your terminal to install the skill


name: Debugging and Troubleshooting description: Systematic error diagnosis and debugging workflow for Rust code. Use when code isn't working, tests fail, or runtime errors occur. allowed-tools: Bash, Read, Grep, Glob

🐛 Debugging and Troubleshooting

Version: 2.0.0 Last Updated: 2025-11-22 Priority: ⭐⭐⭐⭐ (P1 Level) Purpose: 体系的なエラー診断とRustデバッグワークフロー


📋 概要

コンパイルエラー、テスト失敗、ランタイムエラーに対する 体系的な診断と解決ワークフローを提供します。


🎯 P0: 呼び出しトリガー

トリガー
動作不良"this code isn't working"
テスト失敗"why is this test failing?"
エラー解析"debug this error"
コンパイルエラー"compilation error"
ランタイムエラー"runtime panic"

🔧 P1: エラー分類と対処

エラー分類表

分類症状診断コマンド優先度
コンパイルエラーerror[E####]cargo check
テスト失敗test ... FAILEDcargo test -- --nocapture
ランタイムpanicthread 'main' panickedRUST_BACKTRACE=1
ロジックエラー期待と異なる出力dbg!(), ログ
パフォーマンス遅い・メモリ大cargo bench, valgrind
統合エラー外部サービス失敗ネットワーク診断

🚀 P2: デバッグパターン

Pattern 1: コンパイルエラー

# Step 1: エラー確認
cargo check 2>&1 | head -50

# Step 2: エラーコード解析
# error[E0277] → Trait未実装
# error[E0412] → 型未定義
# error[E0433] → モジュール未解決

# Step 3: 詳細情報
rustc --explain E0277

よくあるエラーと解決:

エラーコード原因解決策
E0277Trait未実装#[derive(...)] または手動実装
E0412型が見つからないuse文追加
E0433モジュール解決失敗パス確認、mod宣言
E0502借用競合借用スコープ見直し
E0382所有権移動後使用clone() または参照

Pattern 2: テスト失敗

# Step 1: 失敗テスト特定
cargo test 2>&1 | grep FAILED

# Step 2: 詳細出力で実行
cargo test test_name -- --nocapture

# Step 3: 順次実行(並列問題回避)
cargo test -- --test-threads=1

# Step 4: アサーション詳細
# pretty_assertions, insta使用推奨

Pattern 3: ランタイムpanic

# Step 1: バックトレース取得
RUST_BACKTRACE=1 cargo run

# Step 2: 完全バックトレース
RUST_BACKTRACE=full cargo run

# Step 3: panic箇所特定
# at src/lib.rs:42:5 を確認

# Step 4: デバッガ使用
rust-lldb target/debug/miyabi

Pattern 4: ロジックエラー

// dbg!マクロ使用
let result = dbg!(compute_value());

// tracing使用
tracing::debug!(?value, "computed value");

// 条件付きログ
if cfg!(debug_assertions) {
    println!("Debug: {:?}", state);
}

⚡ P3: 高度なデバッグツール

デバッグツール一覧

ツール用途コマンド
rust-lldbデバッガrust-lldb target/debug/miyabi
cargo-expandマクロ展開cargo expand
cargo-asmアセンブリ確認cargo asm
valgrindメモリ診断valgrind ./target/debug/miyabi
miriUB検出cargo +nightly miri test

VS Codeデバッグ設定

{
  "type": "lldb",
  "request": "launch",
  "name": "Debug Miyabi",
  "cargo": {
    "args": ["build", "--bin=miyabi"]
  },
  "args": [],
  "cwd": "${workspaceFolder}"
}

🛡️ 共通パニック対処

パニック原因対処
unwrap() on NoneOption未処理if let Some / ?
unwrap() on ErrResult未処理match / ?
index out of bounds配列範囲外.get() / bounds check
overflow算術オーバーフローchecked_* / wrapping_*
stack overflow無限再帰再帰ロジック見直し

✅ 成功基準

チェック項目基準
エラー分類正確な分類
根本原因特定原因明確化
解決策提示具体的な修正方法
再発防止テスト追加

🔗 関連Skills

  • Rust Development: ビルド・テスト
  • Performance Analysis: パフォーマンス問題
  • Security Audit: セキュリティ問題

Repository

ShunsukeHayashi
ShunsukeHayashi
Author
ShunsukeHayashi/Miyabi/packages/mcp-bundle/claude-plugins/miyabi-full/skills/debugging-troubleshooting
11
Stars
6
Forks
Updated5d ago
Added1w ago