shareAI-lab/learn-claude-code · error · ValueError
Memory name cannot be empty
Error message
Memory name cannot be empty
What it means
Raised by write_memory_file() in s09_memory/code.py:151 when the memory record's name is empty after stripping whitespace. Every durable memory record must have a non-empty name because the name is slugified (memory_slug(name)) to produce the record's filename; an empty name would yield an empty or invalid filename. The check runs before any type or content validation and before the store directory is touched.
Source
Thrown at s09_memory/code.py:151
if _normalized_memory_text(
str(memory.get("description", ""))
) == 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:View on GitHub (pinned to 985456f4ad)
Solutions
- Check that the name is a non-empty string after strip() before calling write_memory_file().
- If the name comes from LLM output, validate with validate_memory_record() first — it rejects empty names — or derive a fallback name from the description's first words.
- Fix the upstream producer so it never emits an empty name field.
Example fix
# before
write_memory_file(record.get('name', ''), mem_type, description, body)
# after
name = (record.get('name') or '').strip()
if not name:
raise ValueError('record missing a name')
write_memory_file(name, mem_type, description, body) Defensive patterns
Strategy: validation
Validate before calling
def has_memory_name(name) -> bool:
return isinstance(name, str) and bool(name.strip()) Type guard
def is_valid_memory_name(name) -> bool:
return isinstance(name, str) and len(name.strip()) > 0 Try / catch
try:
write_memory_file(name, mem_type, description, body)
except ValueError as e:
if 'cannot be empty' in str(e):
# fill a default or surface to caller
name = fallback_name or 'unnamed-record' Prevention
- Validate all record fields (name/type/description/body) before writing.
- Prefer validate_memory_record() on any LLM-produced dict before persisting.
- Treat empty names as a producer bug: log and skip rather than defaulting silently.
When it happens
Trigger: Calling write_memory_file('', 'user', 'desc', 'body'), passing a name composed only of whitespace like ' ', or passing a programmatically derived name (e.g. a field extracted from LLM output) that is None/empty after strip. Note None fails too: name.strip() raises AttributeError, so empty strings and whitespace-only strings are the exact triggers.
Common situations: Consolidation or capture pipelines that build the name from optional fields (record.get('name', '')) without a presence check; UI forms submitted empty; LLM-generated record dicts where the name key was omitted or blank.
Related errors
- Memory description and body cannot be empty
- The memory index is not a memory record
- Unknown memory type: {mem_type}
- Task subject cannot be empty
- Bash command cannot be empty
AI-assisted analysis of shareAI-lab/learn-claude-code@985456f4ad (2026-08-14).
Data as JSON: /api/errors/f563316ed68c9931.
Report an issue: GitHub.