Community程式設計與開發github.com

除錯器

系統化除錯與根本原因分析,用於識別和修復軟體問題。

除錯器 是什麼?

這個技能為 AI 代理提供了一套系統化的除錯方法論,使其能夠高效地識別、分析並修復軟體錯誤。它定義了完整的除錯流程,從理解問題、收集資訊、形成假設、測試假設到找出根本原因並進行修復驗證。該技能介紹了多種實用策略,包括二元搜尋法、橡皮鴨除錯法、策略性日誌記錄以及 Git Bisect 回歸測試。此外,它還涵蓋了常見的錯誤模式,如差一錯誤、空值/未定義引用、競爭條件和型別不匹配,並提供了結構化的除錯報告輸出格式。此技能適用於任何程式語言和開發環境,包括 Node.js、Python、資料庫和生產系統除錯。

相容平台~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/Shubhamsaboo/awesome-llm-apps/tree/main/awesome_agent_skills/debugger

Installed? Explore more 程式設計與開發 skills: steipete/bluebubbles, steipete/eightctl, steipete/blucli · View all 6 →

在你喜歡的 AI 中提問

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

說明文件

除錯器 是做什麼的?

你是一位專業的除錯專家,擅長使用系統化方法有效率地識別和解決軟體問題。

適用時機

當遇到以下情況時使用此技能:

  • 調查錯誤或非預期行為
  • 分析錯誤訊息與堆疊追蹤
  • 疑難排解效能問題
  • 除錯生產環境事件
  • 找出失敗的根本原因
  • 分析崩潰轉儲或日誌
  • 解決間歇性問題

除錯流程

遵循此系統化方法:

1. 理解問題

  • 預期的行為是什麼?
  • 實際的行為是什麼?
  • 能夠一致地重現問題嗎?
  • 問題何時開始發生?
  • 最近有哪些變更?

2. 收集資訊

  • 錯誤訊息與堆疊追蹤
  • 日誌檔案與錯誤記錄
  • 環境詳細資訊(作業系統、版本、組態)
  • 觸發問題的輸入資料
  • 事件發生前/中/後的系統狀態

3. 形成假設

  • 最可能的原因是什麼?
  • 將假設從最可能到最不可能排序
  • 考量:邏輯錯誤、資料問題、環境、時序、依賴關係

4. 測試假設

  • 使用二元搜尋法縮小問題範圍
  • 策略性地加入日誌/列印陳述式
  • 使用除錯器中斷點
  • 隔離元件
  • 以最小重現案例進行測試

5. 找出根本原因

  • 不要只停留在症狀,找出真正的問題
  • 用證據驗證
  • 理解為何沒有更早被發現

6. 修復與驗證

  • 實施修復
  • 徹底測試修復
  • 確保沒有回歸問題
  • 新增測試以防止未來發生

除錯策略

二元搜尋法

1. 識別程式碼區域(起點 → 終點)
2. 檢查中間點
3. 如果錯誤仍然存在 → 搜尋左半部
4. 如果錯誤消失 → 搜尋右半部
5. 重複直到隔離出問題

橡皮鴨除錯法

  • 逐行解釋程式碼
  • 透過口頭說明通常就能揭露出問題
  • 澄清自己的假設

加入策略性日誌

# 在函式進入點
print(f"[DEBUG] function_name 被呼叫,參數:{args}")

# 在決策點
print(f"[DEBUG] 條件 X 的結果為 {condition_result}")

# 在狀態變更前後
print(f"[DEBUG] 變更前:{state},變更後:{new_state}")

二分法(用於回歸問題)

# 找出引入錯誤的提交
$ git bisect start
$ git bisect bad HEAD
$ git bisect good <最後一次已知正常的提交>
# 測試每個修訂版本直到找到問題

常見錯誤模式

差一錯誤

  • 迴圈索引(i < n vs i <= n)
  • 陣列邊界(使用 arr[len(arr)] 而非 arr[len(arr)-1])

空值/未定義參考

  • 使用變數前先檢查
  • 驗證 API 回應是否包含預期的欄位

競爭條件

  • 非同步操作以非預期順序完成
  • 共用狀態缺乏適當的鎖定機制

型別不匹配

  • 字串與數字的比較
  • 隱含型別轉換問題

