Community生產力與協作github.com

addyosmani/debugging-and-error-recovery

引導系統性的根本原因除錯。在測試失敗、建置中斷、行為不符合預期或遇到任何意外錯誤時使用。當你需要系統性地找出並修復根本原因,而非盲目猜測時,請使用此技能。

debugging-and-error-recovery 是什麼?

「addyosmani/debugging-and-error-recovery」是一個專業的 AI 代理技能,專為開發者設計,用於系統性地診斷和修復軟體錯誤。它能引導使用者從問題發生時開始,透過建立最小重現步驟、使用二分搜尋法找出引入錯誤的變更、檢查核心假設、並隔離變數以快速鎖定根本原因。此技能支援所有主流開發環境,包括 Claude Code、Cline、Cursor 和 GitHub Copilot,可透過「@debugging」或「/debugging」快捷鍵直接叫用。當面對測試失敗、建置中斷、行為不符合預期或任何意外錯誤時,此技能能幫助你從猜測式除錯轉變為結構化、可重現的除錯流程,顯著提升除錯效率與準確性。它特別適合用於解決複雜的跨元件互動問題、效能回歸,以及難以重現的間歇性錯誤。

相容平台~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/addyosmani/agent-skills/tree/main/skills/debugging-and-error-recovery

Installed? Explore more 生產力與協作 skills: steipete/gemini, steipete/gh-issues, steipete/skill-creator · View all 6 →

在你喜歡的 AI 中提問

開啟一個已預先載入此 Agent Skill 的新對話。

說明文件

debugging-and-error-recovery 是做什麼的?

引導系統性的根本原因除錯。在測試失敗、建置中斷、行為不符合預期或遇到任何意外錯誤時使用。當你需要系統性地找出並修復根本原因,而非盲目猜測時,請使用此技能。

使用方式

一般來說,你不需要手動處理。當你要求代理執行開發任務,且測試失敗、建置中斷或行為不符合預期時,此指令應會自動載入。

使用觸發詞

  • @debugging 或 @debug:在會話中提及此觸發詞以載入此指令。
  • /debugging 或 /debug:鍵入此斜線指令以載入此指令。

手動使用

你可以直接在此文件中找到指示並手動套用步驟,或將此文件作為特定除錯會話的上下文引用。

支援的平台

此指令設計用於任何支援系統指令或規則功能的 AI 編碼代理,包括 Claude Code、Cline、Cursor 和 GitHub Copilot。

情境與步驟

當你(AI 代理)在開發過程中遇到任何問題,請遵循以下系統性除錯流程。

1. 準確重現錯誤

在你開始診斷之前,先確保有一個可重現的案例。

  • 失敗的正確命令是什麼?
  • 錯誤訊息或記錄的完整文字是什麼?
  • 測試案例是否完整記錄了預期行為?

除非你能可靠地重現,否則不要繼續。

2. 建立最小案例

將問題隔離到最小的案例或測試。

  • 從失敗的程式碼中移除不相關的部分。
  • 使用硬編碼值簡化輸入。
  • 對於測試,確保測試本身邏輯正確。
  • 檢查常用的陷阱:邊界條件、空值、未定義值。

3. 二分搜尋法(適用時)

如果目前狀態有效,但回歸出現在程式碼庫中:

  • 使用 git bisect 找出引入錯誤的提交。
  • 或者:掃描變動檔案,找出最可能的原因。
    • 尋找型別變更、簽名變更或移除的邊界檢查。

4. 檢查核心假設

重新審視你對程式碼庫所作的假設:

  • 函式參數順序是否假設正確?
  • 錯誤處理是否被忽略?
  • 型別合約是否被侵犯?
  • 非同步操作順序是否正確?
  • 狀態更新是否為不可變?
  • 環境(Node 版本、瀏覽器版本、作業系統)是否被考慮?

5. 隔離變數

