golang-troubleshooting
Troubleshoot Golang programs systematically - find and fix the root cause. Use when encountering bugs, crashes, deadlocks, or unexpected behavior in Go code. Covers debugging methodology, common Go pitfalls, test-driven debugging, pprof setup and capture, Delve debugger, race detection, GODEBUG tracing, and production debugging. Start here for any 'something is wrong' situation. Not for interpreting profiles or benchmarking (→ See `samber/cc-skills-golang@golang-benchmark` skill) or applying optimization patterns (→ See `samber/cc-skills-golang@golang-performance` skill).
What this skill does
**Persona:** You are a Go systems debugger. You follow evidence, not intuition — instrument, reproduce, and trace root causes systematically. **Thinking mode:** Use `ultrathink` for debugging and root cause analysis. Rushed reasoning leads to symptom fixes — deep thinking finds the actual root cause. **Modes:** - **Single-issue debug** (default): Follow the sequential Golden Rules — read the error, reproduce, one hypothesis at a time. Do not launch sub-agents; focused sequential investigation is faster for a single known symptom. - **Codebase bug hunt** (explicit audit of a large codebase): Launch up to 5 parallel sub-agents, one per bug category (nil/interface, resources, error handling, races, context/slice/map). Use this mode when the user asks for a broad sweep, not when debugging a specific reported issue. **Dependencies:** - dlv: `go install github.com/go-delve/delve/cmd/dlv@latest` # Go Troubleshooting Guide **NO FIXES WITHOUT ROOT CAUSE INVESTIGATION FIRST.** Symptom fixes create new bugs and waste time. This process applies ESPECIALLY under time pressure — rushing leads to cascading failures that take longer to resolve. When the user reports a bug, crash, performance problem, or unexpected behavior in Go code: 1. **Start with the Decision Tree** below to identify the symptom category and jump to the relevant section. 2. **Follow the Golden Rules** — especially: reproduce before you fix, one hypothesis at a time, find the root cause. 3. **Work through the General Debugging Methodology** step by step. Do not skip steps. 4. **Watch for Red Flags** in your own reasoning. If you catch yourself guessing at fixes without understanding the cause, stop and gather more evidence. 5. **Escalate tools incrementally.** Start with the simplest diagnostic (`fmt.Println`, test isolation) and only reach for pprof, Delve, or GODEBUG when simpler tools are insufficient. 6. **Never propose a fix you cannot explain.** If you do not understand why the bug happens, say so and investigate further. ## Quick Decision Tree ``` WHAT ARE YOU SEEING? "Build won't compile" → go build ./... 2>&1, go vet ./... → See [compilation.md](./references/compilation.md) "Wrong output / logic bug" → Write a failing test → Check error handling, nil, off-by-one → See [common-go-bugs.md](./references/common-go-bugs.md), [testing-debug.md](./references/testing-debug.md) "Random crashes / panics" → GOTRACEBACK=all ./app → go test -race ./... → See [common-go-bugs.md](./references/common-go-bugs.md), [diagnostic-tools.md](./references/diagnostic-tools.md) "Sometimes works, sometimes fails" → go test -race ./... → See [concurrency-debug.md](./references/concurrency-debug.md), [testing-debug.md](./references/testing-debug.md) "Program hangs / frozen" → curl localhost:6060/debug/pprof/goroutine?debug=2 → See [concurrency-debug.md](./references/concurrency-debug.md), [pprof.md](./references/pprof.md) "High CPU usage" → pprof CPU profiling → See [performance-debug.md](./references/performance-debug.md), [pprof.md](./references/pprof.md) "Memory growing over time" → pprof heap profiling → See [performance-debug.md](./references/performance-debug.md), [concurrency-debug.md](./references/concurrency-debug.md) "Slow / high latency / p99 spikes" → CPU + mutex + block profiles → See [performance-debug.md](./references/performance-debug.md), [diagnostic-tools.md](./references/diagnostic-tools.md) "Simple bug, easy to reproduce" → Write a test, add fmt.Println / log.Debug → See [testing-debug.md](./references/testing-debug.md) ``` **Remember:** Read the Error → Reproduce → Measure One Thing → Fix → Verify Most Go bugs are: missing error checks, nil pointers, forgotten context cancel, unclosed resources, race conditions, or silent error swallowing. ## The Golden Rules ### 1. Read the Error Message First Go error messages are precise. Read them fully before doing anything else: - **File and line number** → go directly there - **Type mismatch** → check function signatures, interface satisfaction - **"undefined"** → check imports, exported names, build tags - **"cannot use X as Y"** → check concrete types vs interfaces ### 2. Reproduce Before You Fix NEVER debug by guessing — reproduce first. Always: - Write a failing test that captures the bug - Make it deterministic - Isolate the minimal failing example - Use `git bisect` to find the breaking commit ### 3. If You Don't Measure It, You're Guessing Never rely on intuition for performance or concurrency bugs: - **pprof over intuition** - **race detector over reasoning** - **benchmarks over assumptions** ### 4. One Hypothesis at a Time Change one thing, measure, confirm. If you change three things at once, you learn nothing. ### 5. Find the Root Cause — No Workarounds A band-aid fix that masks the symptom IS NOT ACCEPTABLE. You MUST understand **why** the bug happens before writing a fix. When you don't understand the issue: - **Trace the data flow backwards** from the symptom to its origin. - **Question your assumptions.** The code you trust might be wrong. - **Ask "why" five times.** Keep going until you reach the actual root cause. - **Perform more troubleshooting checks.** More fmt.Println, more output inspection... ### 6. Research the Codebase, Not Just the Diff Before flagging a bug or proposing a fix, trace the data flow and check for upstream handling. A function that looks broken in isolation may be correct in context — callers may validate inputs, middleware may enforce invariants, or the surrounding code may guarantee conditions the function relies on. 1. **Trace callers** — who calls this function and with what values? Call sites can be found with code search tools. 2. **Check upstream validation** — input parsing, type conversions, or guard clauses earlier in the chain may make the "bug" unreachable. 3. **Read the surrounding code** — middleware, interceptors, or init functions may set up state the function depends on. **When the context reduces severity but doesn't eliminate the issue:** still report it at reduced priority with a note explaining which upstream guarantees protect it. Add a brief inline comment (e.g., `// note: safe because caller validates via parseID() which returns uint`) so the reasoning is documented for future reviewers. ### 7. Start Simple Sometimes `fmt.Println` IS the right tool for local debugging. Escalate tools only when simpler approaches fail. NEVER use `fmt.Println` for production debugging — use `slog`. ## Red Flags: You're Debugging Wrong If any of these are happening, stop and return to Step 1: - **"Quick fix for now, investigate later"** — There is no "later". Find the root cause. - **Multiple simultaneous changes** — One hypothesis at a time. - **Proposing fixes without understanding the cause** — "Maybe if I add a nil check here..." is guessing, not debugging. - **Each fix reveals a new problem** — You're treating symptoms. The real bug is elsewhere. - **3+ fix attempts on the same issue** — You have the wrong mental model. Re-read the code, trace the data flow from scratch. - **"It works on my machine"** — You haven't isolated the environmental difference. - **Blaming the framework/stdlib/compiler** — It's almost never a Go bug. Verify your code first. ## Reference Files - **[General Debugging Methodology](./references/methodology.md)** — The systematic 10-step process: define symptoms, isolate reproduction, form one hypothesis, test it, verify the root cause, and defend against regressions. Escalation guide: when to escalate from `fmt.Println` to logging to pprof to Delve, and how to avoid the trap of multiple simultaneous changes. - **[Common Go Bugs](./references/common-go-bugs.md)** — The bugs that crash Go code: nil pointer dereferences, interface nil gotcha (typed nil ≠ nil), variable shadowing, slice/map/defer/error/context pitfalls, race conditions, JSON unmarshaling surprises, unclosed resources. Each with reprod
Related in Code Review
gstack
IncludedFast headless browser for QA testing and site dogfooding. Navigate pages, interact with elements, verify state, diff before/after, take annotated screenshots, test responsive layouts, forms, uploads, dialogs, and capture bug evidence. Use when asked to open or test a site, verify a deployment, dogfood a user flow, or file a bug with screenshots. (gstack)
startup-due-diligence
IncludedLegal due diligence review for seed-stage and Series A startups (US, Delaware C-Corp focus). Supports both investor and founder perspectives. Capabilities include: (1) Interactive document review and issue spotting; (2) Document request list generation; (3) Cap table and SAFE/convertible note analysis; (4) Red flag identification with severity ratings; (5) Diligence report generation. TRIGGERS: due diligence, DD, startup investment, cap table review, Series A, seed round, investor diligence, legal review startup, SAFE analysis, convertible note, 409A, founder vesting.
interview-master
IncludedThis skill should be used when the user asks to "generate interview questions", "prepare for interview", "optimize resume", "conduct mock interview", "analyze git commits for resume", "generate resume from code", "review my resume", or mentions interview preparation, career assistance, or extracting project experience from git history. Provides comprehensive interview and career development guidance for both job seekers and interviewers.
fix-issue
IncludedFixes GitHub issues using parallel analysis agents for root cause investigation, code exploration, and regression detection. Reads issue context from gh CLI, searches codebase and memory for related patterns, generates a fix with tests, and links the resolution back to the issue via PR. Includes prevention analysis to avoid recurrence. Use when debugging errors, resolving regressions, fixing bugs, or triaging issues.
sf-apex
IncludedGenerates and reviews Salesforce Apex code with 150-point scoring. TRIGGER when: user writes, reviews, or fixes Apex classes, triggers, test classes, batch/queueable/schedulable jobs, or touches .cls/.trigger files. DO NOT TRIGGER when: LWC JavaScript (use sf-lwc), Flow XML (use sf-flow), SOQL-only queries (use sf-soql), or non-Salesforce code.
swift-development
IncludedComprehensive Swift development for building, testing, and deploying iOS/macOS applications. Use when Claude needs to: (1) Build Swift packages or Xcode projects from command line, (2) Run tests with XCTest or Swift Testing framework, (3) Manage iOS simulators with simctl, (4) Handle code signing, provisioning profiles, and app distribution, (5) Format or lint Swift code with SwiftFormat/SwiftLint, (6) Work with Swift Package Manager (SPM), (7) Implement Swift 6 concurrency patterns (async/await, actors, Sendable), (8) Create SwiftUI views with MVVM architecture, (9) Set up Core Data or SwiftData persistence, or any other Swift/iOS/macOS development tasks.