golang-error-handling

Analyze Go code for error wrapping, context propagation, and nil interface checks.

16|2|Updated Jan 21, 2026
One-click install
npx skills add https://github.com/saifoelloh/golang-best-practices-skill --skill golang-error-handling
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: golang-error-handling
Source: https://github.com/saifoelloh/golang-best-practices-skill/tree/main/error-handling
Command: npx skills add https://github.com/saifoelloh/golang-best-practices-skill --skill golang-error-handling

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes scripts (resource) and references (resource) components.

What problem does it solve?

This Skill ensures your Go applications handle errors robustly, preventing critical issues like lost error chains, context leaks, and incorrect error comparisons, which can lead to production bugs and difficult debugging.

Core Features & Use Cases

  • Error Wrapping: Enforces the use of %w for proper error chaining, enabling errors.Is and errors.As.
  • Context Propagation: Ensures context.Context is passed correctly through the call stack, allowing for graceful cancellation and timeouts.
  • Nil Interface Handling: Prevents bugs caused by incorrectly checking interface nil values.
  • Use Case: Reviewing a complex microservice to ensure that all outgoing API calls correctly propagate the request context, so that if the initial client request is cancelled, all downstream operations are also terminated promptly, preventing resource leaks.

Quick Start

Review the error handling in the provided Go code for potential issues.

Frequently Asked Questions about golang-error-handling

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

FAQPage Schema
How do I check for nil interface values correctly in Go to avoid hidden bugs?

Checking nil interface values in Go requires verifying both the type and value are nil, because an interface holding a nil pointer is not itself nil. This Skill analyzes your code to identify incorrect nil interface checks that cause unexpected behavior.

Why does my Go error wrapping lose context and break errors.Is checks?

Go error wrapping loses context when using incorrect formatting verbs instead of the %w directive, which breaks errors.Is and errors.As chains. This Skill detects missing %w usage in your code to ensure proper error wrapping and accurate comparisons.

How do I ensure context propagation works correctly for cancellation and timeouts in Go microservices?

Context propagation in Go microservices requires passing context.Context through the entire call stack to maintain cancellation and timeout mechanisms. This Skill reviews your code to ensure downstream operations correctly inherit and respect the request context.

What is the best way to review Go code for error handling best practices and resource leaks?

Reviewing Go code for error handling best practices involves analyzing error wrapping with %w, context propagation, and nil interface checks. This Skill identifies critical issues that could lead to lost error information and resource leaks during debugging.

How do I prevent lost error chains when wrapping errors in Go applications?

Preventing lost error chains in Go requires using the %w directive when wrapping errors with fmt.Errorf to maintain the error sequence. This Skill analyzes your codebase to find instances where error information is lost due to incorrect wrapping.

Can I use this for reviewing context leaks and cancellation issues in complex microservices?

Yes, you can use this for reviewing complex microservices to verify that outgoing API calls correctly propagate the request context. This ensures cancelled client requests terminate all downstream operations promptly, preventing resource leaks and broken timeouts.