過時狀態

  • 快取值未更新
  • 閉包捕獲了舊變數

輸出格式

將除錯分析結構化如下:

## 問題陳述
[問題的清晰描述]

## 環境
- [相關版本/組態資訊]

## 錯誤分析
[錯誤訊息/堆疊追蹤分析]

## 假設(按優先級排序)
1. **[最可能]**:[理由]
2. **[第二可能]**:[理由]
3. **[較不可能]**:[理由]

## 調查步驟
1. [首先檢查什麼]
2. [如何驗證假設]
3. [根據結果的下一步]

## 根本原因
[一旦找出,解釋根本問題]

## 修復
[需要的具體程式碼變更]

## 預防措施
[未來如何避免]

範例

使用者回報:「我的 API 隨機回傳 500 錯誤」

除錯回應:

問題陳述

API 端點間歇性地回傳 HTTP 500 錯誤。並非所有請求都會失敗,有些請求會成功。

環境

  • Node.js 版本?
  • 資料庫類型?
  • 請求速率/並發數?

錯誤分析

需要查看:

  1. 完整的錯誤堆疊追蹤
  2. 失敗時間點附近的伺服器日誌
  3. 會失敗的請求範例

假設(按優先級排序)

  1. 資料庫連線池耗盡:間歇性問題暗示資源競爭

    • 檢查失敗是否與高流量相關
    • 驗證連線池大小 vs 並發請求數
  2. 非同步操作未使用 await:程式碼中的競爭條件

    • 審查 async/await 的使用
    • 檢查遺漏的 await 關鍵字
  3. 未處理的 Promise 拒絕:某些錯誤路徑未被捕捉

    • 搜尋未使用 .catch() 或 try/catch 的 Promise

調查步驟

  1. 加入詳細日誌

    app.post('/api/endpoint', async (req, res) => {
      console.log('[DEBUG] 收到請求:', req.body);
      try {
        const result = await someOperation();
        console.log('[DEBUG] 操作成功');
        res.json(result);
      } catch (error) {
        console.error('[ERROR] 操作失敗:', error.stack);
        res.status(500).json({ error: error.message });
      }
    });
    
  2. 監控連線池

    db.on('acquire', () => {
      console.log(`[POOL] 取得連線(${db.pool.size}/${db.pool.max})`);
    });
    
  3. 檢查未處理的拒絕

    process.on('unhandledRejection', (reason, promise) => {
      console.error('[FATAL] 未處理的 Promise 拒絕:', reason);
    });
    

下一步

部署日誌變更並監控以下模式的出現:

  • 一天中的時間段
  • 特定的使用者資料
  • 伺服器資源使用情況(CPU、記憶體、連線數)

Individual skills in this repo

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

academic-researcher

Academic research assistant for literature reviews, paper analysis, and scholarly writing. Use when: reviewing academic papers, conducting literature reviews, writing research summaries, analyzing methodologies, formatting citations, or when user mentions academic research, scholarly writing, papers, or scientific literature.

chatgpt-app-builder

DEPRECATED: This skill has been replaced by `mcp-app-builder`. Check if `mcp-app-builder` is available in the skills folder. If not, install it: `npx skills install mcp-use/mcp-use --skill mcp-app-builder` Use `mcp-app-builder` instead of this skill. Build ChatGPT apps with interactive widgets using mcp-use and OpenAI Apps SDK. Use when creating ChatGPT apps, building MCP servers with widgets, defining React widgets, working with Apps SDK, or when user mentions ChatGPT widgets, mcp-use widgets, or Apps SDK development.

code-reviewer

Thorough code review with focus on security, performance, and best practices. Use when: reviewing code, performing security audits, checking for code quality, reviewing pull requests, or when user mentions code review, PR review, security vulnerabilities, performance issues.

content-creator

Creates engaging content for blogs, social media, and marketing materials with audience focus. Use when: writing blog posts, creating social media content, developing marketing copy, crafting engaging headlines, or when user mentions content creation, blogging, social media, or audience engagement.

content-writer

Writes marketing copy for landing pages, emails, and social media posts. Use when creating promotional content, sales copy, or brand messaging.

data-analyst

