affaan-m/ECC · info

failed to create user: %w

Error message

failed to create user: %w

What it means

A Go fmt.Errorf format string from the golang coding-style rules. The rule mandates wrapping every non-nil error with context using the %w verb: fmt.Errorf("failed to create user: %w", err). This is the canonical pattern the codebase expects; violating it (bare return, or %v) leaves the cause unwrappable and unattributed.

Source

Thrown at rules/golang/coding-style.md:26

> This file extends [common/coding-style.md](../common/coding-style.md) with Go specific content.

## Formatting

- **gofmt** and **goimports** are mandatory — no style debates

## Design Principles

- Accept interfaces, return structs
- Keep interfaces small (1-3 methods)

## Error Handling

Always wrap errors with context:

```go
if err != nil {
    return fmt.Errorf("failed to create user: %w", err)
}
```

## Reference

See skill: `golang-patterns` for comprehensive Go idioms and patterns.

View on GitHub (pinned to 01e15490f0)

Solutions

  1. Apply the rule mechanically: every `return err` becomes `return fmt.Errorf("<action>: %w", err)`.
  2. Use %w exclusively; reserve %v for messages where you explicitly want to discard the chain.
  3. Keep wrap messages short and action-oriented ('failed to create user', 'querying orders').
  4. Add wrapcheck to CI to enforce the rule automatically.

Example fix

// before
if err != nil {
    return err
}

// after
if err != nil {
    return fmt.Errorf("failed to create user: %w", err)
}
Defensive patterns

Strategy: validation

Validate before calling

null

Type guard

null

Try / catch

if err := createUser(ctx, u); err != nil {
    log.Printf("create user failed: %v", err)
    return fmt.Errorf("failed to create user: %w", err)
}

Prevention

When it happens

Trigger: Any `if err != nil` block that returns an error. The rule says: do not return the raw error; wrap it with a short, action-oriented message plus %w. Specifically shown for a user-creation failure path.

Common situations: Devs new to the codebase returning bare errors; copy-pasted %v from a tutorial that breaks errors.Is; wrapping with a message that duplicates the layer below; missing the err argument entirely (format warning at runtime).

Related errors


AI-assisted analysis of affaan-m/ECC@01e15490f0 (2026-08-13). Data as JSON: /api/errors/f63f2348f6680bd6. Report an issue: GitHub.