GO

go-lambda-error-handling

This skill provides patterns for handling errors in Go AWS Lambda functions, ensuring failures are explicit and properly mapped across boundaries.

Install

mkdir -p .claude/skills/go-lambda-error-handling && curl -L -o skill.zip "https://agentskills.codes/api/skills/download/14970" && unzip -o skill.zip -d .claude/skills/go-lambda-error-handling && rm skill.zip

Installs to .claude/skills/go-lambda-error-handling

Activation

This is the description your AI agent reads to decide when to run this skill — the better it matches your request, the more reliably it fires.

A skill for handling errors in Go microservices on AWS Lambda.
62 charsno explicit “when” trigger
Advanced

Key capabilities

  • Implement explicit error handling in Go Lambda
  • Map domain errors to HTTP status codes
  • Handle SQS batch item failures
  • Wrap errors with context using `%w`
  • Distinguish domain, validation, dependency, and unexpected failures
  • Ensure idempotency for message processing

How it works

The skill guides the implementation of explicit error handling in Go AWS Lambda services, focusing on mapping failures to appropriate HTTP or SQS responses. It emphasizes wrapping errors with context and distinguishing error categories at architectural boundaries.

Inputs & outputs

You give it
Go AWS Lambda service code with potential failure points
You get back
Go AWS Lambda service with explicit, diagnosable, and correctly mapped errors

When to use go-lambda-error-handling

  • Map internal domain errors to appropriate API Gateway status codes
  • Implement retry-aware error handling for SQS-triggered Lambda functions
  • Refactor code to replace panic calls with explicit error returns
  • Apply error wrapping with context using %w for better observability
  • Define distinct error categories for validation, dependency, and unexpected failures

About this skill

SKILL: go-lambda-error-handling

Purpose

Implement, modify, or review error handling in Go AWS Lambda services so that failures are explicit, diagnosable, and mapped correctly at architecture and transport boundaries.

This skill specializes the broader go-aws-lambda-microservice-hexagonal skill and applies to services whose inbound trigger is one or both of:

  • API Gateway HTTP API
  • Amazon SQS

Use this skill when

  • the codebase is Go
  • the compute model is AWS Lambda
  • the service uses or should use explicit errors instead of hidden fallbacks
  • the task touches domain/application/adapters boundaries
  • the service needs correct error mapping for HTTP or SQS behavior
  • the service needs retry-aware, idempotency-aware failure semantics

Do not use this skill when

  • the task is only about logging or telemetry with no change to error behavior
  • the task is only about styling or refactoring with no error-path impact
  • the service is a trivial one-off function with no reusable domain/application boundary

Core principles

  • Treat errors as values and handle them explicitly.
  • Prefer returning errors over using panic for ordinary control flow.
  • Wrap errors with context using %w so callers can inspect them with errors.Is and errors.As.
  • Keep domain, validation, dependency, and unexpected failures distinguishable.
  • Convert errors only at meaningful boundaries.
  • Do not let AWS transport types or HTTP concerns leak into domain/application errors.
  • Do not swallow errors, invent fallback success values, or return misleading partial success.
  • Panic is reserved for unrecoverable programmer bugs or truly impossible states, not normal business failure.

Architecture rules

Domain layer

  • Domain code may define sentinel or typed domain errors when callers need stable classification.
  • Domain errors must not depend on AWS, HTTP, SQS, or infrastructure-specific types.
  • Domain errors should represent business facts, invariants, and rule violations.
  • Do not log in domain code as a substitute for returning an error.

Application layer

  • Application handlers return explicit errors to the inbound adapter.
  • Application code may wrap lower-level failures with operation context.
  • Application code may classify retryable vs terminal failures when the transport requires it.
  • Application code must not return API Gateway response types or SQS batch response types.

Outbound adapters

  • Outbound adapters translate foreign SDK/client failures into repository/client/publisher errors meaningful to the application layer.
  • Preserve the original cause when translating with %w.
  • Do not leak low-level transport payloads or secrets through returned error text.
  • Keep provider-specific branching confined to the adapter boundary.

Inbound adapters

  • Inbound adapters own final error mapping to HTTP or SQS behavior.
  • Inbound adapters may convert application/domain errors into transport-specific responses.
  • Inbound adapters must not push HTTP or SQS semantics into domain/application code.

Go-specific rules

  • Prefer fmt.Errorf("context: %w", err) for wrapping.
  • Prefer errors.Is and errors.As for inspection.
  • Do not compare wrapped errors by string.
  • Do not use panic/recover as a replacement for ordinary error returns.
  • If panic recovery exists at the Lambda edge, it must be narrow, explicit, and convert the panic into a terminal failure path plus diagnostic logging.
  • Error strings should be lowercase and should not end with punctuation.

HTTP mode rules

  • For expected application failures, return a valid HTTP response with the correct status code from the HTTP adapter.
  • Do not bubble expected business or validation failures as raw Lambda invocation errors.
  • If a Lambda function returns an error or an invalid proxy response, API Gateway can return a generic internal error to the client; avoid this for expected error cases.
  • Keep HTTP status mapping in the HTTP adapter only.
  • Distinguish at least these classes when relevant:
    • validation / bad input -> 4xx
    • not found -> 404
    • conflict / invariant violation -> 409 or other contract-appropriate 4xx
    • dependency or unexpected failure -> 5xx
  • External error responses must be safe; they must not expose secrets, stack traces, or raw infrastructure details.

