{"record":{"id":"dedfb29d7f39993d","repo":"affaan-m/ECC","slug":"get-user-s-w","errorCode":null,"errorMessage":"get user %s: %w","messagePattern":"get user (.+?): %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"commands/go-review.md","lineNumber":119,"sourceCode":"    cacheMu sync.RWMutex\n)\n\nfunc GetSession(id string) *Session {\n    cacheMu.RLock()\n    defer cacheMu.RUnlock()\n    return cache[id]\n}\n```\n\n[HIGH] Missing Error Context\nFile: internal/handler/user.go:28\nIssue: Error returned without context\n```go\nreturn err  // No context\n```\nFix: Wrap with context\n```go\nreturn fmt.Errorf(\"get user %s: %w\", userID, err)\n```\n\n## Summary\n- CRITICAL: 1\n- HIGH: 1\n- MEDIUM: 0\n\nRecommendation: FAIL: Block merge until CRITICAL issue is fixed\n```\n\n## Approval Criteria\n\n| Status | Condition |\n|--------|-----------|\n| PASS: Approve | No CRITICAL or HIGH issues |\n| WARNING: Warning | Only MEDIUM issues (merge with caution) |\n| FAIL: Block | CRITICAL or HIGH issues found |\n","sourceCodeStart":101,"sourceCodeEnd":137,"githubUrl":"https://github.com/affaan-m/ECC/blob/01e15490f04e29cfefe3896951f43db46994d8ee/commands/go-review.md#L101-L137","documentation":"A Go fmt.Errorf format string demonstrated in the go-review command as the recommended fix for 'Missing Error Context'. The reviewer flags a bare `return err` and recommends wrapping with fmt.Errorf using the %w verb to preserve the underlying error while adding context (here, the user id). %w (not %v) preserves errors.Is/errors.As unwrapping.","triggerScenarios":"A handler returns `err` directly from a service call. The reviewer pattern recommends `return fmt.Errorf(\"get user %s: %w\", userID, err)` so the eventual log/response includes which user the lookup was for. The error fires wherever the original err was non-nil.","commonSituations":"Bare `return err` throughout a layered codebase leaving logs with no idea which entity/route failed; using %v instead of %w which breaks errors.Is at the handler; format string with %w but no wrapped error (compile-time invisible).","solutions":["Wrap at every layer boundary with fmt.Errorf(\"<verb> <entity> %s: %w\", id, err) — one wrap per layer.","Use %w (not %v) so the error chain stays unwrappable for errors.Is/errors.As.","Include just enough context (entity type + identifier) without duplicating the message at every layer.","Add a linter (wrapcheck, errcheck) to fail CI on bare `return err`."],"exampleFix":"// before\nreturn err  // No context\n\n// after\nreturn fmt.Errorf(\"get user %s: %w\", userID, err)","handlingStrategy":"try-catch","validationCode":"null","typeGuard":"null","tryCatchPattern":"if err := svc.GetUser(ctx, id); err != nil {\n    if errors.Is(err, domain.ErrNotFound) {\n        http.NotFound(w, r)\n        return\n    }\n    log.Printf(\"get user %s failed: %v\", id, err)\n    http.Error(w, \"internal error\", http.StatusInternalServerError)\n}","preventionTips":["Wrap every returned error with fmt.Errorf(\"...: %w\", err) — one wrap per layer.","Use %w, never %v, when you need errors.Is to keep working.","Add wrapcheck to CI to catch bare `return err`."],"tags":["go","error-wrapping","fmt","context","lint"],"backgroundTag":null,"analyzedSha":"01e15490f04e29cfefe3896951f43db46994d8ee","analyzedAt":"2026-08-13T00:31:08.655Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}