Token导航 LogoToken导航

Agent Skill · 研究检索

debugging(调试)

debugging 用于查找、检索和筛选相关信息,适合在 Codex、Claude、Cursor、Gemini CLI 中需要根据关键词、任务场景或来源线索快速定位候选结果时使用。可结合来源仓库、安装命令和原始 README 继续核验具体用法。安装前建议确认权限范围、维护状态,以及是否会触发联网、命令执行或文件读写。

debugging 是研究检索类 Agent Skill,可用宿主为 Codex、Claude、Cursor、Gemini CLI,通过GitHub 仓库获取,权限为需要联网;许可证信息还不明确,第三方扫描有未通过项,按安装量在研究检索类的 73,675 个 Skill 里排第 38,789。

总安装 1,512周安装 63GitHub Stars 6下载 504核验 2026-05-01

安装说明

本站只整理中文说明,不托管安装包,也不代用户安装。
GitHub
许可证
unknown

安装方式

通过对话安装

复制提示词发给支持本地命令或 Skills 的 AI 助手,先确认命令和权限,再让它执行。

请帮我安装这个 Agent Skill:debugging(调试)
来源仓库:https://github.com/mgd34msu/goodvibes-plugin
仓库路径:skills/debugging
安装命令:
npx skills add https://github.com/mgd34msu/goodvibes-plugin --skill debugging
安装前请先检查当前环境是否支持对应 CLI,并向我确认将要执行的命令、安装目录、联网范围和文件读写权限;确认后再执行。

命令行安装

复制命令到本机终端执行。该命令会通过 npx skills 从第三方来源获取 Skill;本站只展示命令,不托管安装包,也不自动执行。

skills.shnpx skills
npx skills add https://github.com/mgd34msu/goodvibes-plugin --skill debugging

这个 Skill 是做什么的

研究检索类 Skill 主要解决「找资料、核对事实、把来源整理清楚」的问题,通常会让助手先检索再总结。

debugging 用于查找、检索和筛选相关信息。适合在 Codex、Claude、Cursor、Gemini CLI 中根据任务场景快速定位候选结果。通过 npx skills add 命令从指定仓库安装,需确认权限范围和维护状态。使用前建议核实是否会触发联网、命令执行或文件读写操作。

debugging 属于研究检索类 Skill,可作为该场景下的辅助能力补充。

来源仓库内路径:skills/debugging

上手步骤

4 步
  1. 1

    确认自己的宿主工具

    公开资料标注支持 Codex、Claude、Cursor、Gemini CLI;先确认自己用的是其中之一,再按对应工具的 Skills 目录放置。

  2. 2

    拿到安装命令

    可以直接复制的命令是 npx skills add https://github.com/mgd34msu/goodvibes-plugin --skill debugging;命令里的占位符换成自己的路径或密钥再执行。

  3. 3

    安装后重启宿主

    命令执行完要完全退出宿主工具再打开,让新装的 Skill 被重新扫描到,否则列表里可能看不到。

  4. 4

    按最小权限试用

    它需要需要联网,先在测试目录或测试账号里跑,确认没问题再放到正式项目。

常见问题

6 条

debugging 怎么安装?

在终端执行 npx skills add https://github.com/mgd34msu/goodvibes-plugin --skill debugging。装完完全退出宿主工具再打开,让它重新扫描本地 Skill。

debugging 支持哪些 AI 工具?

公开资料标注支持 Codex、Claude、Cursor、Gemini CLI。其他工具只要能读取本地 Skill 目录,一般也能手动放进去,但要自己确认触发方式是否一致。

debugging 需要什么权限?

权限级别是需要联网。该 Skill 可能需要联网访问来源站点、仓库或外部 API;具体网络访问范围需要结合源码和 README 复核。

debugging 是免费的吗?

公开资料没有标注明确许可证,收费和商用限制都无法确认。正式使用前请到来源仓库核对授权说明。

debugging 用的人多吗?

公开数据是累计安装 1,512 次,近一周安装 63 次,下载 504 次,GitHub 6 星。这些数字来自第三方目录统计,只能当作热度参考,不代表质量或安全性。

debugging 安全吗?

第三方扫描有未通过项,风险较高。除非你确认过源码,否则不建议直接安装到常用环境。

值得选的地方和要先想清楚的地方

