Skip to content

notque/vexjoy-agent / skills/programming/programming

programming

Flagged

Language rules, workflows, and tooling: Go, Python, Rust, Kotlin, Swift, PHP, TypeScript type checks and debugging, OpenStack Python, MCP local-docs servers, Node.js backend APIs.

FileKindSize
SKILL.mdskill md19.3 KB
references/go/code-review.mdmarkdown12.0 KB
references/go/code-review/common-review-comments.mdmarkdown6.6 KB
references/go/concurrency.mdmarkdown11.5 KB
references/go/concurrency/concurrency-patterns.mdmarkdown5.7 KB
references/go/error-handling.mdmarkdown10.8 KB
references/go/error-handling/patterns.mdmarkdown4.2 KB
references/go/google-style-guide/SHA256SUMSother313 B
references/go/google-style-guide/UPSTREAM_REVISIONother41 B
references/go/google-style-guide/best-practices/part-01.mdmarkdown10.0 KB
references/go/google-style-guide/best-practices/part-02.mdmarkdown15.0 KB
references/go/google-style-guide/best-practices/part-03.mdmarkdown14.1 KB
references/go/google-style-guide/best-practices/part-04.mdmarkdown13.5 KB
references/go/google-style-guide/best-practices/part-05.mdmarkdown10.5 KB
references/go/google-style-guide/best-practices/part-06.mdmarkdown14.4 KB
references/go/google-style-guide/best-practices/part-07.mdmarkdown16.1 KB
references/go/google-style-guide/best-practices/part-08.mdmarkdown11.4 KB
references/go/google-style-guide/best-practices/part-09.mdmarkdown13.7 KB
references/go/google-style-guide/best-practices/part-10.mdmarkdown16.9 KB
references/go/google-style-guide/decisions/part-01.mdmarkdown15.0 KB
references/go/google-style-guide/decisions/part-02.mdmarkdown12.5 KB
references/go/google-style-guide/decisions/part-03.mdmarkdown11.5 KB
references/go/google-style-guide/decisions/part-04.mdmarkdown8.4 KB
references/go/google-style-guide/decisions/part-05.mdmarkdown9.8 KB
references/go/google-style-guide/decisions/part-06.mdmarkdown14.7 KB
references/go/google-style-guide/decisions/part-07.mdmarkdown13.3 KB
references/go/google-style-guide/decisions/part-08.mdmarkdown14.3 KB
references/go/google-style-guide/decisions/part-09.mdmarkdown15.3 KB
references/go/google-style-guide/decisions/part-10.mdmarkdown8.3 KB
references/go/google-style-guide/guide/part-01.mdmarkdown16.3 KB
references/go/google-style-guide/guide/part-02.mdmarkdown3.0 KB
references/go/google-style-guide/index.mdmarkdown8.4 KB
references/go/preferred-patterns.mdmarkdown12.5 KB
references/go/preferred-patterns/code-examples.mdmarkdown11.6 KB
references/go/quality-gate.mdmarkdown7.3 KB
references/go/quality-gate/common-lint-errors.jsonconfig7.6 KB
references/go/quality-gate/examples.mdmarkdown11.0 KB
references/go/quality-gate/makefile-targets.jsonconfig5.1 KB
references/go/sapcc-conventions.mdmarkdown34.6 KB
references/go/sapcc-conventions/api-design-detailed.mdmarkdown22.7 KB
references/go/sapcc-conventions/architecture-patterns.mdmarkdown18.6 KB
references/go/sapcc-conventions/build-ci-detailed.mdmarkdown18.7 KB
references/go/sapcc-conventions/error-handling-detailed.mdmarkdown20.1 KB
references/go/sapcc-conventions/extended-patterns.mdmarkdown7.1 KB
references/go/sapcc-conventions/go-bits-philosophy-detailed.mdmarkdown24.5 KB
references/go/sapcc-conventions/library-reference.mdmarkdown14.0 KB
references/go/sapcc-conventions/pr-mining-insights.mdmarkdown17.5 KB
references/go/sapcc-conventions/review-standards.mdmarkdown10.5 KB
references/go/sapcc-conventions/sapcc-code-patterns.mdmarkdown46.2 KB
references/go/testing.mdmarkdown9.7 KB
references/go/testing/go-benchmark-and-concurrency.mdmarkdown5.6 KB
references/go/testing/go-test-patterns.mdmarkdown9.0 KB
references/golang-general.mdmarkdown8.9 KB
references/golang-general/go-modern-code.mdmarkdown17.2 KB
references/golang-general/go-verification-workflow.mdmarkdown5.0 KB
references/golang-general/go-version-idioms.mdmarkdown6.8 KB
references/kotlin-general.mdmarkdown7.5 KB
references/kotlin-general/kotlin-patterns.mdmarkdown7.9 KB
references/kotlin-general/kotlin-security-testing.mdmarkdown4.4 KB
references/kotlin-general/kotlin-security.mdmarkdown11.1 KB
references/kotlin/concurrency-patterns.mdmarkdown5.4 KB
references/kotlin/kotlin-testing.mdmarkdown7.9 KB
references/mcp-local-docs.mdmarkdown6.9 KB
references/mcp-local-docs/mcp-patterns.mdmarkdown9.6 KB
references/mcp-local-docs/mcp-preferred-patterns.mdmarkdown6.9 KB
references/mcp-local-docs/server-templates.mdmarkdown4.4 KB
references/mcp-local-docs/typescript-async-patterns.mdmarkdown8.9 KB
references/nodejs-api.mdmarkdown7.3 KB
references/nodejs-api/auth-patterns.mdmarkdown10.0 KB
references/nodejs-api/middleware-patterns.mdmarkdown10.5 KB
references/nodejs-api/nodejs-security.mdmarkdown12.3 KB
references/nodejs-api/webhook-patterns.mdmarkdown9.9 KB
references/php-general.mdmarkdown4.7 KB
references/php-general/php-behaviors.mdmarkdown5.2 KB
references/php-general/php-conventions.mdmarkdown5.8 KB
references/php/modern-php-features.mdmarkdown4.4 KB
references/php/testing-patterns.mdmarkdown7.5 KB
references/python-general.mdmarkdown7.7 KB
references/python-general/flask-jinja-webapp.mdmarkdown5.7 KB
references/python-general/python-local-gates.mdmarkdown4.4 KB
references/python-general/python-modern-code.mdmarkdown23.1 KB
references/python-openstack.mdmarkdown5.2 KB
references/python-openstack/error-handling.mdmarkdown658 B
references/python-openstack/hacking-rules.mdmarkdown4.1 KB
references/python-openstack/openstack-patterns.mdmarkdown1.2 KB
references/python-openstack/oslo-patterns.mdmarkdown6.4 KB
references/python-openstack/output-format.mdmarkdown2.4 KB
references/python-openstack/preferred-patterns.mdmarkdown1.9 KB
references/python-openstack/rpc-versioning.mdmarkdown5.3 KB
references/rust-general.mdmarkdown8.2 KB
references/rust-general/rust-modern-code.mdmarkdown13.4 KB
references/rust-general/rust-verification-workflow.mdmarkdown5.5 KB
references/rust-general/rust-version-idioms.mdmarkdown7.0 KB
references/swift-general.mdmarkdown5.7 KB
references/swift-general/swift-patterns.mdmarkdown6.7 KB
references/swift-general/swift-security-testing.mdmarkdown6.6 KB
references/swift-general/swift-security.mdmarkdown13.3 KB
references/swift/preferred-patterns.mdmarkdown2.4 KB
references/swift/swift-testing.mdmarkdown6.6 KB
references/swift/task-patterns.mdmarkdown3.6 KB
references/typescript-debugging.mdmarkdown9.3 KB
references/typescript-debugging/debugging-workflows-async-memory.mdmarkdown5.8 KB
references/typescript-debugging/debugging-workflows.mdmarkdown5.6 KB
scripts/bench-compare.shscript7.1 KB
scripts/check-errors.shscript7.1 KB
scripts/check-interface-compliance.shscript6.4 KB
scripts/check-sapcc-auth-ordering.shscript5.5 KB
scripts/check-sapcc-httptest.shscript4.4 KB
scripts/check-sapcc-identify-endpoint.shscript5.8 KB
scripts/check-sapcc-json-strict.shscript4.9 KB
scripts/check-sapcc-time-now.shscript4.2 KB
scripts/check-sapcc-todo-format.shscript4.1 KB
scripts/gen-table-test.shscript4.2 KB
scripts/quality_checker.pyscript16.2 KB
scripts/sync-google-style-guide.pyscript2.5 KB
scripts/validate.pyscript6.3 KB

