debugging

star 0

Systematic debugging methodology for identifying and resolving software defects. Use this skill when diagnosing bugs, tracing unexpected behavior, or analyzing error logs and stack traces.

xiaoshuangLi By xiaoshuangLi schedule Updated 2/27/2026

name: debugging description: Systematic debugging methodology for identifying and resolving software defects. Use this skill when diagnosing bugs, tracing unexpected behavior, or analyzing error logs and stack traces.

Debugging Skill

๐ŸŽฏ Purpose

Provides a structured, scientific approach to debugging that avoids random trial-and-error and leads to reliable root cause identification and resolution.

๐Ÿš€ When to Use

  • Diagnosing unexpected behavior or incorrect output
  • Analyzing error messages and stack traces
  • Investigating intermittent or flaky test failures
  • Understanding why a "simple" change caused a regression
  • Debugging performance degradation
  • Tracing data flow through complex systems

๐Ÿ”ฌ Scientific Debugging Method

Step 1: Reproduce the Bug

Before anything else, establish a reliable reproduction case.

# Minimal reproduction requirements:
# 1. Known input that triggers the bug
# 2. Expected output
# 3. Actual (wrong) output
# 4. Reproducibility rate (always / sometimes / rarely)

Step 2: Understand the System

  • Read the relevant code paths before guessing
  • Use grep_files to find all code related to the bug
  • Use glob_files to understand the project structure
  • Use LSP get_definition and get_references to trace symbol usage

Step 3: Form a Hypothesis

"The bug is caused by X because Y" โ€” make one specific, testable hypothesis.

Step 4: Test the Hypothesis

  • Add targeted logging (not console.log everywhere)
  • Use debugger breakpoints to inspect state
  • Write a failing test that captures the bug

Step 5: Fix and Verify

  • Apply the minimal fix that addresses the root cause
  • Run the failing test โ€” it should now pass
  • Run the full test suite to check for regressions

Step 6: Prevent Recurrence

  • Add a regression test
  • Document the root cause in the commit message
  • Consider whether similar bugs exist elsewhere

๐Ÿ” Debugging Strategies

Binary Search Debugging

Cut the search space in half with each observation:

# For version regressions: git bisect
git bisect start
git bisect bad HEAD
git bisect good v1.0.0
# Test each commit, mark good/bad until root commit is found
git bisect run npm test

Rubber Duck Debugging

Explain the problem out loud (or in writing) step by step. Articulating the problem often reveals the solution.

Delta Debugging

"What changed?" โ€” compare working vs broken states:

git diff <working-commit> <broken-commit>
git log --oneline <working-commit>..HEAD

๐Ÿงฐ Debugging Tools by Environment

Node.js / TypeScript

# Enable Node.js debugger
node --inspect-brk dist/index.js
# Then open chrome://inspect in Chrome

# Run tests with debugger
node --inspect-brk node_modules/.bin/jest --runInBand

# Trace asynchronous operations
NODE_OPTIONS='--trace-warnings' node app.js

# Heap snapshot for memory leaks
node --heapsnapshot-signal=SIGUSR2 app.js

Common Log Analysis

# Find all error patterns in logs
grep_files pattern="ERROR|FATAL|Exception" include="**/*.log"

# Find recent changes to a specific function
git log -p --follow -S "functionName" -- src/

๐Ÿ› Common Bug Patterns

Off-by-One Errors

// Wrong: misses last element
for (let i = 0; i < arr.length - 1; i++) { ... }

// Right
for (let i = 0; i < arr.length; i++) { ... }

Async/Await Mistakes

// Bug: not awaiting async function
const result = getData(); // missing await!

// Bug: Promise rejection not caught
fetch(url).then(r => r.json()); // no .catch()

// Correct
const result = await getData();
const result = await fetch(url).then(r => r.json()).catch(handleError);

Null/Undefined Access

// Bug: accessing property of potentially null value
const name = user.profile.name; // TypeError if profile is null

// Safe: optional chaining
const name = user?.profile?.name ?? 'Unknown';

Mutation Bugs

// Bug: mutating shared array
const modifiedData = data;
modifiedData.push(newItem); // also modifies `data`!

// Correct: copy first
const modifiedData = [...data];
modifiedData.push(newItem);

๐Ÿ“‹ Bug Report Template

When escalating a bug or writing a GitHub issue:

## Summary
One-sentence description of the bug.

## Environment
- OS: macOS 14.1 / Ubuntu 22.04
- Node.js: v20.x
- Package version: 1.2.3

## Steps to Reproduce
1. Given ...
2. When ...
3. Then ...

## Expected Behavior
What should happen.

## Actual Behavior
What actually happens (include error messages and stack traces).

## Minimal Reproduction
Link to minimal code that reproduces the issue.

## Additional Context
Relevant logs, screenshots, or related issues.
Install via CLI
npx skills add https://github.com/xiaoshuangLi/aibo --skill debugging
Repository Details
star Stars 0
call_split Forks 0
navigation Branch main
article Path SKILL.md
More from Creator
xiaoshuangLi
xiaoshuangLi Explore all skills →