值得选的地方

  • 同时适配 4 种工具,换客户端不用重新找替代品。

先想清楚的地方

  • 许可证没有明确标注,能不能商用、能不能再分发都不确定。
  • 第三方扫描存在提醒项或未通过项,需要人工逐条确认。
  • 第三方目录整理,版本更新和行为细节以来源仓库为准。

适不适合你

更适合

  • 已经在用 Codex,想直接扩展它能力的人。
  • 需要处理研究检索类任务、又不想每次都手写提示词的人。

不太适合

  • 需要明确授权才能用到公司项目里的场景。
  • 需要厂商级技术支持和 SLA 的生产系统。

研究检索类 Skill 对比

6 个同类
Skill总安装GitHub 星权限许可证扫描
find-skills

寻找技能 · Codex、Claude

31,199,81316,486操作浏览器MIT有提醒
self-improving-agent

自我改进 Agent · OpenClaw

16,464,0023,396接触敏感数据MIT-0通过
soultrace

灵魂追踪 · Codex、Claude

7,588,94412需要联网未明确有提醒
self-improving

自我完善 · OpenClaw

6,829,2841,046需要联网MIT-0通过
microsoft-foundry

微软代工厂 · Codex、Claude

6,614,144764调用外部服务未明确有提醒
debugging

调试 · 本页

1,5126需要联网未明确未通过

按安装量取同分类前几名;数字来自第三方目录统计,只作热度参考,不代表质量结论。

SKILL.md 原文

Resources

scripts/
  validate-debugging.sh
references/
  debugging-patterns.md

Debugging Quality Skill

This skill teaches you how to debug systematically using GoodVibes precision tools. Effective debugging requires a methodical approach: reproduce the issue, isolate the cause, identify the root problem, apply a fix, and verify the solution.

When to Use This Skill

Load this skill when:

  • Investigating runtime errors or exceptions
  • Tracing unexpected behavior or logic errors
  • Analyzing network request/response issues
  • Debugging state management problems
  • Diagnosing performance bottlenecks
  • Investigating build or compilation errors
  • Understanding TypeScript type errors
  • Performing root cause analysis

Trigger phrases: "debug this error", "why is this failing", "investigate the issue", "trace the problem", "analyze the error".

Core Workflow

Phase 1: Reproduce - Confirm the Issue

Before debugging, confirm you can reproduce the issue reliably.

Step 1.1: Gather Error Context

Collect all available error information.

precision_exec:
  commands:
    - cmd: "npm run typecheck 2>&1"
    - cmd: "npm run lint 2>&1"
    - cmd: "npm run build 2>&1"
  verbosity: standard

What to capture:

  • Complete error message and stack trace
  • Error type and code (if applicable)
  • File path and line number
  • Timestamps and environment info
  • User actions that triggered the error
Step 1.2: Find Error Occurrences

Search for similar errors in the codebase.

discover:
  queries:
    - id: error_throw_sites
      type: grep
      pattern: "throw new (Error|TypeError|RangeError)"
      glob: "**/*.{ts,tsx,js,jsx}"
    - id: error_handlers
      type: grep
      pattern: "catch\\s*\\("
      glob: "**/*.{ts,tsx,js,jsx}"
    - id: console_errors
      type: grep
      pattern: "console\\.(error|warn)"
      glob: "**/*.{ts,tsx,js,jsx}"
  verbosity: locations

Pattern categories:

Error PatternMeaningCommon Causes
ReferenceErrorVariable not definedTypo, missing import, scope issue
TypeErrorWrong type usednull/undefined, wrong method, type mismatch
RangeErrorValue out of rangeArray index, numeric overflow
SyntaxErrorInvalid syntaxParsing error, malformed JSON
NetworkErrorRequest failedCORS, timeout, 404, auth failure
Step 1.3: Reproduce Locally

Run the failing operation to confirm reproduction.

precision_exec:
  commands:
    - cmd: "npm run dev"
      timeout_ms: 5000
  verbosity: minimal

Reproduction checklist:

  • Error reproduces consistently
  • Minimal steps to reproduce identified
  • Environment matches production (Node version, deps)
  • Error message matches reported issue

Phase 2: Isolate - Narrow Down the Cause

Reduce the problem space to find where the error originates.

Step 2.1: Read the Stack Trace