references/go/error-handling.md

View on GitHub

# Go Error Handling Skill

Idiomatic Go error handling through context-rich wrapping, sentinel errors, custom error types, and proper error chain inspection. Every error return tells a story -- when read top-to-bottom, wrapped errors form a narrative of what happened and where.

## Available Scripts

- **`scripts/check-errors.sh`** -- Detect bare `return err` and log-and-return failure modes. Run `bash scripts/check-errors.sh --help` for options.

## Instructions

### Phase 1: Understand the Context

Read the repository CLAUDE.md before implementing any error handling, because project-specific conventions (error prefixes, logging patterns, custom base types) override generic Go idioms.

Scan existing error patterns in the package to understand what is already in use. When gopls MCP is available, use `go_symbol_references` to find all usages of sentinel errors across the codebase, and `go_diagnostics` to verify error handling correctness after edits. Fallback: `gopls references` CLI or LSP tool.

### Phase 2: Select the Right Error Pattern

Choose the simplest pattern that fits the situation, because over-engineering error types creates unnecessary abstraction that callers must learn and maintain. A simple wrap handles most cases; do not create custom types when a sentinel suffices, or sentinels when a simple wrap is enough.

| Situation | Pattern | Example |
|-----------|---------|---------|
| Operation failed, caller does not check type | **Wrap with context** | `fmt.Errorf("load config: %w", err)` |
| Caller needs to check for specific condition | **Sentinel error** | `var ErrNotFound = errors.New("not found")` |
| Caller needs structured error data | **Custom error type** | `type ValidationError struct{...}` |
| Error at HTTP boundary | **Status mapping** | `errors.Is(err, ErrNotFound) -> 404` |

