{"record":{"id":"60883e063428a838","repo":"JuliusBrussee/caveman","slug":"memory-s-not-found","errorCode":null,"errorMessage":"memory %s not found","messagePattern":"memory (.+?) not found","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"mem/store.go","lineNumber":647,"sourceCode":"\t\t&validUntil,\n\t\t&supersedes,\n\t\t&supersededBy,\n\t); err != nil {\n\t\treturn err\n\t}\n\tif validUntil.Valid {\n\t\tmemory.ValidUntil = &validUntil.String\n\t}\n\tmemory.Supersedes = supersedes.String\n\tmemory.SupersededBy = supersededBy.String\n\treturn nil\n}\n\nfunc (s *Store) memoryByID(id string) (Memory, error) {\n\tvar memory Memory\n\tif err := scanMemory(s.db.QueryRow(memorySelect+` WHERE id = ?`, id), &memory); err != nil {\n\t\tif err == sql.ErrNoRows {\n\t\t\treturn Memory{}, fmt.Errorf(\"memory %s not found\", id)\n\t\t}\n\t\treturn Memory{}, fmt.Errorf(\"read memory %s: %w\", id, err)\n\t}\n\treturn memory, nil\n}\n\n// migrateMemorySchema upgrades pre-supersession stores in place. SQLite cannot\n// add several columns in one statement, so each missing column is added\n// independently and legacy created_at becomes valid_from.\nfunc migrateMemorySchema(db *sql.DB) error {\n\trows, err := db.Query(`PRAGMA table_info(memories)`)\n\tif err != nil {\n\t\treturn err\n\t}\n\tcolumns := map[string]bool{}\n\tfor rows.Next() {\n\t\tvar cid int\n\t\tvar name, kind string","sourceCodeStart":629,"sourceCodeEnd":665,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/3ee70a102609e550bd2e68004bf5990a9341c851/mem/store.go#L629-L665","documentation":"memoryByID looks up a single memory by primary key; when the query returns sql.ErrNoRows it is converted to the friendly error \"memory <id> not found\" instead of leaking the sql package sentinel. Callers such as History use it to translate a missing row into a domain-level not-found condition.","triggerScenarios":"Calling Store.History(id) (or any caller of memoryByID) with an ID that does not exist in the memories table — a mistyped, deleted, or foreign ID.","commonSituations":"Users pass an ID copied from an expired/superseded memory that was later purged, or truncate/alter the ID; also hit after pointing the CLI at a different cavemem home with a different database.","solutions":["Verify the memory ID is correct and complete (copy-paste the full handle).","Confirm you are pointing at the same store/home directory where the memory was created.","Check the memory still exists via Count/Recall (it may have been expired or deleted).","Handle the not-found case in code instead of treating all History errors as fatal."],"exampleFix":"// before\nm, err := store.History(id) // panics on 'not found'\n// after\nm, err := store.History(id)\nif err != nil && strings.Contains(err.Error(), \"not found\") {\n    return fmt.Errorf(\"no such memory %q\", id)\n}","handlingStrategy":"validation","validationCode":"// before calling History, confirm the ID exists in current recall output\nexists := slices.ContainsFunc(hits, func(h mem.Hit) bool { return h.ID == id })","typeGuard":null,"tryCatchPattern":"m, err := store.History(id)\nif err != nil && strings.Contains(err.Error(), \"not found\") {\n    return errNotFound // domain-level handling, not a crash\n}","preventionTips":["Copy memory IDs verbatim; don't retype or truncate them.","Point the CLI at the same home directory used when the memory was created.","Treat not-found as an expected case in tooling that lists then inspects memories."],"tags":["database","not-found","lookup"],"backgroundTag":"record-not-found","analyzedSha":"3ee70a102609e550bd2e68004bf5990a9341c851","analyzedAt":"2026-09-20T15:53:39.229Z","contentChangedAt":"2026-09-20T15:53:39.229Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}