{"record":{"id":"5399fcf14909c032","repo":"geektutu/7days-golang","slug":"not-found-5399fc","errorCode":null,"errorMessage":"NOT FOUND","messagePattern":"NOT FOUND","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"gee-orm/day6-transaction/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/day6-transaction/session/record.go#L48-L84","documentation":"Sentinel error returned by Session.First (within transaction support) when the LIMIT 1 query returns zero rows. It signals that no record satisfies the query conditions; the caller's destination value is not populated.","triggerScenarios":"First() within s.Transaction(...) where the SELECT LIMIT 1 matches nothing; reading a row created outside the current transaction's isolation; querying an uncommitted row from another connection.","commonSituations":"Transaction inserts in one session but First runs on another uncommitted session; row deleted earlier in the same transaction; wrong condition values.","solutions":["Perform reads inside the same transaction/session that writes the row","Check err.Error()==\"NOT FOUND\" and handle as empty result; roll back or create as appropriate","Verify isolation level if cross-transaction visibility was expected","Confirm condition arguments and table name"],"exampleFix":"// before\nreturn s.Transaction(func() error { return s2.First(&u, \"id=?\", id) }) // different session\n// after\nreturn s.Transaction(func() error { return s.First(&u, \"id=?\", id) }) // same tx session","handlingStrategy":"try-catch","validationCode":"if rows, err := tx.QueryContext(ctx, \"SELECT 1 FROM users LIMIT 1\"); err == nil { defer rows.Close() } // row visibility check inside tx","typeGuard":null,"tryCatchPattern":"err := s.Transaction(func() error {\n    if err := s.First(&u, \"id = ?\", id); err != nil {\n        if err.Error() == \"NOT FOUND\" { return ErrNotFound }\n        return err\n    }\n    return nil\n})","preventionTips":["Read and write in the same transaction/session","Remember uncommitted rows are invisible to other sessions","Match isolation level to expectations","Handle not-found inside the tx as a rollback signal"],"tags":["orm","sql","transaction","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"}