{"record":{"id":"f63f2348f6680bd6","repo":"affaan-m/ECC","slug":"failed-to-create-user-w","errorCode":null,"errorMessage":"failed to create user: %w","messagePattern":"failed to create user: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"info","filePath":"rules/golang/coding-style.md","lineNumber":26,"sourceCode":"\n> This file extends [common/coding-style.md](../common/coding-style.md) with Go specific content.\n\n## Formatting\n\n- **gofmt** and **goimports** are mandatory — no style debates\n\n## Design Principles\n\n- Accept interfaces, return structs\n- Keep interfaces small (1-3 methods)\n\n## Error Handling\n\nAlways wrap errors with context:\n\n```go\nif err != nil {\n    return fmt.Errorf(\"failed to create user: %w\", err)\n}\n```\n\n## Reference\n\nSee skill: `golang-patterns` for comprehensive Go idioms and patterns.\n","sourceCodeStart":8,"sourceCodeEnd":33,"githubUrl":"https://github.com/affaan-m/ECC/blob/01e15490f04e29cfefe3896951f43db46994d8ee/rules/golang/coding-style.md#L8-L33","documentation":"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.","triggerScenarios":"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.","commonSituations":"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).","solutions":["Apply the rule mechanically: every `return err` becomes `return fmt.Errorf(\"<action>: %w\", err)`.","Use %w exclusively; reserve %v for messages where you explicitly want to discard the chain.","Keep wrap messages short and action-oriented ('failed to create user', 'querying orders').","Add wrapcheck to CI to enforce the rule automatically."],"exampleFix":"// before\nif err != nil {\n    return err\n}\n\n// after\nif err != nil {\n    return fmt.Errorf(\"failed to create user: %w\", err)\n}","handlingStrategy":"validation","validationCode":"null","typeGuard":"null","tryCatchPattern":"if err := createUser(ctx, u); err != nil {\n    log.Printf(\"create user failed: %v\", err)\n    return fmt.Errorf(\"failed to create user: %w\", err)\n}","preventionTips":["Treat 'wrap with %w' as a codebase convention; enforce with wrapcheck in CI.","Reserve %v for deliberately discarding the chain.","Keep wrap messages short and action-oriented."],"tags":["go","error-wrapping","fmt","conventions","lint"],"backgroundTag":null,"analyzedSha":"01e15490f04e29cfefe3896951f43db46994d8ee","analyzedAt":"2026-08-13T00:31:08.655Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}