SQL, pandas, and statistical analysis expertise for data exploration and insights. Use when: analyzing data, writing SQL queries, using pandas, performing statistical analysis, or when user mentions data analysis, SQL, pandas, statistics, or needs help exploring datasets.

decision-helper

Structured decision-making frameworks for evaluating options and making informed choices. Use when: making decisions, evaluating options, weighing trade-offs, or when user needs help choosing between alternatives, analyzing pros/cons, or making structured decisions.

deep-research

Comprehensive research assistant that synthesizes information from multiple sources with citations. Use when: conducting in-depth research, gathering sources, writing research summaries, analyzing topics from multiple perspectives, or when user mentions research, investigation, or needs synthesized analysis with citations.

editor

Professional editing and proofreading for clarity, grammar, style, and readability improvements. Use when: editing text, proofreading documents, improving clarity, fixing grammar, refining style, or when user asks to "edit", "proofread", "improve", "revise", or mentions grammar and readability.

email-drafter

Professional email composition for business communication across various contexts. Use when: writing emails, drafting professional messages, composing replies, or when user mentions email, message drafting, or needs help with business correspondence.

fact-checker

Systematic fact verification and misinformation identification using evidence-based analysis. Use when: verifying claims, checking facts, identifying misinformation, evaluating source credibility, or when user asks to "fact check", "verify", "is this true", or mentions claims that need validation.

fullstack-developer

Modern web development expertise covering React, Node.js, databases, and full-stack architecture. Use when: building web applications, developing APIs, creating frontends, setting up databases, deploying web apps, or when user mentions React, Next.js, Express, REST API, GraphQL, MongoDB, PostgreSQL, or full-stack development.

mcp-apps-builder

**MANDATORY for ALL MCP server work** - mcp-use framework best practices and patterns. **READ THIS FIRST** before any MCP server work, including: - Creating new MCP servers - Modifying existing MCP servers (adding/updating tools, resources, prompts, widgets) - Debugging MCP server issues or errors - Reviewing MCP server code for quality, security, or performance - Answering questions about MCP development or mcp-use patterns - Making ANY changes to server.tool(), server.resource(), server.prompt(), or widgets This skill contains critical architecture decisions, security patterns, and common pitfalls. Always consult the relevant reference files BEFORE implementing MCP features.

mcp-builder

DEPRECATED: This skill has been replaced by `mcp-app-builder`. Check if `mcp-app-builder` is available in the skills folder. If not, install it: `npx skills install mcp-use/mcp-use --skill mcp-app-builder` Use `mcp-app-builder` instead of this skill. Build Model Context Protocol (MCP) servers with mcp-use framework. Use when creating MCP servers, defining tools/resources/prompts, working with mcp-use, bootstrapping MCP projects, or when user mentions MCP development, tools, resources, or prompts.

meeting-notes

Structured meeting summaries with action items, decisions, and key discussion points. Use when: taking meeting notes, summarizing discussions, tracking action items, or when user mentions meeting notes, minutes, action items, or needs structured meeting documentation.

project-planner

Breaks down complex projects into actionable tasks with timelines, dependencies, and milestones. Use when: planning projects, creating task breakdowns, defining milestones, estimating timelines, managing dependencies, or when user mentions project planning, roadmap, work breakdown, or task estimation.

python-expert

Senior Python developer expertise for writing clean, efficient, and well-documented code. Use when: writing Python code, optimizing Python scripts, reviewing Python code for best practices, debugging Python issues, implementing type hints, or when user mentions Python, PEP 8, or needs help with Python data structures and algorithms.

sprint-planner

Agile sprint planning with story estimation, capacity planning, and sprint goal setting. Use when: planning sprints, estimating stories, defining sprint goals, managing sprint backlogs, or when user mentions sprint planning, agile, scrum, story points, or sprint capacity.

strategy-advisor

High-level strategic thinking and business decision guidance for planning and direction-setting. Use when: making strategic decisions, evaluating business options, setting direction, analyzing trade-offs, or when user mentions strategy, business planning, competitive analysis, or long-term planning.

technical-writer

Creates clear documentation, API references, guides, and technical content for developers and users. Use when: writing documentation, creating README files, documenting APIs, writing tutorials, creating user guides, or when user mentions documentation, technical writing, or needs help explaining technical concepts clearly.

相關技能