shareAI-lab/learn-claude-code · error · ValueError
Unknown memory type: {mem_type}
Error message
Unknown memory type: {mem_type} What it means
Raised by write_memory_file() in s09_memory/code.py:153 when mem_type is not one of the allowed MEMORY_TYPES: 'user', 'feedback', 'project', 'reference'. Memory records are tagged with a type in their YAML front matter and the index/rebuild logic groups by it, so unknown types would silently fragment the store. The membership test is an exact, case-sensitive tuple check, so 'User' or 'USER' fail just like 'preference'.
Source
Thrown at s09_memory/code.py:153
) == normalized_description:
return False
if _normalized_memory_text(str(memory.get("body", ""))) == normalized_body:
return False
return True
def memory_document(name: str, mem_type: str, description: str, body: str) -> str:
metadata = yaml.safe_dump(
{"name": name, "description": description, "type": mem_type},
sort_keys=False,
allow_unicode=True,
).strip()
return f"---\n{metadata}\n---\n\n{body.strip()}\n"
def write_memory_file(name: str, mem_type: str, description: str, body: str) -> Path:
if not name.strip():
raise ValueError("Memory name cannot be empty")
if mem_type not in MEMORY_TYPES:
raise ValueError(f"Unknown memory type: {mem_type}")
if not description.strip() or not body.strip():
raise ValueError("Memory description and body cannot be empty")
MEMORY_DIR.mkdir(parents=True, exist_ok=True)
path = memory_path(f"{memory_slug(name)}.md")
path.write_text(memory_document(name, mem_type, description, body))
rebuild_memory_index()
return path
def rebuild_memory_index() -> None:
MEMORY_DIR.mkdir(parents=True, exist_ok=True)
lines = []
for path in sorted(MEMORY_DIR.glob("*.md")):
if path.name == MEMORY_INDEX.name:
continue
try:
path = memory_path(path.name)
except ValueError:View on GitHub (pinned to 985456f4ad)
Solutions
- Use one of the exact allowed values: 'user', 'feedback', 'project', 'reference' (import MEMORY_TYPES and choose from it).
- Map free-form or capitalized types to the closest allowed type before writing, defaulting to 'reference'.
- If a genuinely new category is needed, extend the MEMORY_TYPES tuple deliberately and rebuild the index.
Example fix
# before write_memory_file(name, 'preference', description, body) # after from s09_memory.code import MEMORY_TYPES mem_type = mem_type.lower() if mem_type in MEMORY_TYPES else 'reference' write_memory_file(name, mem_type, description, body)
Defensive patterns
Strategy: type-guard
Validate before calling
from s09_memory.code import MEMORY_TYPES
def pick_memory_type(candidate: str) -> str:
return candidate if candidate in MEMORY_TYPES else 'reference' Type guard
def is_known_memory_type(mem_type) -> bool:
from s09_memory.code import MEMORY_TYPES
return isinstance(mem_type, str) and mem_type in MEMORY_TYPES Try / catch
try:
write_memory_file(name, mem_type, description, body)
except ValueError as e:
if 'Unknown memory type' in str(e):
write_memory_file(name, 'reference', description, body)
else:
raise Prevention
- Import MEMORY_TYPES and choose values from it instead of hardcoding strings.
- Normalize LLM-suggested types through an explicit mapping to the four allowed values.
- Extend MEMORY_TYPES deliberately, never by catching the error and writing anyway.
When it happens
Trigger: Calling write_memory_file(name, 'preference', ...) — 'preference' is not in the tuple; passing a capitalized variant like 'Feedback'; passing a type string obtained from an LLM response that invented a new category; passing None or a non-string.
Common situations: LLM-driven memory capture where the model free-forms a type outside the allowed vocabulary; hand-written scripts that assume an intuitive-but-wrong type name; version drift if you upgrade code that once accepted arbitrary types.
Related errors
- The memory index is not a memory record
- Memory name cannot be empty
- Memory description and body cannot be empty
- Invalid task status: {task.status}
- Max 20 todos allowed
AI-assisted analysis of shareAI-lab/learn-claude-code@985456f4ad (2026-08-14).
Data as JSON: /api/errors/6092e754d8b5aee5.
Report an issue: GitHub.