Analyze the call stack to understand execution flow.

Stack trace example:

TypeError: Cannot read property 'name' of undefined
    at getUserName (src/utils/user.ts:42:18)
    at UserProfile (src/components/UserProfile.tsx:15:22)
    at renderWithHooks (node_modules/react/cjs/react.development.js:1234)

Reading strategy:

  1. Start at the top - The actual error location
  2. Trace backwards - Follow the call chain
  3. Ignore node_modules - Focus on your code
  4. Find the entry point - Where did the bad data come from?
precision_read:
  files:
    - path: "src/utils/user.ts"
      extract: content
      range: {start: 35, end: 50}
    - path: "src/components/UserProfile.tsx"
      extract: content
      range: {start: 10, end: 25}
  verbosity: standard
Step 2.2: Trace Data Flow

Follow the data from source to error point.

discover:
  queries:
    - id: function_calls
      type: grep
      pattern: "getUserName\\("
      glob: "**/*.{ts,tsx}"
    - id: data_sources
      type: grep
      pattern: "(fetch|axios|prisma).*user"
      glob: "**/*.{ts,tsx}"
    - id: prop_passing
      type: grep
      pattern: "user=\\{"
      glob: "**/*.tsx"
  verbosity: locations

Data flow analysis:

  • Where does the data originate? (API, database, props)
  • What transformations occur? (map, filter, destructure)
  • What assumptions are made? (not null, specific shape)
  • Where could it become undefined?
Step 2.3: Check Boundary Conditions

Test edge cases where errors commonly occur.

discover:
  queries:
    - id: array_access
      type: grep
      pattern: "\\[[0-9]+\\]|\\[.*\\]"
      glob: "**/*.{ts,tsx}"
    - id: null_checks
      type: grep
      pattern: "(if.*===.*null|if.*===.*undefined|\\?\\.|\\?\\?)"
      glob: "**/*.{ts,tsx}"
    - id: optional_chaining
      type: grep
      pattern: "\\?\\."
      glob: "**/*.{ts,tsx}"
  verbosity: locations

Common boundary issues:

IssueExampleFix
Array out of boundsarr[arr.length]Check arr.length > 0
Null/undefined accessuser.nameUse user?.name
Division by zerototal / countCheck count!== 0
Empty string operationsstr[0]Check str.length > 0
Missing object keysobj.keyUse obj?.key?? default

Phase 3: Identify - Pinpoint the Root Cause

Determine the underlying problem, not just the symptom.

Step 3.1: Analyze Error Patterns

Classify the error to understand common causes.

Type Errors

precision_exec:
  commands:
    - cmd: "npm run typecheck 2>&1 | head -50"
  verbosity: standard

Common TypeScript errors:

Error CodeMeaningFix
TS2339Property does not existAdd property to type or use optional chaining
TS2345Argument type mismatchFix the type or add type assertion
TS2322Type not assignableChange the type or fix the value
TS2571Object is of type unknownAdd type guard or assertion
TS7006Implicit any parameterAdd parameter type annotation

Runtime Errors

discover:
  queries:
    - id: unsafe_access
      type: grep
      pattern: "\\.[a-zA-Z]+(?!\\?)"
      glob: "**/*.{ts,tsx}"
    - id: async_errors
      type: grep
      pattern: "await.*(?!try)"
      glob: "**/*.{ts,tsx}"
  verbosity: files_only

Common runtime errors:

  • Cannot read property X of undefined
  • Cannot read property X of null
  • X is not a function
  • X is not iterable
  • Maximum call stack size exceeded (infinite recursion)
Step 3.2: Check Dependencies and Imports

Module resolution errors are common.

discover:
  queries:
    - id: imports
      type: grep
      pattern: "^import.*from"
      glob: "**/*.{ts,tsx}"
    - id: dynamic_imports
      type: grep
      pattern: "import\\("
      glob: "**/*.{ts,tsx}"
    - id: require_statements
      type: grep
      pattern: "require\\("
      glob: "**/*.{ts,js}"
  verbosity: locations

Common import issues:

IssueSymptomFix
Missing exportModule has no exported memberAdd export to source file
Circular dependencyCannot access before initializationRestructure imports
Wrong pathModule not foundFix relative path or alias
Default vs namedX is not a functionUse import X or import {X}
Type-only importCannot use as valueRemove type keyword
Step 3.3: Validate Assumptions

