Skip to content

notque/vexjoy-agent / skills/programming/programming

programming

Flagged

Language-specific patterns and tooling: Go, Kotlin, PHP, Swift, TypeScript.

FileKindSize
SKILL.mdskill md11.6 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/kotlin/concurrency-patterns.mdmarkdown5.4 KB
references/kotlin/kotlin-testing.mdmarkdown7.9 KB
references/php/modern-php-features.mdmarkdown4.4 KB
references/php/testing-patterns.mdmarkdown7.5 KB
references/swift/preferred-patterns.mdmarkdown2.4 KB
references/swift/swift-testing.mdmarkdown6.6 KB
references/swift/task-patterns.mdmarkdown3.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/patterns.md

View on GitHub
# Extended Go Error Handling Patterns

Overflow reference for the go-patterns skill (error handling section). Contains advanced patterns that do not fit in the main SKILL.md.

---

## Gopls for Error Pattern Analysis

When `gopls` is available, use it to trace error handling patterns across the codebase:

```bash
# Find all usages of a sentinel error (verify consistent handling)
$ gopls references pkg/errors/errors.go:15:5  # position of ErrNotFound

# Find all implementations of a custom error interface
$ gopls implementation internal/errors/types.go:20:6  # position of your error interface

# Trace where errors are returned from a function
$ gopls references pkg/service/handler.go:42:10  # function that returns error
```

**Note:** gopls requires files to be part of a Go module. It cannot analyze standard library files like `builtin.go` directly.

---

## HTTP Handler Error Patterns

### Standard Pattern with respondwith

```go
func handleRequest(w http.ResponseWriter, r *http.Request) {
    data, err := fetchData(r.Context())
    if respondwith.ErrorText(w, err) {
        return
    }

    result, err := processData(data)
    if respondwith.ErrorText(w, err) {
        return
    }

    respondwith.JSON(w, http.StatusOK, result)
}
```

### Middleware Error Wrapping

```go
func errorMiddleware(next http.Handler) http.Handler {
    return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
        defer func() {
            if rec := recover(); rec != nil {
                log.Printf("panic recovered: %v", rec)
                http.Error(w, "internal server error", http.StatusInternalServerError)
            }
        }()
        next.ServeHTTP(w, r)
    })
}
```

---

## Custom Error Type with Unwrap

When a custom error type wraps an inner error, implement `Unwrap()` to preserve the chain:

```go
type ServiceError struct {
    Op   string
    Kind ErrorKind
    Err  error
}

func (e *ServiceError) Error() string {
    if e.Err != nil {
        return fmt.Sprintf("%s: %s: %v", e.Op, e.Kind, e.Err)
    }
    return fmt.Sprintf("%s: %s", e.Op, e.Kind)
}

func (e *ServiceError) Unwrap() error {
    return e.Err
}

// Usage:
func GetUser(id string) (*User, error) {
    user, err := db.Find(id)
    if err != nil {
        return nil, &ServiceError{
            Op:   "GetUser",
            Kind: Internal,
            Err:  err,
        }
    }
    return user, nil
}

// Caller can still use errors.Is/AsType on the inner error (AsType: Go 1.26+):
if svcErr, ok := errors.AsType[*ServiceError](err); ok {
    fmt.Println(svcErr.Op, svcErr.Kind)
}
```

---

## Error Wrapping in Deferred Cleanup

Handle errors from deferred operations without shadowing the primary error:

```go
func WriteData(path string, data []byte) (retErr error) {
    f, err := os.Create(path)
    if err != nil {
        return fmt.Errorf("create file %s: %w", path, err)
    }
    defer func() {
        if cerr := f.Close(); cerr != nil && retErr == nil {
            retErr = fmt.Errorf("close file %s: %w", path, cerr)
        }
    }()

    if _, err := f.Write(data); err != nil {
        return fmt.Errorf("write to %s: %w", path, err)
    }
    return nil
}
```

---

## Multi-Error Aggregation (Go 1.20+)

Use `errors.Join` to combine multiple errors:

```go
func ValidateConfig(cfg *Config) error {
    var errs []error

    if cfg.Host == "" {
        errs = append(errs, fmt.Errorf("host is required"))
    }
    if cfg.Port < 1 || cfg.Port > 65535 {
        errs = append(errs, fmt.Errorf("port must be 1-65535, got %d", cfg.Port))
    }
    if cfg.Timeout <= 0 {
        errs = append(errs, fmt.Errorf("timeout must be positive"))
    }

    return errors.Join(errs...)
}

// Caller can still use errors.Is on individual errors in the joined set
```

---

## Quick Reference Card

```go
// Wrap with context
return fmt.Errorf("operation X for %s: %w", id, err)

// Sentinel error
var ErrNotFound = errors.New("not found")

// Check sentinel
if errors.Is(err, ErrNotFound) { ... }

// Custom error type
type MyError struct { Field string }
func (e *MyError) Error() string { return e.Field }

// Extract custom type (Go 1.26+; use errors.As below 1.26)
if myErr, ok := errors.AsType[*MyError](err); ok { ... }

// Explicit ignore
_ = mayFail()

// Multi-error (Go 1.20+)
return errors.Join(err1, err2)
```
receiving-code-reviewobra/superpowersUse when receiving code review feedback, before implementing suggestions, especially if feedback seems unclear or technically questionable - requires technical rigor and verification, not performative agreement or blind implementationStars: 321kUpdated Claude CodeCodexVerifiedInstall
requesting-code-reviewobra/superpowersUse when completing tasks, implementing major features, or before merging to verify work meets requirementsStars: 321kUpdated Claude CodeCodexVerifiedInstall
using-git-worktreesobra/superpowersUse when starting feature work that needs isolation from current workspace or before executing implementation plans - ensures an isolated workspace exists via native tools or git worktree fallbackStars: 321kUpdated Claude CodeCodexVerifiedInstall
verification-before-completionobra/superpowersUse when about to claim work is complete, fixed, or passing, before committing or creating PRs - requires running verification commands and confirming output before making any success claims; evidence before assertions alwaysStars: 321kUpdated Claude CodeCodexVerifiedInstall