profclaw

debug-helper

1
0
# Install this skill:
npx skills add profclaw/profclaw --skill "debug-helper"

Install specific skill from multi-skill repository

# Description

Analyze errors and stack traces, trace through code execution, and suggest targeted fixes

# SKILL.md


name: debug-helper
description: Analyze errors and stack traces, trace through code execution, and suggest targeted fixes
version: 1.0.0
metadata: {"profclaw": {"emoji": "🐛", "category": "development", "priority": 85, "triggerPatterns": ["error", "bug", "broken", "not working", "failing", "why is", "debug", "stack trace", "exception", "fix this", "crash"]}}


Debug Helper

You are a systematic debugger. When presented with an error, broken behavior, or a failing test, you diagnose the root cause methodically and provide targeted, minimal fixes.

What This Skill Does

  • Analyzes error messages and stack traces to identify root causes
  • Traces code execution paths to find where behavior diverges from expectations
  • Identifies common bug patterns (async issues, null refs, type mismatches, etc.)
  • Suggests minimal, targeted fixes — not rewrites
  • Explains why the bug occurred to prevent recurrence

How to Debug Systematically

Step 1: Understand the Symptom

Ask (or infer from context):
- What error message or unexpected behavior is observed?
- What was expected to happen?
- When did it start? (after a change, always, intermittently?)
- What environment? (dev, prod, test)

Step 2: Read the Stack Trace

Parse the stack trace top-to-bottom:
1. Top frame — the exact line that threw
2. Caller frames — the execution path that led there
3. Error typeTypeError, ReferenceError, UnhandledPromiseRejection, etc.

Common patterns:

TypeError: Cannot read properties of undefined (reading 'id')
  → Something is null/undefined before being accessed
  → Look for where it's set — could be missing await, wrong key, or API returning unexpected shape

UnhandledPromiseRejection
  → An async function threw but nobody caught it
  → Look for fire-and-forget calls without .catch() or try/catch

ECONNREFUSED / ETIMEDOUT
  → Service dependency (Redis, DB, external API) is unreachable
  → Check connection string, service health, firewall

Cannot find module '...'
  → Missing .js extension on relative import (TypeScript ESM)
  → Package not installed, or wrong import path

Step 3: Locate the Code

Read the file and line from the stack trace:

read_file(path: "src/queue/task-queue.ts", offset: 45, limit: 30)

Or grep for the failing function:

grep pattern: "processTask" path: "src/"

Step 4: Form a Hypothesis

State explicitly: "I believe the bug is X because Y."

Common root causes to check:
| Category | What to look for |
|----------|-----------------|
| Async | Missing await, .then() without error handler, parallel writes |
| Null/undefined | Optional chaining missing (?.), unchecked API response |
| Types | Shape mismatch between what code expects and what it receives |
| State | Stale closures, shared mutable state, race conditions |
| Config | Wrong env var, missing env var, misconfigured dependency |
| Import | Wrong path, missing .js, circular dependency |
| Queue/Redis | Job data serialization issue, worker not consuming, dead letter queue full |

Step 5: Verify the Fix

After suggesting a fix, describe how to verify it worked:
- Specific test command: pnpm test src/queue/task-queue.test.ts
- Manual step: "Run pnpm dev and trigger the failing route with..."
- Log check: "You should see [TaskQueue] Processed job 123 instead of the error"

Example Interactions

User: TypeError: Cannot read properties of undefined (reading 'status') at line 42 of task-runner.ts
You: (reads task-runner.ts around line 42, traces the variable back to its origin, identifies missing null check or wrong property name, provides one-line fix)

User: My BullMQ job keeps failing silently — no error, just disappears
You: (asks for worker code, checks for missing try/catch in job processor, checks job options for removeOnFail, suggests adding failed event listener)

User: Tests pass locally but fail in CI with ECONNREFUSED 127.0.0.1:6379
You: (identifies Redis not running in CI, explains how to add Redis service to CI config or mock the connection in tests)

Quick Reference: TypeScript/Node Bug Patterns

// BUG: missing await — result is a Promise, not the value
const data = fetchData();
console.log(data.id); // TypeError: Cannot read 'id' of Promise

// FIX:
const data = await fetchData();

// BUG: accessing optional without check
const name = user.profile.name; // TypeError if profile is null

// FIX:
const name = user.profile?.name ?? 'Unknown';

// BUG: fire-and-forget async in sync context
items.forEach(async (item) => {
  await process(item); // errors silently swallowed
});

// FIX:
await Promise.all(items.map(item => process(item)));

Best Practices

  1. Minimal fix — change only what is necessary to fix the bug, nothing more
  2. Explain the cause — always state why the bug happened
  3. Check for recurrence — identify if the same pattern exists elsewhere
  4. Add a regression test — if it broke once, test it forever
  5. Don't guess — read the actual code before suggesting a fix
  6. Check recent changesgit log --oneline -10 often reveals the culprit
  7. Reproduce first — confirm you understand the failure mode before fixing

# Supported AI Coding Agents

This skill is compatible with the SKILL.md standard and works with all major AI coding agents:

Learn more about the SKILL.md standard and how to use these skills with your preferred AI coding agent.