Question assumptions about data shape and state.

precision_grep:
  queries:
    - id: type_assertions
      pattern: "as (unknown|any|[A-Z][a-zA-Z]+)"
      glob: "**/*.{ts,tsx}"
  output:
    format: context
    context_before: 2
    context_after: 2
  verbosity: standard

Dangerous assumptions:

  • API always returns expected shape
  • Array is never empty
  • User is always authenticated
  • Data is always valid
  • Props are always provided

Validate with:

  • Runtime type validation (Zod, Yup)
  • Type guards (if (typeof x === 'string'))
  • Null checks (if (x!= null))
  • Default values (x?? defaultValue)

Phase 4: Fix - Apply the Solution

Implement the fix based on root cause analysis.

Step 4.1: Choose the Right Fix

Match the fix to the problem type.

Type Safety Fixes

// Before: Implicit any
function getUser(id) {
  return users.find(u => u.id === id);
}

// After: Explicit types
function getUser(id: string): User | undefined {
  return users.find(u => u.id === id);
}

Null Safety Fixes

// Before: Unsafe access
const name = user.profile.name;

// After: Optional chaining
const name = user?.profile?.name ?? 'Anonymous';

Async Error Handling

// Before: Unhandled promise
await fetchData();

// After: Try/catch
try {
  await fetchData();
} catch (error: unknown) {
  logger.error('Failed to fetch data', { error });
  throw new AppError('Data fetch failed', { cause: error });
}

Array Boundary Fixes

// Before: Unsafe access
const first = items[0];

// After: Safe access
const first = items.length > 0 ? items[0] : null;
// Or: const first = items.at(0) ?? null;
Step 4.2: Add Defensive Code

Prevent similar errors in the future.

Input validation:

import { z } from 'zod';

const userSchema = z.object({
  id: z.string().uuid(),
  email: z.string().email(),
  name: z.string().min(1).max(100),
});

function processUser(data: unknown) {
  const user = userSchema.parse(data); // Throws if invalid
  // Now user is type-safe
}

Type guards:

function isUser(value: unknown): value is User {
  return (
    typeof value === 'object' &&
    value !== null &&
    'id' in value &&
    'email' in value
  );
}

if (isUser(data)) {
  // TypeScript knows data is User
  logger.info('User email', { email: data.email });
}

Error boundaries (React):

import { ErrorBoundary } from 'react-error-boundary';

function ErrorFallback({ error }: { error: Error }) {
  return (
    <div role="alert">
      <p>Something went wrong:</p>
      <pre>{error.message}</pre>
    </div>
  );
}

<ErrorBoundary FallbackComponent={ErrorFallback}>
  <MyComponent />
</ErrorBoundary>
Step 4.3: Apply the Fix

Use precision_edit to make the change.

precision_edit:
  edits:
    - path: "src/utils/user.ts"
      find: |
        function getUserName(user) {
          return user.name;
        }
      replace: |
        function getUserName(user: User | undefined): string {
          return user?.name ?? 'Unknown';
        }
  verbosity: minimal

Phase 5: Verify - Confirm the Fix Works

Validate that the fix resolves the issue without breaking anything.

Step 5.1: Type Check

Ensure TypeScript errors are resolved.

precision_exec:
  commands:
    - cmd: "npm run typecheck"
  verbosity: standard

All type errors must be resolved.

Step 5.2: Run Tests

Confirm tests pass.

precision_exec:
  commands:
    - cmd: "npm test"
  verbosity: standard

If tests fail:

  • Fix introduced a regression
  • Test expectations need updating
  • Test revealed another issue
Step 5.3: Manual Verification

Reproduce the original error scenario.

precision_exec:
  commands:
    - cmd: "npm run dev"
      timeout_ms: 5000
  verbosity: minimal

Verification checklist:

  • Original error no longer occurs
  • Edge cases handled (null, empty, large values)
  • No new errors introduced
  • Performance not degraded
  • User experience improved

Phase 6: Network Debugging

Debug API requests and responses.

Step 6.1: Find Network Calls

Locate all HTTP requests.