Even when an error seems simple and unlikely to be inspected, always define a sentinel if the error crosses a package boundary, because you cannot predict what callers will need and adding sentinels later is a breaking change.

**Gate**: Before writing code, name the pattern you are using and why it fits. If the answer is "custom type" but no caller needs structured data, downgrade to sentinel or wrap.

### Phase 3: Wrap Errors with Context

Every error return adds context describing the operation that failed. Never use naked `return err`, because unwrapped errors lose context about where in the call chain the failure occurred -- by the time the error reaches the top, no one knows what operation triggered it.

```go
func LoadConfig(path string) (*Config, error) {
    data, err := os.ReadFile(path)
    if err != nil {
        return nil, fmt.Errorf("load config from %s: %w", path, err)
    }

    var cfg Config
    if err := json.Unmarshal(data, &cfg); err != nil {
        return nil, fmt.Errorf("parse config JSON from %s: %w", path, err)
    }

    return &cfg, nil
}
// Output: "parse config JSON from /etc/app.json: invalid character..."
```

Rules for wrap messages:
- Describe the **operation**, not the error (`"load config"` not `"error loading config"`), because prefixes like "error" or "failed" add zero information -- the caller already knows it is an error
- Include **identifying data** (filename, ID, key), because without it the error message cannot distinguish between instances of the same operation
- Use `%w` to preserve the error chain, because `%v` severs the chain and makes `errors.Is`/`errors.As` return false for all wrapped errors
- Start lower-case, no trailing punctuation, because this is Go convention and errors are often concatenated with colons where capitals and periods look wrong

Wrap once per call boundary. Do not double-wrap at the same level (`fmt.Errorf("process: error processing: %w", fmt.Errorf("processing failed: %w", err))`), because redundant wrapping creates unreadable error chains where the same context appears multiple times.

Each level should add only its own context, not repeat caller context, because duplicate context in logs makes errors harder to parse and debug.

Every function that returns an error must have its error checked. Never silently discard errors (`file.Close()` without checking), because silent failures cause data corruption, resource leaks, or hard-to-debug issues downstream. If you intentionally ignore an error, make it explicit with `_ = fn()` so readers know the discard was deliberate, not accidental.

When auditing existing code, scan for naked `return err` statements and missing `%w` verbs to find places where context is being lost.

### Phase 4: Define Sentinel Errors When Callers Need to Check

Sentinel errors are package-level variables for conditions callers must handle specifically. Define them at API boundaries where callers need to branch on error identity.