一次只變更一件事。不要同時修復多個問題。

  • 如果問題消失,你就找到了。
  • 如果問題仍然存在,繼續隔離。
  • 記錄你已排除的內容。

6. 從邊界開始修復

最常見的錯誤發生在邊界處:

  • 開始/結束索引
  • 空陣列
  • 單一元素
  • 最大/最小值
  • 非同步競態條件
  • 未定義的環境變數

7. 驗證修復

  • 修復是否通過了所有現有測試?
  • 是否新增了一個針對此特定錯誤的測試?
  • 修復是否意外破壞了其他功能?
  • 如果合適,請考慮進行回歸測試。

範例

情境:測試因「經過」結果不一致而失敗

# 測試案例(失敗)
def test_time_convert():
    assert time_convert("1:30 PM") == "13:30"
    assert time_convert("12:00 AM") == "00:00"
    assert time_convert("12:00 PM") == "12:00"

步驟 1:重現

執行失敗的測試並觀察錯誤。可能是「12:00 AM」導致「12:00」而非「00:00」。

步驟 2:最小案例

隔離到只測試「12:00 AM」。確認問題出在邊界值(午夜)。

步驟 3:檢查核心假設

  • 函式是否錯誤地將午夜當作中午?
  • 比較運算子是否為不完全的大於/小於?

步驟 4:隔離變數

只修復這一個案例,並重新執行邊界測試。

步驟 5:修復

def time_convert(time_str):
    # 現有邏輯
    # 修復:正確處理午夜(12:00 AM -> 00:00)

步驟 6:驗證

確認所有測試通過。

進階除錯技巧

  • 複雜系統除錯:當處理多個元件時,使用隔離和二分搜尋法來找出是哪個互動導致了問題。
  • 效能回歸:如果是效能問題,加入基準測試並逐步將效能二分到可接受的程度。
  • 間歇性錯誤:這是最難處理的!尋找記錄模式、競態條件以及未處理的非同步流程。考慮新增更詳細的記錄。

何時使用此技能

在以下情況,你應該主動應用此技能:

  • ❌ 測試失敗且原因不明。
  • ❌ 建置步驟在預期成功時卻中斷。
  • ❌ UI 行為與使用者互動不符。
  • ❌ 看似合理的變更導致意外結果。
  • ❌ 你陷入了修改-觀察的猜測循環。

當情況更加穩固且除錯步驟不明顯時,請不要使用此技能。有時快速目視掃描就足夠了。

作者

由 Addy Osmani 建立(addyosmani)。

Individual skills in this repo

This repo contains 20 individual skills — each has its own dedicated page.

addyosmani/agent-skills

Guides stable API and interface design. Use when designing APIs, module boundaries, or any public interface. Use when creating REST or GraphQL endpoints, defining type contracts between modules, or establishing boundaries between frontend and backend.

addyosmani/agent-skills

Prepares production launches. Use when preparing to deploy to production, or when asking what needs to be in place before shipping. Use when you need a pre-launch checklist, when setting up monitoring, when planning a staged rollout, or when you need a rollback strategy.

addyosmani/agent-skills

Builds production-quality, accessible, responsive user-facing UIs. Use when building or modifying interfaces and pages, creating components, implementing layouts, meeting WCAG accessibility requirements, managing state, or when the output needs to look and feel production-quality rather than AI-generated.

addyosmani/browser-testing-with-devtools

Tests in real browsers via Chrome DevTools MCP. Use when building or debugging anything that runs in a browser. Use when you need to inspect the DOM, capture console errors, analyze network requests, profile performance, or verify visual output with real runtime data. Requires the chrome-devtools MCP server to be configured.

addyosmani/ci-cd-and-automation

Automates CI/CD pipeline setup. Use when setting up or modifying build and deployment pipelines. Use when you need to automate quality gates, configure test runners in CI, or establish deployment strategies.

addyosmani/code-review-and-quality

Conducts multi-axis code review. Use before merging any change. Use when reviewing code written by yourself, another agent, or a human. Use when you need to assess code quality across multiple dimensions before it enters the main branch.