discover:
  queries:
    - id: fetch_calls
      type: grep
      pattern: "fetch\\("
      glob: "**/*.{ts,tsx,js,jsx}"
    - id: axios_calls
      type: grep
      pattern: "axios\\.(get|post|put|delete|patch)"
      glob: "**/*.{ts,tsx,js,jsx}"
    - id: api_routes
      type: glob
      patterns: ["src/app/api/**/*.ts", "pages/api/**/*.ts"]
  verbosity: locations
Step 6.2: Check Request/Response Handling

Validate error handling for network calls.

precision_grep:
  queries:
    - id: fetch_with_catch
      pattern: "fetch\\([^)]+\\).*catch"
      glob: "**/*.{ts,tsx,js,jsx}"
  output:
    format: context
    context_after: 5
  verbosity: standard

Common network issues:

IssueSymptomFix
CORS errorBlocked by CORS policyAdd CORS headers to API
401 UnauthorizedMissing or invalid tokenAdd auth header, refresh token
404 Not FoundWrong URL or routeFix endpoint path
500 Server ErrorBackend exceptionCheck server logs, fix backend
TimeoutRequest takes too longIncrease timeout, optimize backend
Network failureFailed to fetchCheck connectivity, retry logic

Debugging CORS:

// Next.js API route
export async function GET(request: Request) {
  return Response.json(data, {
    headers: {
      'Access-Control-Allow-Origin': '*', // Development only - use specific origin in production
      'Access-Control-Allow-Methods': 'GET, POST, OPTIONS',
      'Access-Control-Allow-Headers': 'Content-Type, Authorization',
    },
  });
}

Debugging authentication:

// Check for auth header
const token = request.headers.get('Authorization')?.replace('Bearer ', '');
if (!token) {
  return Response.json({ error: 'Unauthorized' }, { status: 401 });
}

try {
  const session = await verifyToken(token);
} catch (error: unknown) {
  logger.error('Token verification failed', { error });
  return Response.json({ error: 'Invalid token' }, { status: 401 });
}
Step 6.3: Validate Request Payloads

Ensure request data is correct.

discover:
  queries:
    - id: request_bodies
      type: grep
      pattern: "(body:|JSON.stringify)"
      glob: "**/*.{ts,tsx}"
    - id: validation_schemas
      type: grep
      pattern: "z\\.object\\("
      glob: "**/*.{ts,tsx}"
  verbosity: locations

Request validation:

import { z } from 'zod';

const createUserSchema = z.object({
  email: z.string().email(),
  name: z.string().min(1).max(100),
});

export async function POST(request: Request) {
  const body = await request.json();
  const result = createUserSchema.safeParse(body);

  if (!result.success) {
    return Response.json(
      { error: 'Validation failed', details: result.error.flatten() },
      { status: 400 }
    );
  }

  // Now result.data is type-safe
}

Phase 7: State Debugging

Debug React state and state management.

Step 7.1: Find State Usage

Locate state declarations and updates.

discover:
  queries:
    - id: useState_calls
      type: grep
      pattern: "useState<?"
      glob: "**/*.{tsx,jsx}"
    - id: state_updates
      type: grep
      pattern: "set[A-Z][a-zA-Z]*\\("
      glob: "**/*.{tsx,jsx}"
    - id: useEffect_hooks
      type: grep
      pattern: "useEffect\\("
      glob: "**/*.{tsx,jsx}"
  verbosity: locations

Common state issues:

IssueSymptomFix
Stale closureState value is outdatedUse functional update
Missing dependencyuseEffect doesn't re-runAdd to dependency array
Infinite loopComponent re-renders foreverFix dependencies or condition
State race conditionUpdates override each otherUse reducer or queue
Lost state on unmountData disappearsLift state up or use global state

Stale closure fix:

// Before: Stale closure
const [count, setCount] = useState(0);

function increment() {
  setTimeout(() => {
    setCount(count + 1); // count is stale
  }, 1000);
}

// After: Functional update
function increment() {
  setTimeout(() => {
    setCount(prev => prev + 1); // Always current
  }, 1000);
}

useEffect dependency fix:

// Before: Missing dependency
useEffect(() => {
  fetchData(userId);
}, []); // userId changes ignored

// After: Complete dependencies
useEffect(() => {
  fetchData(userId);
}, [userId]); // Re-runs when userId changes
Step 7.2: Check for State Mutations

Find direct state mutations (anti-pattern).