```go
package mypackage

import "errors"

var (
    ErrNotFound     = errors.New("not found")
    ErrUnauthorized = errors.New("unauthorized")
    ErrInvalidInput = errors.New("invalid input")
)

func GetUser(ctx context.Context, id string) (*User, error) {
    user, err := db.QueryUser(ctx, id)
    if err != nil {
        if errors.Is(err, sql.ErrNoRows) {
            return nil, ErrNotFound
        }
        return nil, fmt.Errorf("query user %s: %w", id, err)
    }
    return user, nil
}

// Caller:
user, err := GetUser(ctx, id)
if errors.Is(err, ErrNotFound) {
    // handle not found
}
```

### Phase 5: Create Custom Error Types for Rich Context

Use custom types only when callers need to extract structured data from errors, because a custom type forces callers to import your package and use `errors.As` -- unnecessary coupling if all they need is identity checking via `errors.Is`.

```go
type ValidationError struct {
    Field   string
    Message string
}

func (e *ValidationError) Error() string {
    return fmt.Sprintf("validation failed on field %q: %s", e.Field, e.Message)
}

func ValidateUser(u *User) error {
    if u.Email == "" {
        return &ValidationError{Field: "email", Message: "required"}
    }
    return nil
}

// Caller uses errors.AsType (Go 1.26+):
if valErr, ok := errors.AsType[*ValidationError](err); ok {
    fmt.Printf("Field %s failed: %s\n", valErr.Field, valErr.Message)
}
```

### Phase 6: Inspect Errors with errors.Is and errors.As

Use `errors.Is` for value comparison and `errors.As` for type extraction. Never use string matching (`strings.Contains(err.Error(), "not found")`) or direct type assertions (`err.(*MyError)`), because string matching is fragile -- error messages change across versions and wrapping -- and type assertions skip the unwrap chain so they miss wrapped errors entirely.

**errors.Is** checks if any error in the chain matches a specific value:
```go
if errors.Is(err, ErrNotFound) { /* handle */ }
if errors.Is(err, context.Canceled) { /* cancelled */ }
if errors.Is(err, os.ErrNotExist) { /* file missing */ }
```

**errors.AsType** (Go 1.26+) extracts a specific error type from the chain. Use `errors.As` with a target pointer only when go.mod is below 1.26:
```go
if pathErr, ok := errors.AsType[*os.PathError](err); ok {
    fmt.Printf("Path: %s, Op: %s\n", pathErr.Path, pathErr.Op)
}

if netErr, ok := errors.AsType[net.Error](err); ok && netErr.Timeout() {
    /* handle timeout */
}
```

### Phase 7: Map Errors to HTTP Status at Boundaries

Error-to-status mapping belongs at the HTTP handler level, not in domain logic, because embedding HTTP semantics in domain code couples your business logic to the transport layer.

```go
func errorToStatus(err error) int {
    switch {
    case errors.Is(err, ErrNotFound):
        return http.StatusNotFound
    case errors.Is(err, ErrUnauthorized):
        return http.StatusUnauthorized
    case errors.Is(err, ErrInvalidInput):
        return http.StatusBadRequest
    default:
        return http.StatusInternalServerError
    }
}
```

### Phase 8: Test Error Paths

Use table-driven tests to verify error handling, because error paths are the most common source of untested behavior and table-driven structure makes it easy to add cases:

```go
func TestProcessUser(t *testing.T) {
    tests := []struct {
        name    string
        input   *User
        wantErr error
    }{
        {
            name:    "nil user",
            input:   nil,
            wantErr: ErrInvalidInput,
        },
        {
            name:    "missing email",
            input:   &User{Name: "test"},
            wantErr: ErrInvalidInput,
        },
    }

    for _, tt := range tests {
        t.Run(tt.name, func(t *testing.T) {
            err := ProcessUser(tt.input)
            if tt.wantErr != nil {
                if !errors.Is(err, tt.wantErr) {
                    t.Errorf("got error %v, want %v", err, tt.wantErr)
                }
            } else if err != nil {
                t.Errorf("unexpected error: %v", err)
            }
        })
    }
}
```

### Phase 9: Verify Error Handling Completeness

