{"record":{"id":"83a69d68ed9192e8","repo":"geektutu/7days-golang","slug":"not-found-83a69d","errorCode":null,"errorMessage":"NOT FOUND","messagePattern":"NOT FOUND","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"gee-orm/day5-hooks/session/record.go","lineNumber":66,"sourceCode":"\t\t}\n\t\tif err := rows.Scan(values...); err != nil {\n\t\t\treturn err\n\t\t}\n\t\ts.CallMethod(AfterQuery, dest.Addr().Interface())\n\t\tdestSlice.Set(reflect.Append(destSlice, dest))\n\t}\n\treturn rows.Close()\n}\n\n// First gets the 1st row\nfunc (s *Session) First(value interface{}) error {\n\tdest := reflect.Indirect(reflect.ValueOf(value))\n\tdestSlice := reflect.New(reflect.SliceOf(dest.Type())).Elem()\n\tif err := s.Limit(1).Find(destSlice.Addr().Interface()); err != nil {\n\t\treturn err\n\t}\n\tif destSlice.Len() == 0 {\n\t\treturn errors.New(\"NOT FOUND\")\n\t}\n\tdest.Set(destSlice.Index(0))\n\treturn nil\n}\n\n// Limit adds limit condition to clause\nfunc (s *Session) Limit(num int) *Session {\n\ts.clause.Set(clause.LIMIT, num)\n\treturn s\n}\n\n// Where adds limit condition to clause\nfunc (s *Session) Where(desc string, args ...interface{}) *Session {\n\tvar vars []interface{}\n\ts.clause.Set(clause.WHERE, append(append(vars, desc), args...)...)\n\treturn s\n}\n","sourceCodeStart":48,"sourceCodeEnd":84,"githubUrl":"https://github.com/geektutu/7days-golang/blob/cf3644382101dc13e7fd92e8f5c66cabc51bcd3b/gee-orm/day5-hooks/session/record.go#L48-L84","documentation":"Sentinel error returned by Session.First when the LIMIT 1 query (with AfterQuery hooks already applied to fetched rows) yields an empty result set. It means no row matched the session's chain conditions; the destination value is left unset.","triggerScenarios":"First(&dest, cond) with no matching rows; after-hooks filtering rows conceptually; querying before seed data exists.","commonSituations":"Unseeded test DB; soft-deleted rows excluded by hook-added conditions; wrong condition arguments.","solutions":["Treat the sentinel as an empty-result signal and branch on it","Verify hooks/conditions aren't excluding the row you expect","Seed data or relax the WHERE condition","Wrap it in a typed ErrRecordNotFound for cleaner handling"],"exampleFix":"// before\nerr := s.First(&u)\n// after\nvar ErrRecordNotFound = errors.New(\"NOT FOUND\")\nif errors.Is(err, ErrRecordNotFound) { /* create or 404 */ }","handlingStrategy":"try-catch","validationCode":"var users []User\nif err := s.Find(&users); err == nil && len(users) == 0 { /* will be NOT FOUND */ }","typeGuard":null,"tryCatchPattern":"if err := s.First(&u, hooks...); err != nil {\n    if err.Error() == \"NOT FOUND\" { return errNotFound }\n    return err\n}","preventionTips":["Review hook conditions that may filter rows","Seed data before hooks run in tests","Centralize not-found handling in one helper","Log condition args on miss to debug"],"tags":["orm","sql","not-found"],"backgroundTag":"record-not-found","analyzedSha":"cf3644382101dc13e7fd92e8f5c66cabc51bcd3b","analyzedAt":"2026-09-03T18:31:24.087Z","contentChangedAt":"2026-09-03T18:31:24.087Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}