discover:
  queries:
    - id: array_mutations
      type: grep
      pattern: "\\.(push|pop|shift|unshift|splice)\\("
      glob: "**/*.{tsx,jsx}"
    - id: object_mutations
      type: grep
      pattern: "[a-zA-Z]+\\.[a-zA-Z]+\\s*=\\s*"
      glob: "**/*.{tsx,jsx}"
  verbosity: locations

Immutable updates:

// Before: Mutation
const [items, setItems] = useState([1, 2, 3]);
items.push(4); // BAD: Mutates state
setItems(items);

// After: Immutable
setItems([...items, 4]); // GOOD: New array

// Object updates
const [user, setUser] = useState({ name: 'Alice', age: 30 });
setUser({ ...user, age: 31 }); // GOOD: New object

Phase 8: Performance Debugging

Diagnose performance bottlenecks.

Step 8.1: Find Performance Anti-patterns

Search for common performance issues.

discover:
  queries:
    - id: n_plus_one
      type: grep
      pattern: "(for|forEach|map).*await.*(prisma|db|query)"
      glob: "**/*.{ts,tsx}"
    - id: inline_objects
      type: grep
      pattern: "(onClick|onChange|style)=\\{\\{"
      glob: "**/*.{tsx,jsx}"
    - id: missing_memo
      type: grep
      pattern: "(map|filter|reduce|sort)\\("
      glob: "**/*.{tsx,jsx}"
  verbosity: locations

Performance issues:

Anti-patternImpactFix
N+1 queriesSlow database queriesUse include or batch loading
Inline objects in JSXUnnecessary re-rendersExtract to constant or useMemo
Large lists without virtualizationSlow renderingUse react-window or similar
Missing indexesSlow queriesAdd database indexes
Unnecessary re-rendersLaggy UIUse React.memo, useMemo, useCallback
Step 8.2: Profile Build Performance

Check for slow builds.

precision_exec:
  commands:
    - cmd: "npm run build"
  verbosity: standard

Build performance issues:

  • Large bundle size (check with bundle analyzer)
  • Slow TypeScript compilation (check tsconfig)
  • Missing tree-shaking (check imports)
  • Development dependencies in production (check package.json)

Phase 9: Root Cause Analysis

Go beyond symptoms to find underlying issues.

Step 9.1: Ask Why Five Times

Drill down to the root cause.

Example:

  1. Why did the app crash? - User data was undefined
  2. Why was user data undefined? - API returned null
  3. Why did API return null? - Database query returned no rows
  4. Why were there no rows? - User ID was incorrect
  5. Why was user ID incorrect? - Route parameter parsing failed

Root cause: Route parameter parsing doesn't handle edge cases.

Step 9.2: Check System Dependencies

Validate environment and dependencies.

precision_exec:
  commands:
    - cmd: "node --version"
    - cmd: "npm --version"
    - cmd: "npm list --depth=0"
  verbosity: minimal

Common dependency issues:

  • Version mismatch (package.json vs lockfile)
  • Peer dependency conflicts
  • Outdated packages with known bugs
  • Missing native dependencies
Step 9.3: Review Recent Changes

Find what changed before the error appeared.

precision_exec:
  commands:
    - cmd: "git log --oneline -10"
    - cmd: "git diff HEAD~5..HEAD"
  verbosity: standard

Git bisect for complex issues:

git bisect start
git bisect bad HEAD
git bisect good v1.0.0
# Test, then mark:
git bisect good  # or bad
# Repeat until culprit commit found

Phase 10: Prevention - Avoid Future Issues

Add safeguards to prevent recurrence.

Step 10.1: Add Tests

Write tests that catch the error.

import { describe, it, expect } from 'vitest';

describe('getUserName', () => {
  it('should handle undefined user', () => {
    expect(getUserName(undefined)).toBe('Unknown');
  });

  it('should handle user without name', () => {
    expect(getUserName({ id: '123' })).toBe('Unknown');
  });

  it('should return user name', () => {
    expect(getUserName({ id: '123', name: 'Alice' })).toBe('Alice');
  });
});
Step 10.2: Add Logging

Log key decision points for future debugging.

import { logger } from '@/lib/logger';

function processUser(user: User | undefined) {
  if (!user) {
    logger.warn('User is undefined in processUser');
    return null;
  }

  logger.info('Processing user', { userId: user.id });

  try {
    // Process user
  } catch (error: unknown) {
    logger.error('Failed to process user', { userId: user.id, error });
    throw error;
  }
}