Before completing, check:
- [ ] All errors checked -- no unchecked returns, because silent failures cause data corruption and resource leaks
- [ ] Context added -- each wrap describes the operation, because without context the final error message is meaningless
- [ ] `%w` verb used -- error chain preserved, because `%v` severs the chain and breaks `errors.Is`/`errors.As`
- [ ] Narrative formed -- error messages readable top-to-bottom, because debugging relies on the error chain telling a coherent story
- [ ] Sentinel errors defined -- for conditions callers must check, because adding sentinels later is a breaking change
- [ ] `errors.Is`/`errors.As` used -- no string comparison or type assertion, because string matching breaks when messages change
- [ ] HTTP status mapped -- at handler boundaries only, because domain code should not know about HTTP
- [ ] Simplest pattern used -- no over-engineered custom types where a wrap or sentinel suffices

## Error Handling

### Error: "error chain broken -- errors.Is returns false"
Cause: Used `%v` instead of `%w` in `fmt.Errorf`, or created a new error instead of wrapping.
Solution:
1. Check all `fmt.Errorf` calls use `%w` for the error argument
2. Ensure sentinel errors are not re-created (use the same `var`)
3. Verify custom types implement `Unwrap()` if they wrap inner errors

### Error: "redundant error context in logs"
Cause: Same context added at multiple call levels, or wrapping errors that already contain the info.
Solution:
1. Each level should add only its own context, not repeat caller context
2. One wrap per call boundary -- do not double-wrap at the same level

### Error: "sentinel error comparison fails across packages"
Cause: Error was recreated with `errors.New` instead of using the exported variable.
Solution:
1. Import and reference the package-level `var ErrX` directly
2. Never shadow sentinel errors with local `errors.New` calls

## References

### Reference Files
- `${CLAUDE_SKILL_DIR}/references/error-handling/patterns.md`: Extended patterns -- gopls tracing, HTTP handler patterns, error wrapping in middleware
rea-changelog-updatemorluto/reaPrepare or rewrite REA release changelogs and GitHub release notes from pinned Git history, with verified contributor thanks and Release Please synchronization.Stars: 470kUpdated Claude CodeCodexVerifiedInstall
academy-guideanthropics/skillsStop and check this skill before finishing any reply to a question about how to use Claude or a Claude product — it recommends matching courses, tutorials, and use cases from Claude Academy (academy.claude.com), Anthropic's learning hub. Trigger on: "how do I", "how can I", "getting started with", "what can Claude do", "teach me", "learn to use"; questions about artifacts, projects, skills, plugins, connectors, MCP; requests about rolling Claude out to a team, class, or organization; and any ask for training materials, onboarding content, or learning resources. Use it when the user is learning how to use a feature or product — not when they are mid-task and just want the task done. This skill composes with other skills: after consulting product documentation to answer how a Claude feature works, also check here for a matching course or tutorial — a docs-grounded answer and an Academy recommendation belong together. Only recommend on a strong match; never invent Academy content.Stars: 197kUpdated Claude CodeCodexVerifiedInstall
claude-apianthropics/skillsReference for the Claude API / Anthropic SDK — model ids, pricing, params, streaming, tool use, MCP, agents, caching, token counting, model migration. TRIGGER — read BEFORE opening the target file; don't skip because it "looks like a one-liner" — whenever: the prompt names Claude/Anthropic in any form (Claude, Anthropic, Fable, Opus, Sonnet, Haiku, `anthropic`, `@anthropic-ai`, `claude-*`, `us.anthropic.*`, `[1m]`); the user asks about an LLM (pricing/model choice/limits/caching) — never answer from memory; OR the task is LLM-shaped with provider unstated (agent/MCP/tool-definition/multi-agent/RAG/LLM-judge/computer-use; generate/summarize/extract/classify/rewrite/converse over NL; debugging refusals/cutoffs/streaming/tool-calls/tokens). SKIP only when another provider is being worked on (overrides all triggers): OpenAI/GPT/Gemini/Llama/Mistral/Cohere/Ollama named in the query; OR `grep -rE 'openai|langchain_openai|google.generativeai|genai|mistralai|cohere|ollama'` over the project hits (run this grep FIRST if no provider named — don't Read the file).Stars: 197kUpdated Claude CodeCodexUnverifiedInstall
doc-coauthoringanthropics/skillsGuide users through a structured workflow for co-authoring documentation. Use when user wants to write documentation, proposals, technical specs, decision docs, or similar structured content. This workflow helps users efficiently transfer context, refine content through iteration, and verify the doc works for readers. Trigger when user mentions writing docs, creating proposals, drafting specs, or similar documentation tasks.Stars: 197kUpdated Claude CodeCodexVerifiedInstall