addyosmani/code-simplification

Simplifies code for clarity. Use when refactoring code for clarity without changing behavior. Use when code works but is harder to read, maintain, or extend than it should be. Use when reviewing code that has accumulated unnecessary complexity.

addyosmani/constraint-driven-development

Establishes a project's quality bar as a written contract and stops agents quietly lowering it. Interviews the user on which dimensions matter, supplies sane default thresholds when they have no number in mind, records everything in CONSTRAINTS.md, and watches the diff for a weakened bar — new @ts-ignore or eslint-disable suppressions, skipped or deleted tests, assertions stripped out, unimplemented stubs, thresholds edited down. Use when no quality bar is written down, when the user says "set up constraints" or "define our standards", when the user wants dimensions they care about — accessibility, web performance, coverage — set up as enforced constraints, when an agent keeps silencing checks or skipping tests to get to green, when you need a coverage or performance threshold and don't know what number to pick, or when an agent writes more code than anyone will read.

addyosmani/deprecation-and-migration

Manages deprecation and migration. Use when removing old systems, APIs, or features. Use when migrating users from one implementation to another. Use when deciding whether to maintain or sunset existing code.

addyosmani/documentation-and-adrs

Records decisions and documentation. Use when making architectural decisions, changing public APIs, shipping features, or when you need to record context that future engineers and agents will need to understand the codebase.

addyosmani/doubt-driven-development

Subjects every non-trivial decision to a fresh-context adversarial review before it stands. Use when correctness matters more than speed, when working in unfamiliar code, when stakes are high (production, security-sensitive logic, irreversible operations), or any time a confident output would be cheaper to verify now than to debug later.

addyosmani/git-workflow-and-versioning

Structures git workflow practices. Use when making any code change. Use when committing, branching, resolving conflicts, or when you need to organize work across multiple parallel streams.

addyosmani/idea-refine

Refines raw ideas into sharp, actionable concepts through structured divergent and convergent thinking. Use when an idea is still vague, when you need to stress-test assumptions before committing to a plan, or when you want to expand options before converging on one. Triggers on "ideate", "refine this idea", or "stress-test my plan".

addyosmani/incremental-implementation

Delivers changes incrementally. Use when implementing any feature or change that touches more than one file. Use when you're about to write a large amount of code at once, or when a task feels too big to land in one step.

addyosmani/interview-me

Extracts what the user actually wants instead of what they think they should want. Achieves this through one-question-at-a-time interview until ~95% confidence about the underlying intent. Use when an ask is underspecified ("build me X" without "for whom" or "why now"), when the user explicitly invokes ("interview me", "grill me", "are we sure?", "stress-test my thinking"), or when you catch yourself silently filling in ambiguous requirements before any plan, spec, or code exists.

addyosmani/observability-and-instrumentation

Instruments code so production behavior is visible and diagnosable. Use when adding logging, metrics, tracing, or alerting. Use when shipping any feature that runs in production and you need evidence it works. Use when production issues are reported but you can't tell what happened from the available data.

addyosmani/performance-optimization

Optimizes application performance. Use when performance requirements exist, when you suspect performance regressions, or when Core Web Vitals or load times need improvement. Use when profiling reveals bottlenecks that need fixing.

addyosmani/planning-and-task-breakdown

Breaks work into ordered tasks. Use when you have a spec or clear requirements and need to break work into implementable tasks. Use when a task feels too large to start, when you need to estimate scope, or when parallel work is possible.

addyosmani/security-and-hardening

Hardens code against vulnerabilities. Use when handling user input, authentication, data storage, or external integrations. Use when building any feature that accepts untrusted data, manages user sessions, or interacts with third-party services.

addyosmani/source-driven-development

Grounds every implementation decision in official documentation. Use when you want authoritative, source-cited code free from outdated patterns. Use when building with any framework or library where correctness matters.

相關技能