SQS mode rules

  • Treat delivery as at-least-once.
  • Make message handling idempotent.
  • Classify failures into retryable vs terminal where the business and infrastructure behavior require it.
  • When partial batch response is enabled, catch per-record failures and return batchItemFailures for failed records.
  • Do not throw from the handler after partial batch mode is adopted; an unhandled exception makes the entire batch fail.
  • For FIFO queues, stop processing after the first failure and return failed plus unprocessed message IDs in batchItemFailures to preserve ordering.
  • Keep batch transport behavior inside the SQS adapter.

Retry and idempotency rules

  • Retryability must be a deliberate classification, not an accidental side effect of generic failure handling.
  • Retryable errors should be reserved for transient dependency/network/throttling conditions or explicitly retryable workflows.
  • Terminal errors should not be retried forever; prefer DLQ/redrive strategy where applicable.
  • Idempotency must protect business side effects when the same message or command is processed more than once.

Logging interaction rules

  • Do not log and return the same error at every layer.
  • Log terminal failures at the boundary where they become operationally meaningful.
  • It is acceptable to add context while propagating without logging at every step.
  • Error handling must remain correct even if logging is removed.

Testing rules

  • Unit tests for domain/application code must assert error classification with errors.Is / errors.As where appropriate.
  • Adapter tests must verify error mapping behavior, not only happy paths.
  • HTTP adapter tests must verify expected status codes and safe response bodies for error scenarios.
  • SQS adapter tests must verify partial batch behavior, retry classification, and FIFO stop-on-first-failure behavior when relevant.
  • Panic recovery tests, if implemented, must verify narrow edge recovery only.

Dependency rules

  • Prefer Go standard library error facilities first.
  • Any third-party error package requires explicit approval from the active prompt, task, or repository conventions.
  • Do not introduce convenience libraries that replace ordinary Go error returns unless explicitly required.

Checklist for implementation

  • Define stable domain/application error categories only where callers need them.
  • Preserve causes with %w when crossing boundaries.
  • Keep transport mapping inside inbound adapters.
  • Keep provider/client translation inside outbound adapters.
  • Ensure HTTP expected failures become valid HTTP responses.
  • Ensure SQS expected per-record failures become correct partial batch responses.
  • Keep panic/recover out of ordinary control flow.
  • Add or update tests for changed error paths.

Done when

  • the service uses explicit, inspectable error values
  • wrapped errors preserve useful cause information
  • domain/application errors are transport-agnostic
  • HTTP adapters map expected failures to correct responses without raw Lambda errors
  • SQS adapters implement explicit retry/failure behavior and partial batch response where applicable
  • tests verify error classification and boundary mapping
  • no hidden fallbacks, swallowed errors, or string-based error branching remain in touched areas

When not to use it

  • When the task is only about logging or telemetry with no change to error behavior
  • When the task is only about styling or refactoring with no error-path impact
  • When the service is a trivial one-off function with no reusable domain/application boundary

Limitations

  • Applies to services whose inbound trigger is API Gateway HTTP API or Amazon SQS
  • Panic is reserved for unrecoverable programmer bugs or truly impossible states
  • Do not let AWS transport types or HTTP concerns leak into domain/application errors

How it compares

This skill provides a specialized framework for error handling in Go AWS Lambda, ensuring failures are explicit and correctly mapped at transport boundaries, which is more reliable than generic error handling approaches.

Compared to similar skills

go-lambda-error-handling side by side with the closest alternatives in the catalog.

SkillInstallsUpdatedSafetyDifficulty
go-lambda-error-handling (this skill)04moNo flagsAdvanced
new-aws-service03moNo flagsIntermediate
go-kafka-consumer-reliability03moNo flagsAdvanced
golang-context03moReviewIntermediate

Try saying

Example prompts that trigger this skill in your AI assistant.

You might also like

new-aws-service

bernos

Scaffold a new AWS service wrapper in pkg/aws/<servicename>/ following the established cloudformationservice pattern

00

go-kafka-consumer-reliability

kabradshaw1

Use when creating, modifying, reviewing, or debugging Go services that consume Kafka, especially projection/read-model consumers, segmentio/kafka-go readers, DLQ handling, retries, offset commits, consumer groups, or idempotent event processing.

00

golang-context

samber

Idiomatic context.Context usage in Golang — propagation through API boundaries, cancellation, timeouts and deadlines, request-scoped values, context.WithoutCancel for background work outliving requests. Apply when designing context propagation across layers, debugging leaked or unexpired contexts, c

00

architecture-patterns

wshobson

Implement proven backend architecture patterns including Clean Architecture, Hexagonal Architecture, and Domain-Driven Design. Use when architecting complex backend systems or refactoring existing applications for better maintainability.

55214

workflow-orchestration-patterns

wshobson

Design durable workflows with Temporal for distributed systems. Covers workflow vs activity separation, saga patterns, state management, and determinism constraints. Use when building long-running processes, distributed transactions, or microservice orchestration.

10117

golang-pro

sickn33

Master Go 1.21+ with modern patterns, advanced concurrency, performance optimization, and production-ready microservices. Expert in the latest Go ecosystem including generics, workspaces, and cutting-edge frameworks. Use PROACTIVELY for Go development, architecture design, or performance optimization.

1479

Search skills

Search the agent skills registry