Logging best practices:

  • Use structured logging (JSON)
  • Include context (user ID, request ID)
  • Use appropriate log levels (error, warn, info, debug)
  • Never log sensitive data (passwords, tokens)
  • Use correlation IDs to trace requests
Step 10.3: Add Monitoring

Track errors in production.

Error tracking (Sentry, Rollbar):

import * as Sentry from '@sentry/nextjs';

Sentry.init({
  dsn: process.env.SENTRY_DSN,
  tracesSampleRate: 0.1,
  beforeSend(event, hint) {
    // Filter sensitive data
    if (event.request) {
      delete event.request.cookies;
    }
    return event;
  },
});

Custom error classes:

export class AppError extends Error {
  constructor(
    message: string,
    public code: string,
    public statusCode: number = 500,
    public context?: Record<string, unknown>
  ) {
    super(message);
    this.name = 'AppError';
  }
}

throw new AppError('User not found', 'USER_NOT_FOUND', 404, { userId });

Common Debugging Patterns

See references/debugging-patterns.md for detailed patterns organized by category.

Error Pattern Detection

Use discover to find multiple error patterns at once.

discover:
  queries:
    # Type safety issues
    - { id: any_usage, type: grep, pattern: ':\\s*any', glob: '**/*.{ts,tsx}' }
    - { id: type_assertions, type: grep, pattern: 'as (any|unknown)', glob: '**/*.{ts,tsx}' }
    # Runtime safety
    - { id: unsafe_access, type: grep, pattern: '\\.[a-zA-Z]+(?!\\?)', glob: '**/*.{ts,tsx}' }
    - { id: unhandled_promises, type: grep, pattern: 'await.*(?!try)', glob: '**/*.{ts,tsx}' }
    # Performance
    - { id: n_plus_one, type: grep, pattern: 'for.*await.*prisma', glob: '**/*.{ts,tsx}' }
    - { id: inline_objects, type: grep, pattern: 'onClick=\\{\\{', glob: '**/*.{tsx,jsx}' }
  verbosity: locations

Systematic Error Analysis

Step 1: Categorize the error

  • Type error (compile-time)
  • Runtime error (null, undefined, type mismatch)
  • Logic error (wrong behavior, no exception)
  • Performance error (too slow)
  • Network error (API failure)

Step 2: Find similar patterns

  • Search for the error message
  • Search for the error type
  • Search for the failing function name

Step 3: Trace the data

  • Where does the data come from?
  • What transformations occur?
  • Where does it fail?

Step 4: Validate assumptions

  • Is the data shape correct?
  • Are types accurate?
  • Are edge cases handled?

Step 5: Fix and verify

  • Apply the fix
  • Run type check
  • Run tests
  • Verify manually

Precision Tools for Debugging

Discover Tool

Run parallel searches to find error patterns.

discover:
  queries:
    - id: error_sites
      type: grep
      pattern: "throw new"
      glob: '**/*.{ts,tsx,js,jsx}'
    - id: catch_blocks
      type: grep
      pattern: "catch\\s*\\("
      glob: '**/*.{ts,tsx,js,jsx}'
    - id: console_logs
      type: grep
      pattern: "console\\.(log|error|warn)"
      glob: '**/*.{ts,tsx,js,jsx}'
  verbosity: locations

Precision Grep

Search with context for understanding surrounding code.

precision_grep:
  queries:
    - id: error_context
      pattern: "TypeError|ReferenceError|RangeError"
      glob: "**/*.{ts,tsx,js,jsx}"
  output:
    format: context
    context_before: 5
    context_after: 5
  verbosity: standard

Precision Exec

Run diagnostic commands.

precision_exec:
  commands:
    - cmd: "npm run typecheck 2>&1"
    - cmd: "npm run lint 2>&1"
    - cmd: "npm test 2>&1"
  verbosity: standard

Precision Edit

Apply fixes atomically.

precision_edit:
  edits:
    - path: "src/utils/user.ts"
      find: "user.name"
      replace: "user?.name ?? 'Unknown'"
  verbosity: minimal

Validation Script

Use scripts/validate-debugging.sh to validate debugging practices.

