Skip to content
debug-helper logo

Debug Helper

debug-helper

Help debug code by analyzing error messages, identifying root causes, and providing fix suggestions.

SKILL.md

Full skill instructions

Debug Helper

帮助调试代码,分析错误信息,定位问题根源,提供修复建议。

Help debug code by analyzing error messages, identifying root causes, and providing fix suggestions.

When to Use

当用户请求以下操作时使用此 skill:

  • 调试代码 / Debug code
  • 分析错误信息 / Analyze error messages
  • 修复 bug / Fix bugs
  • 理解异常原因 / Understand exception causes
  • 排查问题 / Troubleshoot issues

Instructions

调试步骤 / Debugging Steps

  1. 收集信息 - 获取错误信息、堆栈跟踪、相关代码
  2. 分析错误 - 理解错误类型和消息含义
  3. 定位根源 - 找到导致问题的代码位置
  4. 提供解决方案 - 给出具体的修复建议
  5. 预防建议 - 提供避免类似问题的建议

常见错误类型 / Common Error Types

错误类型可能原因
TypeError类型不匹配、空值操作
ReferenceError未定义变量、作用域问题
SyntaxError语法错误、缺少括号/引号
RuntimeError运行时逻辑错误
NetworkError网络请求失败、超时

分析框架 / Analysis Framework

对于每个错误,需要分析:

  • What: 发生了什么错误
  • Where: 错误发生在哪里
  • Why: 为什么会发生
  • How: 如何修复

输出格式 / Output Format

使用 templates/​debug-report.md 模板格式化输出。

Use the templates/​debug-report.md template to format output.

## 调试分析报告 / Debug Analysis Report

### 错误概述 / Error Summary
[错误类型和简要描述]

### 根本原因 / Root Cause
[详细分析]

### 修复方案 / Fix
[具体代码修改]

### 预防建议 / Prevention
[如何避免类似问题]

Examples

输入 / Input

错误信息:

TypeError: Cannot read properties of undefined (reading 'map')
    at UserList (UserList.jsx:15:23)
    at renderWithHooks (react-dom.development.js:14985:18)

相关代码:

function UserList({ users }) {
  return (
    <ul>
      {users.map(user => (
        <li key={user.id}>{user.name}</​li>
      ))}
    </​ul>
  );
}

输出 / Output

调试分析报告

错误概述

TypeError: Cannot read properties of undefined (reading 'map')

在 UserList 组件第 15 行调用 .map() 时,users 变量为 undefined。

根本原因

  1. 直接原因: 尝试在 undefined 上调用 .map() 方法
  2. 深层原因:
    • 父组件可能没有传递 users prop
    • 数据获取尚未完成时组件已渲染
    • API 返回格式与预期不符

修复方案

方案 1: 添加默认值(推荐)

function UserList({ users = [] }) {
  return (
    <ul>
      {users.map(user => (
        <li key={user.id}>{user.name}</​li>
      ))}
    </​ul>
  );
}

方案 2: 条件渲染

function UserList({ users }) {
  if (!users || users.length === 0) {
    return <p>No users found</​p>;
  }

  return (
    <ul>
      {users.map(user => (
        <li key={user.id}>{user.name}</​li>
      ))}
    </​ul>
  );
}

方案 3: 可选链操作符

function UserList({ users }) {
  return (
    <ul>
      {users?.map(user => (
        <li key={user.id}>{user.name}</​li>
      ))}
    </​ul>
  );
}

预防建议

  1. 使用 TypeScript - 添加类型检查

    interface Props {
      users: User[];
    }
    
  2. 添加 PropTypes - 运行时类型检查

    UserList.propTypes = {
      users: PropTypes.array.isRequired
    };
    
  3. 检查数据源 - 确保父组件正确传递数据

  4. 处理加载状态 - 在数据获取期间显示加载指示器

More skills from majiayu000

xiaohongshu logo
majiayu000/claude-arsenal

xiaohongshu

xiaohongshu

286 148
View
agent-task-conductor logo
majiayu000/claude-skill-registry

agent-task-conductor

Conduct multi-agent task orchestration and workflow coordination.

663 1
View
conductor-setup logo
majiayu000/claude-skill-registry

conductor-setup

Initialize project with Conductor artifacts (product definition,

663 1
View
animation-designer logo
majiayu000/claude-skill-registry

animation-designer

Expert in web animations, transitions, and motion design using Framer Motion and CSS

663 1
View
diagramming logo
majiayu000/claude-skill-registry

diagramming

Creates Mermaid and ASCII diagrams for flowcharts, architecture, ERDs, state machines, mindmaps, and more. Use when user mentions diagram, flowchart, mermaid, ASCII diagram, text diagram, terminal diagram, visualize, C4, mindmap, architecture diagram, sequence diagram, ERD, or needs visual docume...

663 1
View
h3-pg logo
majiayu000/claude-skill-registry-data

h3-pg

PostgreSQL bindings for H3 hexagonal grid system. Use when working with H3 cells in Postgres, including spatial indexing, geometry/geography integration, and raster analysis.

23 1
View
conductor-development logo
majiayu000/claude-skill-registry

conductor-development

Context-Driven Development skill for projects using Conductor. Use this skill when you detect a `conductor/` directory in the project, when working on tasks defined in a `plan.md` file, or when the user asks about tracks, specs, or plans. Automatically applies TDD workflow, tracks task completion...

663 1
View
conductor-status logo
majiayu000/claude-skill-registry

conductor-status

Display project status, active tracks, and next actions

663 1
View
dockerization logo
majiayu000/claude-skill-registry

dockerization

Official Stakpak application containerization standard operating procedure, a step-by-step guidline to properly dockerize applications. This is a rule book curated by the Stakpak Team.

663 1
View

Popular AI tools

Kaiber logo
Video

Kaiber

Generate, edit, and beat-sync AI video with leading models in one workspace.

Paid
View
Vimcal logo
Productivity

Vimcal

The world's fastest calendar for remote work

Free
View

Transform Your Design with AI Designer by ImgCreator.ai

Freemium
View
Akool AI logo
Content & writing

Akool AI

Revolutionizing Video Production with AI-Powered Creativity

Paid
View

Extend an image past the frame and let AI fill the new aspect ratio.

Freemium
View
StarByFace logo
Security

StarByFace

Discover your celebrity doppelgänger with StarByFace!

Free
View
C

ChainClarity explains 700+ crypto whitepapers in plain English, with layered summaries, comparisons, research tools, alerts, and a $4.99 Pro plan.

Freemium
View
Opus Clip logo
Coding & apps

Opus Clip

Opus.ai: Revolutionize Your Web Experience

Free
View