golang-troubleshooting

Diagnose and fix root causes of bugs, crashes, and deadlocks in Go programs.

1|Updated May 25, 2020
One-click install
npx skills add https://github.com/titaneric/dotfiles --skill golang-troubleshooting-titaneric
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: golang-troubleshooting
Source: https://github.com/titaneric/dotfiles/tree/main/dot_agents/skills/golang-troubleshooting
Command: npx skills add https://github.com/titaneric/dotfiles --skill golang-troubleshooting-titaneric

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires dlv, and includes references (resource) components.

What problem does it solve? Go bugs like nil pointer dereferences, race conditions, goroutine leaks, and silent error swallowing are hard to trace, and quick symptom-level fixes often create new failures. This Skill enforces a systematic debugging methodology that finds the actual root cause before any fix is applied. ## Core Features & Use Cases - Systematic Debugging Methodology: A 10-step process covering symptom definition, reproduction with failing tests, single-hypothesis testing, root-cause tracing, and defense-in-depth verification. - Common Go Pitfall Catalog: Detailed references for interface nil gotchas, variable shadowing, defer-in-loop leaks, concurrent map access, WaitGroup misuse, JSON float64 surprises, and channel deadlocks. - Diagnostic Tooling Guidance: Practical usage of pprof profiling, Delve debugger, race detector, GODEBUG tracing, and production debugging techniques. - Use Case: When a Go service intermittently crashes with 'concurrent map read and map write' despite recover middleware, the Skill explains why this fatal error bypasses recover and guides you to fix it with sync.RWMutex and the race detector. ## Quick Start Ask the AI to debug your Go program using the golang-troubleshooting skill, describing the symptom such as a panic, hang, or flaky test.

Frequently Asked Questions about golang-troubleshooting

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I debug a nil pointer dereference panic in Go?

Read the stack trace to find the exact line, then trace backward to where the nil value originated rather than adding a nil check at the crash site. Common causes include unchecked error returns, map lookups returning zero values, and uninitialized struct fields.

How do I find race conditions in Go code?

Run tests or the program with the -race flag, such as go test -race ./... or go run -race main.go. The race detector slows execution roughly 10x but reliably reports data races with full stack traces of conflicting accesses.

Why does my Go error check pass when the error should be nil?

A typed nil pointer wrapped in an error interface is not a nil interface, so err != nil evaluates true. Fix it by returning nil explicitly from the function instead of returning a typed nil variable like var err *MyError.

Can recover() catch panics from child goroutines in Go?

No, recover() only catches panics in the same goroutine where it is deferred. A panic in a child goroutine crashes the entire program, so each goroutine must include its own defer/recover block.

How do I detect goroutine leaks in a Go service?

Capture the goroutine profile via /debug/pprof/goroutine?debug=2 and look for goroutines stuck in chan receive. In tests, use go.uber.org/goleak, and monitor runtime.NumGoroutine() over time in production.

When should I use Delve versus pprof for Go debugging?

Use Delve for breakpoint-based stepping through code and inspecting variables during development or test debugging. Use pprof for profiling CPU, heap, goroutines, mutexes, and blocking behavior in running services, including production.