./scripts/validate-debugging.sh /path/to/project

The script checks:

  • console.log statements removed from production
  • Error boundaries implemented
  • Source maps configured
  • Proper logging libraries used
  • Try/catch blocks handling errors
  • Debug dependencies excluded from production

Quick Reference

Debugging Checklist

Reproduce:

  • Error reproduces consistently
  • Minimal reproduction steps identified
  • Environment matches
  • Error message captured

Isolate:

  • Stack trace analyzed
  • Data flow traced
  • Boundary conditions tested
  • Similar patterns found

Identify:

  • Error categorized
  • Root cause identified (not symptom)
  • Assumptions validated
  • Dependencies checked

Fix:

  • Appropriate fix chosen
  • Defensive code added
  • Fix applied
  • No new issues introduced

Verify:

  • Type check passes
  • Tests pass
  • Manual verification complete
  • Edge cases tested

Prevent:

  • Tests added for the issue
  • Logging added
  • Monitoring configured
  • Documentation updated

Error Severity Guide

Critical (fix immediately):

  • Application crashes
  • Data loss or corruption
  • Security vulnerabilities
  • Production outage

High (fix soon):

  • Feature completely broken
  • Poor user experience
  • Performance degradation
  • Type safety violations

Medium (fix when able):

  • Edge case failures
  • Minor UX issues
  • Console warnings
  • Missing error handling

Low (fix eventually):

  • Code style issues
  • Missing documentation
  • Optimization opportunities
  • Refactoring needs

Common Mistakes to Avoid

Fixing symptoms, not causes:

  • BAD: Add null check without understanding why it's null
  • GOOD: Trace why the value is null and fix the source

Skipping verification:

  • BAD: Apply fix and assume it works
  • GOOD: Run tests, type check, and manual verification

Ignoring edge cases:

  • BAD: Fix the common case only
  • GOOD: Test null, undefined, empty, and large values

No prevention:

  • BAD: Fix the bug and move on
  • GOOD: Add tests and logging to prevent recurrence

Advanced Techniques

Binary Search Debugging

For complex issues, use binary search to narrow down.

Comment out half the code:

  1. Comment out half the function
  2. If error persists, problem is in remaining half
  3. If error disappears, problem is in commented half
  4. Repeat until isolated

Rubber Duck Debugging

Explain the problem out loud:

  1. Describe what the code should do
  2. Describe what it actually does
  3. Walk through line by line
  4. Often reveals the issue during explanation

Time-Travel Debugging

Use git to find when the bug was introduced:

git bisect start
git bisect bad HEAD
git bisect good v1.0.0
# Test each commit
git bisect good  # or bad

Logging Strategy

Trace important values:

function processData(data: unknown) {
  logger.debug('Input data', { data });

  const validated = schema.parse(data);
  logger.debug('Validated data', { validated });

  const transformed = transform(validated);
  logger.debug('Transformed data', { transformed });

  return transformed;
}

Use correlation IDs:

import { v4 as uuid } from 'uuid';

export async function POST(request: Request) {
  const requestId = uuid();
  logger.info('Request started', { requestId });

  try {
    const result = await processRequest(request);
    logger.info('Request completed', { requestId });
    return Response.json(result);
  } catch (error: unknown) {
    logger.error('Request failed', { requestId, error });
    throw error;
  }
}

Integration with Other Skills

  • Use error-recovery for automated fix attempts
  • Use code-review to catch errors during review
  • Use testing-strategy to prevent regressions
  • Use performance-audit for performance issues
  • Use security-audit for security vulnerabilities

Resources

平台分布

Codex

32.66%
按下载量换算165

Claude

31.58%
按下载量换算159

Cursor

19.02%
按下载量换算96

Gemini CLI

8.15%
按下载量换算41

安全审计

Gen Agent Trust Hub

未通过

Socket

通过

Snyk

通过

权限和风险

需要联网

该 Skill 可能需要联网访问来源站点、仓库或外部 API;具体网络访问范围需要结合源码和 README 复核。

安装前确认

本站仅展示第三方公开信息,不托管安装包,不提供自动安装或运行环境。安装前应自行审查源码、依赖和命令行为。来源安全扫描存在提醒或未通过项,安装前请自行复核。目前只有一个公开来源,建议同时核对源仓库。

继续浏览同类 Skills