{"record":{"id":"f45e5b22de78a9bb","repo":"nexu-io/open-design","slug":"memory-entry-requires-name-and-a-valid-type","errorCode":null,"errorMessage":"memory entry requires `name` and a valid `type`","messagePattern":"memory entry requires `name` and a valid `type`","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"apps/daemon/src/memory.ts","lineNumber":510,"sourceCode":"  return upsertMemoryEntry(dataDir, {\n    id,\n    name:\n      typeof patch?.name === 'string' && patch.name.trim()\n        ? patch.name\n        : current.name,\n    description:\n      typeof patch?.description === 'string'\n        ? patch.description\n        : current.description,\n    type: nextType,\n    body: typeof patch?.body === 'string' ? patch.body : current.body,\n  });\n}\n\nexport async function upsertMemoryEntry(dataDir, input, options) {\n  const { name, description, type, body } = input || {};\n  if (!name || !isValidType(type)) {\n    throw new Error('memory entry requires `name` and a valid `type`');\n  }\n  const id = input?.id && /^[a-z0-9_]+$/.test(input.id)\n    ? input.id\n    : deriveMemoryId(type, name);\n  await ensureDir(memoryDir(dataDir));\n  await fsp.writeFile(\n    entryPath(dataDir, id),\n    renderEntryFile(name, description, type, body, options?.source ?? 'manual'),\n  );\n  await ensureIndexHasEntry(dataDir, id, name, description);\n  const entry = await readMemoryEntry(dataDir, id);\n  if (!entry) throw new Error('failed to read memory entry after write');\n  if (!options?.silent) {\n    emitChange({\n      kind: 'upsert',\n      id: entry.id,\n      name: entry.name,\n      description: entry.description,","sourceCodeStart":492,"sourceCodeEnd":528,"githubUrl":"https://github.com/nexu-io/open-design/blob/5be4028344c2eb4c667c5a97bda8f750c5597ef7/apps/daemon/src/memory.ts#L492-L528","documentation":"upsertMemoryEntry requires a non-empty name string and a type that is in the valid set. Valid types are defined by MEMORY_TYPES from packages/contracts: 'profile', 'user', 'feedback', 'project', 'reference', 'rule'. The isValidType check rejects anything else.","triggerScenarios":"Calling upsert with an empty/undefined/null name; calling upsert with a type not in the valid set (e.g. 'note', 'memory', 'custom', 'tag'); type has wrong casing (e.g. 'User' instead of 'user').","commonSituations":"UI form submitted without a name field; API caller sends an outdated or custom type value; type field has a typo; caller assumes arbitrary type strings are accepted.","solutions":["Provide a non-empty name string in the input","Set type to exactly one of: 'profile', 'user', 'feedback', 'project', 'reference', 'rule'","Validate the type against MEMORY_TYPES before calling upsertMemoryEntry"],"exampleFix":"// before — invalid type 'note'\nupsertMemoryEntry(dataDir, { name: 'My note', type: 'note', body: '...' });\n\n// after — valid type 'reference'\nupsertMemoryEntry(dataDir, { name: 'My note', type: 'reference', body: '...' });","handlingStrategy":"validation","validationCode":"import { MEMORY_TYPES } from '@open-design/contracts';\n\nconst VALID_MEMORY_TYPES = new Set(MEMORY_TYPES);\n\nfunction assertValidMemoryInput(input) {\n  if (!input?.name || typeof input.name !== 'string' || !input.name.trim()) {\n    throw new Error('Memory entry requires a non-empty name');\n  }\n  if (!VALID_MEMORY_TYPES.has(input.type)) {\n    throw new Error(`Invalid memory type: ${input.type}. Valid types: ${[...VALID_MEMORY_TYPES].join(', ')}`);\n  }\n}","typeGuard":"import { MEMORY_TYPES } from '@open-design/contracts';\n\ntype MemoryType = typeof MEMORY_TYPES[number];\n\nfunction isValidMemoryType(type: unknown): type is MemoryType {\n  return typeof type === 'string' && (MEMORY_TYPES as readonly string[]).includes(type);\n}","tryCatchPattern":null,"preventionTips":["Always validate name and type before calling upsertMemoryEntry","Reference MEMORY_TYPES from packages/contracts to stay in sync with the valid type set","Use lowercase type values — the check is case-sensitive","Make UI forms require a name field before submission is enabled"],"tags":["memory","validation","type-checking"],"backgroundTag":null,"analyzedSha":"5be4028344c2eb4c667c5a97bda8f750c5597ef7","analyzedAt":"2026-08-12T12:03:58.812Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}