JuliusBrussee/caveman · error

memory not found

Error message

memory %s not found

What it means

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.

Solutions

  1. Verify the memory ID is correct and complete (copy-paste the full handle).
  2. Confirm you are pointing at the same store/home directory where the memory was created.
  3. Check the memory still exists via Count/Recall (it may have been expired or deleted).
  4. Handle the not-found case in code instead of treating all History errors as fatal.

Example fix

// before
m, err := store.History(id) // panics on 'not found'
// after
m, err := store.History(id)
if err != nil && strings.Contains(err.Error(), "not found") {
    return fmt.Errorf("no such memory %q", id)
}
Defensive patterns

Strategy: validation

Validate before calling

// before calling History, confirm the ID exists in current recall output
exists := slices.ContainsFunc(hits, func(h mem.Hit) bool { return h.ID == id })

Try / catch

m, err := store.History(id)
if err != nil && strings.Contains(err.Error(), "not found") {
    return errNotFound // domain-level handling, not a crash
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: Record Not Found Errors: "not found", RecordNotFound, and "was not found" — what they mean and how to fix them — this error's family across 28 libraries.

Related errors


AI-assisted analysis of JuliusBrussee/caveman@3ee70a1026 (2026-09-20). Data as JSON: /api/errors/60883e063428a838. Report an issue: GitHub.

Appendix: source

Thrown at mem/store.go:647

		&validUntil,
		&supersedes,
		&supersededBy,
	); err != nil {
		return err
	}
	if validUntil.Valid {
		memory.ValidUntil = &validUntil.String
	}
	memory.Supersedes = supersedes.String
	memory.SupersededBy = supersededBy.String
	return nil
}

func (s *Store) memoryByID(id string) (Memory, error) {
	var memory Memory
	if err := scanMemory(s.db.QueryRow(memorySelect+` WHERE id = ?`, id), &memory); err != nil {
		if err == sql.ErrNoRows {
			return Memory{}, fmt.Errorf("memory %s not found", id)
		}
		return Memory{}, fmt.Errorf("read memory %s: %w", id, err)
	}
	return memory, nil
}

// migrateMemorySchema upgrades pre-supersession stores in place. SQLite cannot
// add several columns in one statement, so each missing column is added
// independently and legacy created_at becomes valid_from.
func migrateMemorySchema(db *sql.DB) error {
	rows, err := db.Query(`PRAGMA table_info(memories)`)
	if err != nil {
		return err
	}
	columns := map[string]bool{}
	for rows.Next() {
		var cid int
		var name, kind string

View on GitHub (pinned to 3ee70a1026)